Control as Inference and Active Inference › From Cost Minimization to Beliefs About Optimality
World Models HandbookAll chapters Control as Inference and Active Inference › From Cost Minimization to Beliefs About OptimalityOne section · Sections in this chapter2 / 10 ↓
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
Recall the picture from Classical Planning and Optimal Control: a Markov decision process with dynamics and a cost or reward signal, solved by dynamic programming to produce a policy that maximizes expected discounted return. The solution is prescriptive. It tells you what to do. The Bellman equation is a command: at each state, take the best action, where "best" is defined with all the force of an argmax operator. There is no room in that formalism for hesitation between two nearly equivalent routes, no place to record that three different behaviors were all pretty good, and no mechanism by which acting stochastically could ever be rational if acting deterministically is available.
Control as inference is descriptive first and prescriptive second. We start with bare dynamics and no special status for actions: a trajectory is simply drawn from a generative model in which states evolve and actions occur according to some vague prior. Then we bolt on one extra piece of evidence: a binary variable for each timestep that says whether time was "optimal". Conditioning on the observation that every timestep was optimal converts the generative model into a distribution over near-optimal behavior. Solving the control problem now looks like a familiar statistical task: compute (or approximate) a posterior. Notice what has happened to the direction of reasoning: instead of pushing preferences forward through time to decide what to do, we assume good behavior exists and reason backward to discover what it looks like.
Instead of defining an objective functional to maximize directly, control as inference defines a distribution over optimal behavior and treats the policy as that distribution's marginals:
where denotes the event that every timestep was optimal. Optimality is evidence, and control is posterior inference.
Why go through this indirection? It would be fair to object that we are making life complicated on purpose: we had a working optimization framework, and we wrapped it in probabilistic clothing. The probabilistic formulation adds capabilities the bare optimization framework structurally lacked. Three reasons recur throughout the literature.
- Planning becomes inference tooling. Any approximate posterior machinery, message passing, variational inference, Monte Carlo sampling, becomes a candidate planner. This is a substantial practical dividend. The community has spent decades building fast, scalable, well-understood inference algorithms for graphical models; the moment planning is phrased as posterior computation, that entire library of machinery applies directly to decision-making without modification.
- Exploration becomes automatic. The posterior over optimal trajectories is multimodal: it spreads mass over all behaviors that plausibly earned high return, rather than collapsing onto a single deterministic winner. We will see that this yields maximum-entropy reinforcement learning. Nobody writes "add noise for exploration" into the algorithm; the hedging is intrinsic to conditioning on soft evidence, and its magnitude is set by a single interpretable dial.
- Agents that reason about their own models get a unified currency. As we saw in Bayesian Filtering and Belief States, perception is already posterior inference over latent state. Control as inference makes action the same kind of computation over the same kind of object. Perception and action stop being two modules glued together and become two uses of one calculus, which is precisely the unification that makes world-model-based agents conceptually coherent.
The Optimality Variable and Its Graphical Model
Let us make the construction precise. Fix a finite horizon . The generative model over trajectories has the usual chain structure, with one addition per timestep: an optimality node that depends on and is treated as observed. This dependence structure matters: hangs off the state-action pair like a sensor reading, since optimality is judged by what happened at that step alone, mediated through nothing else in the graph.
Read the graph left to right: latent states chain forward, actions are drawn from a (typically uniform) prior, and each pair of state and action emits evidence about its own optimality. Nothing in this graph knows about rewards yet. It describes a random system bumbling through states taking arbitrary actions, exactly the setup from which HMM smoothing begins. The reward enters through one modeling choice, a single sentence linking evidence to reward:
Here denotes an unnormalized factor: the omitted multiplier is independent of at each timestep. That convention is what lets the product of omitted multipliers be absorbed into one trajectory-level normalizer. The function is the familiar reward and is a temperature: small means optimality evidence is sharp and demanding, while large tolerates sloppy, high-entropy behavior. Equivalently, is the inverse temperature. The terminology comes from statistical physics, where temperature governs how strongly a Boltzmann distribution concentrates on low-energy configurations; here it plays the same role with reward standing in for negative energy. The message-passing section below shows how the exponential form permits backward recursions and how a common maximum-entropy relaxation restores the Bellman machinery from the previous chapter.
Conditioning on all optimality nodes gives the core object of the whole framework:
This is worth pausing on, because the entire chapter lives inside this equation. Under the unnormalized-factor convention above, all state-action-independent multipliers are absorbed into , leaving the dynamics prior tilted by the exponential of trajectory return. High-return trajectories occupy most of the posterior mass; mediocre ones retain some; terrible ones are exponentially suppressed but never eliminated. Because exponential weighting never assigns exactly zero probability to anything, even catastrophically bad trajectories survive with vanishing-but-positive weight, which will matter when we discuss exploration and robustness later. The sum in the exponent is the plain additive return from Part II Chapter 1, which is precisely why reward and optimality evidence can be identified without changing the underlying decision problem. Had we chosen any other encoding, the quantity being traded off across timesteps would not be return, and we would have silently invented a different objective.
is an auxiliary binary random variable whose likelihood is tied to reward by . It has no physical meaning; it is a scaffolding device that lets us phrase a decision problem as conditional probability. Ziebart's inverse reinforcement learning tradition and Levine's synthesis popularized this framing; related path-integral control work arrived at equivalent exponential weightings through stochastic optimal control.
One honesty checkpoint before proceeding. Treating an event like "this trajectory had return " as having probability stretches the word probability. As written, the exponential is an unnormalized weight: it is not probability mass, and calling it a likelihood would require specifying a base measure and normalization. (A continuous density may exceed one, so magnitude alone is not the objection.) The clean return tilt also relies on the omitted factor being independent of state and action; normalizing the binary conditional separately at every would generally introduce state-action-dependent constants and change the posterior. The partition function is mathematically well defined, but it need not be the physical chance of witnessing a repeatable optimality event. The construction survives because we use relative weights within the posterior, and those ratios remain well defined regardless of whether the absolute scale has a physical interpretation. The practical boundary is therefore simple: treat the exponential as an unnormalized tilt, not as a calibrated physical probability, and test the induced ranking under the stochastic outcomes that matter.
Messages Are Values: Soft Bellman Equations
Computing the full trajectory posterior by enumerating trajectories is hopeless, since the number of length- trajectories grows exponentially in both horizon and branching factor; even our humble grid admits action sequences within the rollout horizons we will sample shortly. But we do not need to enumerate anything. A backward message produces the causally conditioned action distribution used for control. Full smoothing marginals under combine that backward message with a forward message, exactly as HMM smoothing combines both directions without enumerating state sequences. The remarkable fact is what the backward messages turn out to be.
Define dimensionless backward log-messages and . Log-space converts products of evidence into sums. For stochastic transitions, exact marginalization gives
The logarithm sits outside the next-state expectation. Replacing this risk-sensitive state aggregation with a linear expectation yields the familiar entropy-regularized Bellman operator used by maximum-entropy reinforcement learning,
When , replacing the log-of-expectation state update by a linear expectation is exact for deterministic transitions. The stationary operator displayed here uses later in the grid world, so even with deterministic dynamics it should be read as the fixed point of a discounted maximum-entropy control objective, not as the exact backward-message recursion of the finite optimality graph. Its action aggregation is an actual log-sum-exp, so as the induced policy concentrates on hard-max actions; as grows, inferior actions receive more mass. Encoding a discounted return directly in the optimality graph would instead use time-dependent evidence factors such as ; the resulting exact recursion carries that time dependence and is not the stationary -on-value operator above.
We can watch this interpolation happen directly. Take four illustrative action values with the spread produced by our grid world, compute the implied Boltzmann weights across a range of temperatures, and plot each weight against its value: as shrinks, mass collapses onto the best action; as it grows, all actions converge toward equal weight.
import numpy as np
# Stand-in action values for one state, with spreads typical of the
# low-temperature solutions computed later in this chapter.
demo_Q = np.array([2.90, 3.10, 2.70, 2.30])
temperatures = np.array([0.05, 0.10, 0.25, 0.50, 1.00, 2.00])
def softmax_weights(q_values, beta):
z = q_values / beta
z = z - z.max()
w = np.exp(z)
return w / w.sum()
softmax_curves = {float(b): softmax_weights(demo_Q, b) for b in temperatures}
At the top-valued action holds nearly every unit of weight, the visual signature of a recovered Bellman backup. At the four actions sit almost shoulder to shoulder near one quarter each, evidence that has nearly stopped constraining anything.
Discounting by mirrors how classical control discounts future rewards; in the purely probabilistic reading, finite horizons induce similar decay, and can be seen as either a modeling choice about patience or an analytic convenience for keeping infinite-horizon sums finite.
To connect the message notation to the usual reward-scale action value, define . The action prior remains part of the marginal:
For the uniform action prior used throughout the worked example, is the same for every action and cancels during normalization, leaving the familiar softmax . The demo_Q values above are on this reward scale, so softmax_weights(demo_Q, beta) divides by temperature exactly once.
This is the celebrated Boltzmann (softmax) rationality rule. The little equation is one of the most reused artifacts in modern decision-making research, and it is worth appreciating just how far it travels. It appears as an assumption about human irrationality in behavioral economics, where noisy choices are modeled as deterministic preferences plus thermal perturbation; as the choice model underpinning inverse reinforcement learning, where recovering rewards from demonstrations requires assuming something about how demonstrators soften their own optimality; as the temperature in language-model sampling, where the same dial trades fluency against diversity; and as the exploration rule in dozens of RL algorithms. Here we derived it; nowhere did we tell the agent to explore stochastically. Stochasticity falls out of the posterior, with probability mass allocated across actions in exact proportion to how plausible each is under the optimality hypothesis.
Backward message passing in the finite chain is exact when it retains the log-of-expectation state update above. The stationary linear-expectation recursion is a maximum-entropy control relaxation that can be run as value iteration with a softened action maximum. Planning and belief propagation therefore share a common algebraic template, but they are not interchangeable under every stochastic model. Keeping that boundary explicit lets us borrow inference intuitions without claiming exact marginals where the implemented operator computes a control surrogate.
Running the soft Bellman operator to a fixed point is equivalent to maximizing the entropy-regularized objective
so the soft Bellman fixed point exactly solves this discounted reward-and-policy-entropy objective. Its identification with the exact optimality-conditioned trajectory posterior is narrower: it holds in the deterministic, undiscounted () special case described above. With stochastic dynamics or , control as inference motivates a variational or Bellman surrogate rather than the same exact posterior marginal (see Levine's 2018 tutorial, Haarnoja et al.'s soft actor-critic line, and Fox, Pakman, and Tishby on the variational side). Entropy bonuses and exponential tilting therefore share an algebraic language without becoming identical constructions in every setting.
This equivalence is not merely elegant. It matters practically because a maximum-entropy policy can act as a distributed hedge: it keeps mass on alternative routes, so ordinary replanning has options available after a model error. That is a useful design intuition, not a universal robustness guarantee; a soft policy can still spread probability onto dangerous actions. The warehouse experiment's Temperature Dial below measures this instance directly with seeded closed-loop rollouts, plotting mean return and policy entropy across seven temperatures. The observed direction is an empirical property of this setup, not a theorem for every environment.