Compositionality and Systematic Generalization › Worked Example: A Factorial Dynamical World

Michael BrenndoerferJune 24, 20264 min read
World Models HandbookAll chapters
Part 4 of 12Space, Physics, and Causality
Chapter 24Compositionality and Systematic Generalization › Worked Example: A Factorial Dynamical World
Reading section 7 of 12 · Worked Example: A Factorial Dynamical World · 4 minSection 7 of 12 · 4 min

Book contents

Section 7 of 12 · 4 min read

Compositionality and Systematic Generalization › Worked Example: A Factorial Dynamical WorldOne section · Sections in this chapter7 / 12 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Let's make all of this concrete with the smallest possible factorial world. The state is a single scalar xx. The world is described by two independent mechanisms:

  • Mechanism A (intrinsic dynamics), with three variants indexed by m∈{0,1,2}m \in \{0, 1, 2\}, each with a decay αm\alpha_m and a curvature κm\kappa_m.
  • Mechanism B (action response), with three variants indexed by n∈{0,1,2}n \in \{0, 1, 2\}, each with an action gain βn\beta_n and a state-action coupling γn\gamma_n.

The transition is:

xt+1=αmxt+κmtanh⁡(xt)⏟mechanism A  +  βnat+γn at xt⏟mechanism B  +  εt,x_{t+1} = \underbrace{\alpha_m x_t + \kappa_m \tanh(x_t)}_{\text{mechanism A}} \;+\; \underbrace{\beta_n a_t + \gamma_n\, a_t\, x_t}_{\text{mechanism B}} \;+\; \varepsilon_t,

where:

  • xtx_t: the scalar state at time tt
  • ata_t: the action taken at time tt
  • αm,κm\alpha_m, \kappa_m: the decay and curvature parameters of mechanism A variant mm
  • tanh⁡(xt)\tanh(x_t): the hyperbolic tangent of the state, which bounds the curvature contribution to magnitude at most ∣κm∣|\kappa_m|; the full intrinsic term can still grow linearly through αmxt\alpha_m x_t
  • βn,γn\beta_n, \gamma_n: the action gain and the state-action coupling of mechanism B variant nn
  • εt\varepsilon_t: small process noise added to the state at each transition, with standard deviation 0.020.02 in the implementation below

The structural form of this equation is the entire point of the exercise. The right-hand side is a literal sum of a mechanism-A term and a mechanism-B term, with no interaction between them, so the true dynamics satisfy the additive factorization exactly. This is the ideal case for a factorized model: its inductive bias is not an approximation of the truth but a restatement of it. The two mechanisms are also semantically distinct, one governing how the state evolves on its own and one governing how actions perturb it, so the factorization matches a natural physical reading of the world rather than a mere algebraic convenience.

There are 3×3=93 \times 3 = 9 worlds. We will train on six of them and hold out the anti-diagonal: (m=2,n=0)(m{=}2, n{=}0), (m=1,n=1)(m{=}1, n{=}1), and (m=0,n=2)(m{=}0, n{=}2).

To see the composition rule in action, fix xt=2x_t = 2 and at=−1a_t = -1, and ignore noise. Mechanism A with m=1m=1 contributes 0.85×2−0.3×tanh⁡(2)=1.70−0.29≈1.410.85 \times 2 - 0.3 \times \tanh(2) = 1.70 - 0.29 \approx 1.41, using tanh⁡(2)≈0.96\tanh(2) \approx 0.96. Mechanism B with n=0n=0 contributes 0.8×(−1)=−0.80.8 \times (-1) = -0.8, giving xt+1≈1.41−0.80=0.61x_{t+1} \approx 1.41 - 0.80 = 0.61. Mechanism B with n=1n=1 instead contributes 1.6×(−1)+0.2×(−1)×2=−1.6−0.4=−2.01.6 \times (-1) + 0.2 \times (-1) \times 2 = -1.6 - 0.4 = -2.0, giving xt+1≈1.41−2.0=−0.59x_{t+1} \approx 1.41 - 2.0 = -0.59. The two worlds share the intrinsic term exactly and differ only in the action response. If a model has adequately identified both contributions on the state-action support used by the held-out rollout, the valid additive rule determines their combination; learning a separate categorical world embedding supplies no corresponding constraint on (1,1)(1,1).

The arithmetic makes the data-sharing argument tangible. Every training world with m=1m=1 in our split, namely (1,0)(1,0) and (1,2)(1,2), provides observations of the same intrinsic term 0.85x−0.3tanh⁡(x)0.85 x - 0.3\tanh(x), and every world with n=1n=1, namely (0,1)(0,1) and (2,1)(2,1), provides observations of the same action-response term. The held-out world (1,1)(1,1) asks the model to add two familiar contributions. In the true simulator the pairing introduces no interaction term, but finite data, limited excitation, optimization, and off-support component error can still leave the learned contributions inaccurate.

The composition rule can be drawn directly: each mechanism contributes a curve over states, and the held-out prediction is simply their sum.

In[13]:
Code
## Mechanism contribution curves for mechanism A variant m=1 and
## mechanism B variant n=1 over a range of states, at action a=-1.
## Parameters match FACTOR_A[1] and FACTOR_B[1] from the worked example.
x_range = np.linspace(-2.5, 2.5, 200)
action = -1.0
contrib_a = 0.85 * x_range + (-0.30) * np.tanh(x_range)
contrib_b = 1.60 * action + 0.20 * action * x_range
composed = contrib_a + contrib_b
Out[14]:
Visualization
Two mechanism contribution curves and their sum over a state range.
Additive composition of the two mechanisms at action a=-1. The held-out world (A=1, B=1) is predicted by summing two contribution curves, each learned from worlds with different partners.