Manuscript Offprint
arXiv:2610.32414When Does Dynamics Randomization Test Context Inference?
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.
Oleg Smirnov
King AI Labs, Microsoft Gaming
John Pertoft
King AI Labs, Microsoft Gaming
Sofiane Ennadir
King AI Labs, Microsoft Gaming
Bjartur Hjaltason
King AI Labs, Microsoft Gaming
Sara Karimi
King AI Labs, Microsoft Gaming & KTH Royal Institute of Technology
Abstract: Environments with randomized dynamics are widely used to ask whether world models need explicit context inference. However, randomization can leave little predictive information for a context encoder to add, because distinct latent parameters may produce similar transitions at visited states, or those states may already reveal the active context. We formalize the remaining one-step information as predictive headroom and compare kernels under fixed and visited state–action distributions to distinguish changes in query coverage from changes in context weights. We analyze discrete and continuous environments and find low headroom both when kernels differ little and when visitation reduces an otherwise large discrepancy. At the same time, resetting state components increases headroom, showing that context evidence accumulates in state. We propose reporting this headroom alongside the randomized parameters, so that gains from explicit context inference can be interpreted relative to the information missing from the current state and action.
1 Introduction
In model-based RL, environments with randomized dynamics are commonly used to test whether world models benefit from explicit context inference. Latent physical parameters, such as masses and forces, can vary across episodes, and models that infer the active context are compared against context-blind predictors. However, a benchmark can randomize parameters and still leave a context mechanism little predictive information to add.
Contextual MDPs formalize latent dynamics that vary across episodes [1, 2]. Online system identification conditions a policy on parameters inferred from recent experience [3]. Adaptive dynamics models [4] and context-aware predictors [5, 6] use experience to improve prediction under changing parameters. While those methods make predictive structure explicit, we quantify how much information about transitions the current state withholds before any such mechanism is added.
We identify two mechanisms that can reduce the remaining predictive information. First, kernels that differ substantially across the state space may differ little at the visited state–action pairs. A wall, for example, can block the displacement induced by wind. Second, the dynamics can make visited states already informative about the hidden parameter. For instance, a persistent force changes both position and velocity, so the current state can contain information accumulated over earlier transitions. Even a memoryless model can then use this evidence without a history encoder. A small gain from revealing the true context can thus reflect weak kernel differences or implicit identification.
We introduce an experimental diagnostic of context information under a given visitation. We compare transition kernels under a fixed reference and at visited state–action pairs using prior context weights, then reweight contexts by visitation to estimate the remaining predictive headroom. We show, in discrete and continuous settings, that similar headroom can arise from differing kernel variation. We propose reporting this measure when comparing world models, because explicit context inference can add predictive information only where the inputs miss it.
Predictive headroom. The optimal predictor uses the mixture , whereas revealing context instead gives . Their minimum expected one-step log-loss difference is
This quantity measures the transition information context adds beyond the current pair, and can be estimated using known kernels and fitted context mixtures. While the target concerns information in the inputs, a learned world model can still incur approximation or optimization error.
Fixed-reference and matched-query variation. Define the prior mixture and the local prior-weighted separation . We compare
where is a fixed, context-independent query distribution. Therefore, can be used to compare kernels at common queries, while is used to evaluate their differences where data were collected, retaining prior context weights in both.
The structural-to-matched comparison changes query coverage only. The matched-to-visited comparison holds queries fixed and replaces prior context weights by in both the outer average and the predictive mixture. This reweighting reflects state-dependent evidence and any marginal shift caused by pooling episodes of unequal length. We note that since the comparisons use different distributions, those quantities do not constitute general bounds on one another.
Low matched variation indicates that context changes little about one-step outcomes on the visited support. A large matched-to-visited reduction shows that context reweighting matters. To attribute that reduction to state-mediated identification, we must account for changes in marginal context weights . A concentrated marginal alone can reduce headroom even when state is independent of context. We collect uniformly random actions, so any context evidence in the predictor inputs comes from state.
3 Controlled evidence
Environments. MiniGrid [7] provides an enumerable state space , with position and direction on an Empty-8x8 grid. We use a Wind variation that samples independent drift coordinates from . After each native action, each axis moves one cell in the sampled direction with probability equal to its drift magnitude, subject to wall blocking. In another variation, Resistance samples an action-failure probability , and a failed action leaves the state unchanged. Finally, we consider Point-Mass-Attractor as a continuous two-dimensional system with observed position and velocity, where one of four hidden corners exerts force alongside the action, with independent position and velocity noise and reflecting boundaries.

Figure 1: Dynamics variation and predictive headroom across perturbation strengths. (a,b) Wind and Resistance mechanisms. (c–e) The structural reference and estimated visited headroom differ substantially on Wind and Attractor but remain close on Resistance. Attractor's structural curve uses the interior Gaussian reference. Shading shows bootstrap intervals.
Table 1: Comparisons at representative settings. Fixed and matched columns retain prior context weights, while visited headroom uses fitted visitation-dependent weights. Attractor's identical prior references use its query-invariant interior kernel. Uncertainties are the larger one-sided deviations from the bootstrap intervals.
| Setting | Fixed | Matched | Visited |
|---|---|---|---|
| Wind () | 0.871 | 0.620 | 0.077 ± 0.002 |
| Resistance () | 0.062 | 0.059 | 0.055 ± 0.001 |
| Attractor () | 1.006 | 1.006 | 0.109 ± 0.002 |
We experiment with 5,000 episodes in each setting under uniform random actions: up to 256 steps in MiniGrid and 50 in Attractor, where the fixed episode length avoids duration-induced context reweighting. Context labels are logged for the diagnostic and excluded from the state-action predictive information set. We evaluate transition prediction without training policies or comparing returns.
Estimation. MiniGrid's structural reference is uniform over interior positions, four directions, and seven actions. There, we enumerate the kernels and integrate the continuous context prior. Visited headroom averages exact kernel KL divergences against mixtures fitted at each pair, leaving out the scored episode and applying one pseudo-count of smoothing. In Attractor, we use its query-invariant interior Gaussian kernel for the prior references. Its visited estimate scores logged next states under the known kernels, including boundary reflection, against a mixture with a five-fold, episode-split nearest-neighbor context posterior.
The estimates retain all transitions. MiniGrid refits its mixtures, whereas Attractor resamples fixed per-episode contributions. Attractor neighbor-count selection uses the scored folds' context labels, and its intervals omit posterior refitting uncertainty. We report fitted-predictor estimates, rather than exact mutual information, along with uncertainties. Implementation details are deferred to Appendix A.
Sources of low headroom. Figure 1 illustrates that visited headroom can remain low as dynamics variation increases. In Wind (Table 1), matching the query distribution reduces the reference by , so coverage accounts for part of the difference. Using visitation-dependent context weights at those same queries removes a further of the matched reference. This comparison measures changes in context weights under the collection distribution, including any shift in marginal context frequencies.
In Resistance, prior-weighted separation changes little under either comparison, and visited headroom retains about of the matched reference. Its low headroom mostly reflects weak kernel differences under these query and action weights. In Attractor, the prior reference is large but estimated visited headroom is about of that interior reference.
Table 2: State resets increase predictive headroom without changing episode context. Full resets resample position and direction in Wind. In Attractor they resample position and zero velocity. Changes in parentheses use each intervention dataset's own no-reset baseline, collected separately from the sweep datasets.
| Reset | Wind | Attractor |
|---|---|---|
| None | 0.078 ± 0.002 | 0.112 ± 0.002 |
| Full, every 10 steps | 0.411 ± 0.006 (+430%) | 0.473 ± 0.004 (+324%) |
| Full, every 2 steps | 0.723 ± 0.017 (+833%) | — |
| Position only, every 10 steps | — | 0.143 ± 0.003 (+28%) |
State-component resets. We reset selected components before recording the current state, keeping the episode context and uniform action rule unchanged. Wind resamples valid position and direction uniformly, while Attractor resamples position uniformly in and either zeroes or preserves velocity. Table 2 shows that frequent Wind resets increase predictive headroom. In Attractor, resetting both position and velocity raises headroom more than resetting position alone. The resets leave the transition family fixed while changing both query coverage and the posterior over context. The baseline Wind comparison separates these contributions, but no reset-specific matched references are reported. The reset comparisons show that context information accumulates in state, including velocity, but do not isolate its effect from changes in coverage.
4 Implications for evaluating world models
Low headroom can explain a small gain from explicit context inference when the observed state already supplies most of the evidence needed for prediction. High headroom instead indicates that revealing context can improve prediction. However, one should separately measure which information a learned representation retains and how well its predictor uses it, since a context encoder can still improve learning or approximation even when headroom is low. Comparisons of predictors with and without explicit context inference should therefore measure both the information available in the inputs and the errors of the actual models under matched data and compute.
We propose reporting whether a benchmark's context-conditional kernels remain predictively distinct at overlapping observed states. This requires specifying the collection rule, predictive inputs, transition weighting, and marginal context frequencies relative to the design prior. A low matched reference suggests changing the queries or perturbations, whereas a large matched-to-visited reduction requires distinguishing context imbalance from information retained in state. Increasing the parameter range alone does not resolve either issue reliably. We can compute these comparisons from context labels and simulator kernels, but with learned kernels we must also account for prediction error.
Initial-state distributions, episode length, and observed physical coordinates also influence how much context remains hidden. A reset that changes position but preserves velocity can retain context information that the benchmark is intended to withhold. We therefore recommend reporting matched-query variation under each reset protocol's collection distribution to separate changes in the prediction support from changes in context weights when interpreting the resulting headroom.
We note that our measurements concern one-step prediction on the collection distribution, while a model deployed for planning or new goals may need predictions at states and actions rarely represented there. Broad counterfactual coverage and low on-distribution headroom are compatible. We propose examining the evaluation support before interpreting task success or a small context benefit as evidence about the need for explicit predictive structure. For learned policies or physical robots, this requires measurements under their own prediction and control conditions.
5 Conclusion
Dynamics randomization alone does not establish that a benchmark tests context inference. Our controlled examples show that similar predictive headroom can accompany very different kernel variation, and that observed state can retain evidence about hidden dynamics. Reporting this headroom would help distinguish limited opportunity for context inference from weaknesses of the methods being compared, making such benchmarks more informative about when explicit context inference in world models has information to add.
References
[1] A. Hallak, D. Di Castro, and S. Mannor. Contextual Markov decision processes, 2015. URL https://arxiv.org/abs/1502.02259.
[2] F. Doshi-Velez and G. Konidaris. Hidden parameter Markov decision processes: A semiparametric regression approach for discovering latent task parametrizations. In Proceedings of the Twenty-Fifth International Joint Conference on Artificial Intelligence, pages 1432–1440. IJCAI/AAAI Press, 2016. URL https://www.ijcai.org/Proceedings/16/Papers/206.pdf.
[3] W. Yu, J. Tan, C. K. Liu, and G. Turk. Preparing for the unknown: Learning a universal policy with online system identification. In N. M. Amato, S. S. Srinivasa, N. Ayanian, and S. Kuindersma, editors, Robotics: Science and Systems XIII, Massachusetts Institute of Technology, Cambridge, Massachusetts, USA, July 12-16, 2017, 2017. doi:10.15607/RSS.2017.XIII.048. URL http://www.roboticsproceedings.org/rss13/p48.html.
[4] A. Nagabandi, I. Clavera, S. Liu, R. S. Fearing, P. Abbeel, S. Levine, and C. Finn. Learning to adapt in dynamic, real-world environments through meta-reinforcement learning. In International Conference on Learning Representations, 2019. URL https://openreview.net/forum?id=HyztsoC5Y7.
[5] K. Lee, Y. Seo, S. Lee, H. Lee, and J. Shin. Context-aware dynamics model for generalization in model-based reinforcement learning. In International Conference on Machine Learning, pages 5757–5766. PMLR, 2020.
[6] B. Evans, A. Thankaraj, and L. Pinto. Context is everything: Implicit identification for dynamics adaptation. In 2022 International Conference on Robotics and Automation (ICRA), pages 2642–2648. IEEE, 2022.
[7] M. Chevalier-Boisvert, B. Dai, M. Towers, R. Perez-Vicente, L. Willems, S. Lahlou, S. Pal, P. S. Castro, and J. Terry. MiniGrid & MiniWorld: Modular & customizable reinforcement learning environments for goal-oriented tasks. In Advances in Neural Information Processing Systems, volume 36, pages 73383–73394, 2023. doi:10.52202/075280-3209.
A Implementation and estimation details
MiniGrid kernels. Both families retain the Empty-8x8 layout, goal, and reward. The logged episodes start at , facing right, and end on goal termination at or truncation at 256 steps. The native action updates position or direction first. For Wind, each coordinate specifies drift sign( ) with probability , and no drift otherwise. A proposed displacement into a wall is blocked. Resistance executes the native action with probability and otherwise leaves position and direction unchanged. The fixed reference enumerates state-action queries. Continuous contexts are integrated by quadrature, without context binning. The sweeps use and .
For visited headroom, we group known kernels at logged contexts by state–action cell. For each scored episode, we fit the mixture using the other episodes and add one uniform pseudo-row over that cell's kernel outcome support. The score integrates KL over the discrete next-state outcomes rather than using only the realized next state. The 200 percentile bootstrap resamples reweight entire episodes and recompute the mixtures. The point estimate assigns equal weight to pooled transitions.
Attractor dynamics. The point mass has unit mass, timestep , and uniformly sampled context (Figure 2). With force and independent actions , the noiseless update is followed by . Independent Gaussian increments have per-coordinate variances for velocity and for position, with . A single reflection per axis at the workspace boundaries reverses velocity with damping factor 0.5. Initial position is uniform in and initial velocity is zero. The sweep uses .
Before reflection, context changes only the Gaussian mean displacement, so the prior-weighted information is independent of the query. We evaluate both fixed and matched references from this interior kernel by one-dimensional quadrature for each coordinate. For visited scores, we compute the reflected density by summing its preimages with their Jacobians.
Attractor posterior fitting. Five episode-level folds produce nearest-neighbor class frequencies from standardized position and velocity, with one Laplace pseudo-count for each of the four contexts. Actions are independent uniform draws, so the posterior uses state features only. Neighbor counts in are compared by context log loss on the same scored folds. At each logged next state, the estimator subtracts the fitted mixture log density from the true-context log density and averages over all transitions. The 1000 percentile bootstrap resamples use fixed episode sums and counts, without refitting or repeating neighbor selection. These intervals summarize sampling variation conditional on the fitted predictions, not the full estimation uncertainty. Even known component kernels do not make the visitation-dependent posterior exact.
As a local check, immediately after a zero-velocity position reset the context posterior is the known uniform prior. At reset interval ten, the fitted mean log-density contrast on those transitions is 1.0110 nats, versus 0.9961 when using the known prior. At interval two the corresponding values are 1.0093 and 1.0071. This checks the estimator on the reset stratum, not on all visited states.

Figure 2: Point-Mass-Attractor force fields. The first four panels show the context-dependent force for each kernel . The final panel shows the prior-averaged force .