Reinforcement learning (RL) agents often struggle in complex, multi-object environments due to the "curse of dimensionality"—the exponential growth of possible states as objects are added. For instance, an agent might learn to interact with Object A and Object B independently during training, but fail completely when required to interact with both simultaneously in a novel configuration.
This limitation is especially severe in offline RL, where agents must learn from a fixed dataset without the ability to explore. While humans naturally use compositional reasoning to imagine "what if" scenarios, standard RL agents remain confined to the support of their training data. To address this, researchers introduce MoCoDA (Model-based Counterfactual Data Augmentation), a framework that enables RL agents to generalize to completely unseen states by leveraging "locally factored" dynamics models.
The Core Concept: Locally Factored Dynamics
The core insight behind MoCoDA is that while global environment dynamics are highly complex, they are frequently locally factored. Consider a driving scenario: the rules for staying in a lane are largely independent of whether the car is in a city or on a highway, at least until an intersection is reached. By training a model to understand how individual components of an environment interact locally, we can compose these known rules to simulate novel out-of-distribution (OOD) scenarios.
The MoCoDA Framework
The MoCoDA framework generates high-quality counterfactual data to train agents on these OOD scenarios. It operates in three main steps:
- Model the Parent Distribution: The system learns the distribution of "parents" (the specific state-action variables that causally influence a change) from the empirical training data.
- Augment the Parents: It generates an "augmented parent distribution" by creating new, unseen combinations of these parent variables (e.g., combining the dynamics of "driving on the left" with a "city environment").
- Generate Counterfactual Transitions: A learned locally factored dynamics model is applied to these augmented parents to predict the resulting next states. This yields a synthetic "augmented dataset" of transitions that the agent never actually experienced.
Crucially, MoCoDA employs a Masked Dynamics Model. This architecture uses a mask $M(s, a)$ to ensure the model only attends to the relevant parent variables for each specific component of the state update. This structural constraint is the key to its ability to generalize reliably out-of-distribution.
Experimental Validation
The paper evaluates MoCoDA on continuous control domains designed to test OOD generalization:
- 2D Navigation: An agent must navigate from the bottom-left to the top-right of a square. Training data only contains "L-shaped" trajectories. Standard agents remain stuck in these L-shapes, but agents trained with MoCoDA-U (uniform augmentation) successfully learn the optimal diagonal path.
- HookSweep2: A challenging robotics task where a Fetch robot uses a hook to sweep two boxes. The training data only shows the robot sweeping one box at a time. The target task requires sweeping both simultaneously—a completely unseen state. Standard offline RL algorithms (BCQ, TD3-BC) fail completely (< 2% success). MoCoDA achieves a 20-38% success rate, and MoCoDA-P (a variant prioritized for the specific target task) reaches an impressive 84% success rate.
Furthermore, using a standard, non-factored MLP dynamics model for augmentation performed significantly worse, proving the necessity of the factored architecture.
Key Insights and Limitations
- Local Factorization is Key: The authors prove that dynamics models respecting local factorization require exponentially fewer samples to train and provably generalize to unseen state-variable combinations.
- Overcoming the "Butterfly Effect": Even with a generalizing dynamics model, policies trained directly on original data fail due to temporal entanglement. MoCoDA bridges this gap by bringing OOD states into the training distribution via synthetic data.
- Limitations: MoCoDA currently relies on knowing (or accurately estimating) the local causal structure (the masks). It also assumes states are already decomposed into meaningful variables. Future work will need to integrate MoCoDA with unsupervised object discovery to learn these factors directly from raw inputs like pixels.
Overall, MoCoDA provides a powerful theoretical and practical framework for moving RL beyond simple imitation of training data toward true compositional reasoning in complex worlds.
Summary updated