Reinforcement Learning in Presence of Discrete Markovian Context Evolution

Hang Ren, Aivar Sootla, Taher Jafferjee, Junxiao Shen, Jun Wang, Haitham Bou Ammar

TL;DR

This paper introduces a model-based Reinforcement Learning (RL) framework designed for environments where hidden "contexts"—such as weather conditions or mechanical failures—change abruptly and follow a Markovian evolution during an episode. By combining a sticky Hierarchical Dirichlet Process (HDP) prior with a novel "context distillation" technique, the authors enable agents to automatically infer the number of hidden states and adapt their policies in real-time, significantly outperforming standard POMDP and continual RL baselines.

The Challenge of Non-Stationary Environments

Standard RL algorithms typically assume stationarity: the rules of the environment (transition dynamics and reward functions) stay the same. In the real world, this is rarely true. A drone might encounter sudden wind gusts, or a self-driving car might experience a partial actuator failure.

While "Meta-RL" addresses environments that differ between episodes, it often struggles when the environment changes during an episode. Existing "non-stationary RL" methods usually assume changes are slow and continuous. This paper tackles the more difficult case of abrupt, discrete, and unobservable context changes that follow a Markov process. The core challenge is that the agent doesn't know how many contexts exist, what they represent, or when they will switch.

Methods: The HDP-C-MDP Framework

The authors propose HDP-C-MDP, a Bayesian model-based approach designed to infer and adapt to these hidden contexts.

Graphical model of the HDP-C-MDP showing the relationship between hidden contexts, states, actions, and HDP priors.

Its key components include:

  1. Sticky Hierarchical Dirichlet Process (HDP) Prior: The HDP is a non-parametric Bayesian prior that allows for an "infinite" number of potential states. The authors use a "sticky" version, which adds a bias toward self-transitions. This is a crucial inductive bias for RL: if you are in a "high wind" context now, you are likely to stay in it for the next few time steps.
  2. Variational Inference: Instead of simple maximum likelihood estimation (which often gets stuck in local optima), the authors use variational inference to learn the transition dynamics and the hidden context evolution simultaneously from data.
  3. Context Distillation: To handle the fact that the model might "invent" too many contexts (spurious states), the authors developed a distillation procedure. It calculates the stationary distribution of the learned Markov chain and prunes states with negligible probability mass. This allows the model to collapse redundant or noisy contexts into a concise, interpretable set.
  4. Policy Representation: The authors prove that the optimal policy in this setting depends on the context belief (the posterior probability of being in a specific context given past observations). They integrate this belief into off-the-shelf RL algorithms like Soft Actor-Critic (SAC) and Model Predictive Control (MPC).

Key Insights and Results

The researchers evaluated their approach on three modified "Gym" environments designed to test context adaptation: Cart-Pole Swing-Up (with actuator failures), Drone Take-off (where contexts affect motor efficiency), and Highway Intersection (where contexts affect steering/acceleration dynamics).

Optimization and Interpretability

The Bayesian approach provides a smoother optimization landscape. While Maximum Likelihood Estimation (MLE) frequently gets trapped in poor local optima (failing to identify context switches), the HDP-based model consistently converges to the correct context structure.

Comparison of learned context transition matrices using HDP, Dirichlet, MLE, and HDP with distillation.

Because the model learns discrete contexts and transition matrices, the resulting "world model" is often human-interpretable. One can literally see the model identifying "Failure Mode A" vs. "Normal Operation."

Cardinality Independence and Distillation

You don't need to know the exact number of hidden contexts. By setting a loose upper bound and using HDP with distillation, the model "discovers" the true number of contexts from the data. Pruning spurious contexts isn't just a post-processing step; when used during training, it acts as a regularizer that prevents the model from overfitting to noise or "unseen" data transitions.

Robustness to Failure

In the Cart-Pole task with "hard failures" (where actions are reversed), the proposed C-SAC and C-CEM algorithms achieved returns nearly identical to an agent with full ground-truth information. Standard POMDP approaches (like PPO with an RNN) often fail in these settings. Without a strong prior on Markovian evolution, RNNs tend to learn an "average" of all contexts rather than identifying distinct modes of operation, leading to sub-optimal "middle-of-the-road" policies.

Furthermore, in the 12D Drone and Intersection environments, the contextual models significantly outperformed "No Information" baselines, proving the approach scales to more complex state spaces.

Limitations and Future Work

  • State Observability: The paper assumes the underlying state (e.g., position, velocity) is fully observable, even if the context is hidden. Future work could extend this to "pixels-to-actions" settings where the state itself is partially observable.
  • Sample Efficiency: While effective, the model-based approach requires a fair amount of data to learn the transition dynamics. Integrating techniques like synthetic transition generation could improve sample efficiency.
  • Discovery of New Contexts: While the model can handle a fixed set of contexts, making the system fully "continual"—where it can seamlessly add a brand-new, never-before-seen context without any retraining—remains an open challenge.

Summary updated

BibTeX
@inproceedings{ren2022reinforcement,
  author = {Hang Ren and Aivar Sootla and Taher Jafferjee and Junxiao Shen and Jun Wang and Haitham Bou Ammar},
  title = {{Reinforcement Learning in Presence of Discrete Markovian Context Evolution}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=CmsfC7u054S},
}
Figure