Abstract
Standard reinforcement learning algorithms often struggle in environments with non-stationary dynamics, where physical properties or task goals change over time. We present Latent Context-based Soft Actor Critic (LC-SAC), an extension of the Soft Actor-Critic (SAC) framework designed for such settings. LC-SAC utilizes a recurrent context encoder to distill historical transitions into a latent context variable, which is then used to condition the agent's policy and value functions. By employing contrastive learning via the InfoNCE loss, the encoder captures essential environmental characteristics. Our evaluations on MuJoCo and MetaWorld benchmarks demonstrate that LC-SAC significantly improves performance in non-stationary tasks while maintaining stability in stationary ones.
Introduction
Deep Reinforcement Learning (DRL) has achieved remarkable success in various domains. However, most state-of-the-art algorithms, such as Soft Actor-Critic (SAC), rely on the assumption of environment stationarity. In real-world applications, robots frequently encounter changing conditions—such as varying object weights, shifting target locations, or mechanical wear—that violate this assumption. Without a mechanism to recognize and adapt to these changes, agents often fail to generalize across different episodes, treating every interaction as if it occurs in a vacuum.
To address this, we propose LC-SAC. The core idea is to provide the agent with "situational awareness" by encoding recent experiences into a latent context variable. This variable serves as an implicit memory, allowing the agent to distinguish between different environmental dynamics and adapt its behavior accordingly.
Methodology
The LC-SAC framework integrates a Latent Context Encoder into the standard SAC architecture to handle non-Markovian dependencies.
Latent Context Encoder
The encoder processes a sequence of recent transitions $e_t = (s_t, a_t, r_t)$. As illustrated in Figure 1, the architecture utilizes linear layers followed by a Long Short-Term Memory (LSTM) network to capture temporal dependencies from the history of states, actions, and rewards. The output is mapped to a latent context variable $c$, which represents the current environmental "mode."
Contrastive Learning and Policy Integration
To ensure the context variable $c$ captures meaningful information about the environment's dynamics rather than noise, we employ contrastive learning. Specifically, the InfoNCE (Information Noise Contrastive Estimation) loss is used to maximize the mutual information between the context and future transitions.
As shown in the overall framework (Figure 2), the learned context $c$ is concatenated with the current state $s$. The policy network $\pi_\theta(a|s, c)$ and value networks $Q_\phi(s, a, c)$ are then conditioned on this augmented input. This transformation effectively converts a non-stationary problem into a stationary one from the perspective of the policy by including the necessary historical context.
Experiments and Results
We evaluated LC-SAC on two distinct benchmarks: MuJoCo for stationary continuous control and MetaWorld ML1 for non-stationary meta-learning tasks.
Performance in Non-stationary Environments
In MetaWorld ML1 tasks (e.g., Push-v2, Reach-v2, and Pick-Place-v1), where object and target positions vary significantly across episodes, LC-SAC demonstrated substantial improvements over baseline SAC. While standard SAC struggled to learn a consistent policy due to the changing goal locations, LC-SAC successfully identified the task variant from initial interactions and achieved high success rates.
Stability in Stationary Environments
Testing on MuJoCo benchmarks (Ant, HalfCheetah, Hopper, Humanoid) confirmed that LC-SAC does not degrade performance in stable environments. Although the additional complexity of the LSTM and contrastive loss can slightly slow initial convergence in simple tasks like HalfCheetah, the final performance remains comparable to standard SAC, proving the algorithm's robustness.
Discussion and Limitations
A key insight from our study is the effectiveness of deterministic context variables. While probabilistic approaches (like PEARL) are common, we found that deterministic variables led to faster and more stable policy improvements in our specific architecture.
However, LC-SAC introduces some trade-offs. The use of LSTMs and contrastive loss increases training time and memory requirements. Furthermore, the performance is sensitive to hyperparameters, particularly the dimension of the context variable and the update frequency of the encoder. Updating the context encoder slightly more frequently than the policy was found to be critical for maintaining a stable "worldview" for the agent.
Conclusion
LC-SAC provides a robust framework for reinforcement learning in non-stationary environments. By combining recurrent context encoding with contrastive learning, agents can effectively adapt to changing dynamics. Future work will explore more complex non-stationary scenarios and optimize the encoder architecture to reduce computational overhead while handling longer-term dependencies.
Summary updated