Problem Setting

The latent context / MDP can change abruptly at an unknown time inside the same episode.

This is different from methods such as DARLING, where the MDP is assumed to remain fixed within one episode.

SeCBAD assumes that the context is piecewise stable:

The regime stays unchanged for some stochastic amount of time and then changes abruptly.

The method tries to answer two hidden questions:

  1. Where did the current regime begin?
  2. What is the current regime?

Equivalently, SeCBAD jointly infers:

where:

  • : current latent context / regime
  • : how long the current regime has lasted so far

The segment structure itself is latent: the agent is not told where one regime ends and the next begins.

Once SeCBAD estimates where the current segment began, it can use only the data since the estimated latest change point to infer the current context. This avoids contaminating current-regime inference with data generated by previous regimes.

Context Inference and Context Belief

The true context is hidden.

The agent therefore maintains a probability distribution over possible latent contexts:

This is called the context belief.

  • context inference: the process of estimating the hidden context from data
  • context belief: the probability distribution over possible contexts
  • inferred context belief: the context belief produced by the inference model

The history is the trajectory observed by the agent, including states, actions, rewards and transitions.

After the context belief is inferred, SeCBAD augments the ordinary RL state:

where is the inferred context belief.

The policy therefore becomes:

The policy does not receive the true regime ID. It receives the inferred belief about the current regime.

Latent Situational MDP

The paper formalizes the changing environment as a Latent Situational Markov Decision Process (LS-MDP):

where:

  • : state space
  • : action space
  • : latent context space
  • : observable context-related information used as auxiliary information during training
  • : segment-duration variable
  • : transition function
  • : reward function
  • : discount factor

The current context changes both the transition and reward functions:

Therefore a context change corresponds to an actual MDP change.

Segment notation

is the segment index.

At the beginning of segment , the environment samples:

where:

  • : total duration that segment will eventually have
  • : context / regime active during segment

During that segment, the context remains fixed:

is different from .

  • : total length of segment
  • : how long the current segment has lasted so far at time

For example, if a segment will eventually last five steps:

then during the segment:

and when a new segment starts, resets to 1.

Observable Context

During training, the paper assumes access to an auxiliary noisy observation:

is not the RL transition tuple.

It is an additional context-related signal correlated with the hidden context.

For example, the hidden context may describe terrain properties, while could be some noisy simulator-provided measurement related to those properties.

For my purpose, can be viewed as optional privileged training information.

The more important setting for my work is to infer context directly from the ordinary streaming RL sample:

without requiring privileged context labels or measurements.

Joint Inference

SeCBAD decomposes joint context / segment inference as:

where:

is everything observed up to time .

The equation can be understood in plain language as:

First estimate where the current segment started. Then, using only data from that segment, estimate what the current context is.

Or more compactly:

This is just the ordinary probability product rule:

The term posterior means a probability distribution after observing data.

For example:

  • prior: belief about segment length before seeing the trajectory
  • posterior: updated belief after observing transitions and rewards

Context Encoder

Section 3.1 first considers the easier case where the current segment length is known.

Then the problem becomes:

Given the transitions belonging to the current segment, what latent context best explains them?

SeCBAD uses an inference network / encoder .

Conceptually:

The encoder is implemented using a GRU.

It does not output a discrete regime label such as "A" or "B". Instead, it outputs a distribution in a continuous latent context space.

The latent context distribution is modeled as a diagonal Gaussian whose mean and variance are produced by the encoder.

Encoder-Decoder Training

The encoder and decoder are trained before deployment.

The encoder tries to infer a useful latent context representation.

The decoder then asks whether that inferred context can explain what happened in the current trajectory segment.

The decoder contains models for:

  • next-state transition
  • reward
  • optional observable context

Conceptually:

and, during training, optionally:

The context representation is therefore trained to contain information useful for explaining how the environment currently behaves.

Equation 2

Equation 2 is essentially a VAE-style objective.

It contains two ideas:

  1. The inferred context should reconstruct / explain the observed segment well.
  2. The latent context distribution should remain close to a reasonable prior.

In plain language:

Learn a context representation that is informative enough to explain the current environment, but regularized enough that it does not simply memorize arbitrary trajectories.

The KL-divergence term is the regularization term.

The full ELBO derivation is not important for my project.

Equation 3

Equation 3 simply expands the reconstruction term step by step.

For every transition in the current segment, the decoder asks:

Given the previous state, action and inferred context, how likely are the observed next state and reward?

These likelihoods are summed across the current segment.

The important design idea is that only data believed to belong to the current segment are used.

If the true history is:

the encoder should infer the current context from:

rather than:

This is the main benefit of estimating the segment boundary.

Belief Context as a Mixture Distribution

The true is unknown.

Therefore SeCBAD considers multiple possible current segment lengths.

For example:

Each possible segment length produces a different context belief because the encoder sees a different trajectory window.

Conceptually:

  • assume -> context distribution 1
  • assume -> context distribution 2
  • assume -> context distribution 3
  • ...

The final context belief combines all of these distributions, weighted by the posterior probability of the corresponding segment length.

This is why it is called a mixture distribution.

In plain language:

For every plausible point where the current regime may have started, infer a context under that assumption, and combine those context beliefs according to how plausible each segment length is.

For implementation simplicity, the paper also considers selecting the most likely segment length and using only the corresponding context belief. They report little performance loss from this approximation.

Policy Optimization

Once the context belief is inferred, the RL part is relatively simple.

Instead of giving the policy only:

SeCBAD gives:

Therefore:

becomes:

The same belief-augmented state idea is used for the value / reward / transition formulation under the belief-MDP interpretation.

The belief is not an additional reward.

It is additional information included in the state representation.

SeCBAD uses PPO for policy optimization.

Training vs Deployment

During training:

  • the context encoder is trained
  • the decoder is trained
  • the PPO policy is trained
  • auxiliary observable context may be available

During deployment:

  • the encoder is frozen
  • the decoder is frozen
  • the policy is frozen
  • is no longer available

The system then uses observed transitions and rewards to estimate:

  1. the current segment-length posterior
  2. the current latent-context belief

and feeds the inferred context belief to the policy.

Therefore SeCBAD is mainly:

It is not a lifelong learner that continues updating its context encoder and policy indefinitely during deployment.

Relevance to My Research

The most useful idea from SeCBAD is the decomposition:

In particular, it provides a concrete example of learning:

where is a compact latent representation of the current regime.

Another useful idea is that stale data from previous regimes should not contaminate inference of the current regime.

However, SeCBAD itself does not satisfy the strict streaming setting I am interested in.

Major mismatches:

  • requires a separate training phase
  • context encoder / decoder are pretrained and then frozen
  • uses trajectory segments / past history
  • evaluates multiple possible segment lengths
  • relies on a history window rather than only the newest transition
  • uses PPO rather than a strict streaming actor-critic
  • does not continue learning indefinitely during deployment

Therefore I should not directly implement SeCBAD on top of AVG.

The useful transformation for my setting would be to replace:

with a fixed-size online recurrent context state:

The recurrent state summarizes relevant history without storing the trajectory itself.

Memory then remains fixed rather than growing with segment length.

The policy could become:

and similarly:

This suggests the research question:

Can SeCBAD-style latent regime inference be achieved in a truly streaming learner using only the current transition and a fixed-size recurrent context state, without replay, stored trajectory segments, pretrained context models, or per-regime policies?

Main Takeaway

SeCBAD's main contribution is not simply allowing an MDP to change inside an episode.

Its important idea is:

Explicitly infer both where the current piecewise-stable regime began and what latent context is currently active, then condition the RL policy on the resulting context belief.

For my project, the most valuable component is the latent regime representation:

The missing piece is how to make this mechanism truly streaming and lifelong under bounded memory.