Levine reframes the control problem as probabilistic inference in a graphical model with binary optimality variables, where the trajectory posterior weights paths by exponentiated reward. Exact inference gives a soft value iteration — softmax in place of max — but with an optimism bias under stochastic dynamics; variational inference fixes it and lands exactly on maximum-entropy RL, whose practical faces are soft Q-learning and soft actor-critic.
The lecture opens with a question about modeling: does optimal control provide a
reasonable model of human and animal behavior? A monkey moving a cursor to a target
usually reaches it — but by a different route each time, sometimes lazily indirect.
The mistakes aren’t uniform noise: with practice they “tend to occur in ways that
matter less for the success of the task.” The monkey knows the manner of reaching
the goal barely affects the reward, so it lets that part be sloppy.
The RL framework we’ve built cannot express this. For any objective that is linear
in the state–action marginal, every fully observed MDP admits a deterministic
optimal policy — so randomness can never be rational under hard optimality. Yet
natural agents faced with the same situation twice don’t do the same thing, and
“good behavior is still the most likely” without being the only behavior. We need a
probabilistic model of near-optimal behavior, and Levine flags three reasons to
want one: it explains sub-optimal demonstrations (crucial for the inverse RL lecture
that follows), it lets us attack control with the whole toolbox of inference
algorithms, and it explains why stochastic behavior helps exploration and transfer.
A graphical model in which inference is control
Take the usual MDP chain of states and actions with transitions
p(st+1∣st,at) — that alone carries “no assumption of optimal behavior.”
To encode why an agent picks one action over another, add one node per time step:
The choice looks arbitrary — Levine admits as much twice — but it earns its keep
immediately. Bayes’ rule on the trajectory posterior gives
where p(τ) carries only the dynamics and initial state. With deterministic
dynamics, p(τ) is an indicator of physical consistency, and the picture is
exactly the sloppy monkey: the highest-reward trajectory is the most likely, equal-
reward routes are chosen at random, and probability decays exponentially as reward
drops — so the agent will wander on the way to the goal but will not fail to reach it.
Exact inference: backward messages and soft value functions
Three inference problems matter in this chain-structured model, and they’re solved
the way you’d solve an HMM — by message passing. The backward messageβt(st,at)=p(Ot:T∣st,at) is the probability of being
optimal from now to the end. Insert st+1 and integrate it out; conditional
independence of future optimality variables given st+1 factorizes the result
into the transition, the current exp(r) term, and the next message, giving the
recursion (run backward from βT=p(OT∣sT,aT)):
The action prior p(at∣st) — how likely actions are before you know
whether the agent is optimal, emphatically not the policy — is assumed uniform, and
this loses nothing: any non-uniform prior can be folded into the reward as
r~=r+logp(at∣st) and the machinery rerun with a uniform prior.
Now define Vt(st)=logβt(st) and Qt(st,at)=logβt(st,at)
and the recursion becomes eerily familiar:
The first equation is a log-sum-exp — a soft max: as the Q values grow, it
approaches maxaQt. Value iteration’s hard max over actions has been softened,
“which kind of makes sense — we want to soften our notion of optimality so that
slightly sub-optimal things are still possible.” The second equation is a Bellman
backup when the dynamics are deterministic (one term in the expectation, log and exp
cancel), but under stochastic dynamics the log-expected-exp is dominated by the
luckiest next state — an optimism problem we’ll return to.
The policy is the posterior p(at∣st,O1:T). Past
optimality variables are d-separated by st, and applying Bayes’ rule to numerator
and denominator simultaneously collapses everything into a ratio of messages:
Forward messagesαt(st)=p(st∣O1:t−1) come from the
mirror-image recursion, and their product with backward messages gives state
marginals: p(st∣O1:T)∝βt(st)αt(st).
Picture two cones — one radiating backward from the goal (states from which you can
still reach it), one forward from the start (states reachable with high reward) —
with near-optimal behavior living in their intersection. Human reaching experiments
actually show this cigar-shaped state distribution: tight at start and goal, widest
in the middle. Forward messages aren’t needed for the policy, but they are the
workhorse of inverse RL in the next lecture.
The optimism problem, and the variational fix
What we actually want is “given that you obtained high reward, what was your action
probability, given that your transition probabilities did not change?” That is a
variational inference problem: find q(s1:T,a1:T) close to the posterior
p(s1:T,a1:T∣O1:T) but constrained to the true dynamics.
The trick is a peculiar variational family where most of q is fixed to match p:
Only the action conditional is learned. With x=O1:T and
z=(s1:T,a1:T), this is exactly the q(z)≈p(z∣x) setup from
the variational inference lecture, so write the evidence lower bound:
Optimizing the bound by dynamic programming from the last step backward uses one
recurring fact: an objective of the form
Eq[something]−Eq[logq] is maximized by
q∝exp(something). Each step therefore gives
q(at∣st)=exp(Qt(st,at)−Vt(st)) with V the log-integral-exp
normalizer — and, crucially, the backup for Q is now the regular Bellman backup
Qt=r+E[Vt+1], “not optimistic anymore.” The result is soft
value iteration: identical to value iteration except
V(s)←softmaxaQ(s,a) replaces the hard max. Variants
follow mechanically: a discount γ (equivalently a 1−γ chance of
death), an explicit temperature, and an infinite-horizon version that just runs the
backup to convergence.
The variational picture instantiates directly as deep RL algorithms.
Alternatively, attack the bound directly with policy gradients:
J(θ)=∑tEπθ[r(st,at)]+H(πθ(at∣st))
is the standard objective plus an entropy bonus — the widely used
entropy-regularized policy gradient, which combats premature collapse of policy
entropy (on-policy exploration lives entirely in that stochasticity). Its gradient
has a pleasant surprise: differentiating through the entropy contributes a constant
−1 inside the parentheses, which the baseline property lets you drop — so the
entire modification is subtracting logπ from the reward, nothing more.
Substituting logπ=Q−V and crunching further, the entropy-regularized
policy gradient comes out looking almost exactly like the soft Q-learning update —
differing only in an extra −∇V term on one side and a soft max on the other
— a striking structural connection between the two families.
The practical culmination is soft actor-critic: an off-policy actor-critic
where the critic update is the ordinary policy Q-function backup with a
−logπ entropy term added to the target, and the actor update maximizes
E[Q^ϕπ(s,a)]+H(πθ). In variational
language, the critic step is message passing in the variational family and the
actor step fits q to the posterior; in practice it’s a simple, very effective
algorithm — “one of the most widely used off-policy continuous control algorithms
today.”
What soft optimality buys you
Levine closes with evidence that this is more than a modeling nicety. An ant robot
facing two passages to a goal: a conventional algorithm commits early to whichever
passage its Q-function happens to rank higher, and can commit wrong; a policy
proportional to exp(Q) keeps probability mass on both peaks until one is clearly
better (Haarnoja et al., soft Q-learning with deep energy-based policies).
Pre-trained with the underspecified reward “run fast in any direction,” a soft-Q ant
runs in every direction — entropy demands it — and then fine-tunes into a specific
corridor far faster than DDPG, which must first unlearn its one committed direction.
Soft actor-critic trained a real robot arm to stack Lego blocks robustly under
physical perturbation, and taught the Minitaur quadruped a real-world walking gait
that generalized to slopes and stairs it never trained on.
The suggested readings trace the lineage: Todorov’s linearly solvable MDPs and
human motor control work, Kappen’s “optimal control as graphical model inference,”
Ziebart’s maximum-entropy inverse RL, the soft Q-learning and soft actor-critic
papers, and Levine’s 2018 tutorial “Reinforcement Learning and Control as
Probabilistic Inference.”
Check yourself
Derivation-style exercises in the lecture’s spirit — work them on paper.
Problem 19.1trajectory posterior
Starting from the graphical model with
p(Ot∣st,at)=exp(r(st,at)), derive
p(τ∣O1:T)∝p(τ)exp(∑tr(st,at)). Then
specialize to deterministic dynamics: for two feasible trajectories τ1,τ2
with total rewards R1>R2, what is the ratio of their posterior probabilities,
and what does this predict about the monkey choosing among equal-reward routes?
Show solution
By the definition of conditional probability,
p(τ∣O1:T)=p(τ,O1:T)/p(O1:T).
The numerator factorizes over the model’s CPDs:
p(τ)∏tp(Ot∣st,at)=p(τ)∏texp(r(st,at)),
and a product of exponentials is the exponential of the sum, giving
p(τ)exp(∑tr); the denominator is a constant in τ, hence the
proportionality. With deterministic dynamics p(τ) is an indicator of physical
consistency, so for two feasible trajectories the ratio is
p(τ1∣⋅)/p(τ2∣⋅)=exp(R1−R2) — probability decays
exponentially in the reward gap. If R1=R2 the ratio is 1: equal-reward routes
are chosen uniformly at random, which is exactly the observed variety in how the
monkey reaches the target while still (almost) never missing it, since missing costs
a large reward gap.
Problem 19.2softmax backup
Define Vt(st)=logβt(st) and Qt(st,at)=logβt(st,at).
(a) Derive Vt(st)=log∫exp(Qt(st,at))dat from the message
recursion with a uniform action prior. (b) For discrete actions with values
Q=(10,9,2), compute the soft max and compare it to the hard max; repeat for
10×Q. What does this say about the effect of reward magnitude?
Show solution
(a) The state message is
βt(st)=Eat∼p(at∣st)[βt(st,at)]; with a
uniform prior this is a constant times ∫βt(st,at)dat. Taking logs
and dropping the additive constant (it shifts all values equally and cancels in the
policy exp(Q−V)),
Vt=log∫exp(Qt)dat. (b)
log(e10+e9+e2)=10+log(1+e−1+e−8)≈10.31, versus a
hard max of 10 — the soft max exceeds the max slightly, dominated by the largest
term. For (100,90,20):
100+log(1+e−10+e−80)≈100.00005, essentially the hard max.
Scaling rewards up (equivalently, lowering the temperature) makes the soft max
converge to the hard max, which is why soft optimality “reduces to classical hard
optimality as the reward magnitude increases.”
Problem 19.3optimism bias
An action leads to a jackpot state with Vt+1=10 with probability 0.001 and
to a state with Vt+1=0 otherwise. Compare the exact-inference backup
logE[exp(Vt+1)] with the standard backup E[Vt+1].
Which inference question does the first answer, and how does the variational
formulation change the backup?
Show solution
Standard: E[Vt+1]=0.001×10=0.01 — nearly worthless.
Exact inference:
log(0.001e10+0.999e0)=log(22.03+0.999)≈log(23.03)≈3.14
— hundreds of times larger, dominated entirely by the rare lucky outcome. The
log-exp backup answers “given that you obtained high reward, what happened?” —
and conditioned on success, the posterior transition probability of the jackpot
state is inflated: the model changes the dynamics to agree with the evidence, which
real dynamics are not allowed to do. The variational formulation fixes the dynamics
inside q to the true p(st+1∣st,at), and the resulting dynamic
program replaces the backup with the ordinary
Qt=r+E[Vt+1], scoring the action at its honest 0.01 while
keeping the soft max over actions (which is the part we actually wanted).
Problem 19.4ELBO cancellation
Write out logp(O1:T)≥Ez∼q[logp(x,z)−logq(z)]
for x=O1:T, z=(s1:T,a1:T), and
q=p(s1)∏tp(st+1∣st,at)q(at∣st). Show exactly which
terms cancel and why the specific choice of variational family is what makes the
bound collapse to reward plus entropy.
Show solution
logp(x,z)=logp(s1)+∑tlogp(st+1∣st,at)+∑tlogp(Ot∣st,at)
and
logq(z)=logp(s1)+∑tlogp(st+1∣st,at)+∑tlogq(at∣st).
Because q was defined with the same initial-state distribution and the same
transitions as p, the logp(s1) terms and every transition term appear
identically in both and cancel in the difference. What remains is
Eq[∑tlogp(Ot∣st,at)−logq(at∣st)],
and substituting logp(Ot∣st,at)=r(st,at) and using
linearity gives
∑tE(st,at)∼q[r(st,at)+H(q(at∣st))].
Had we let the variational family learn its own dynamics, the transition terms
would not cancel, the bound would contain dynamics ratios, and — worse — the
optimizer could exploit them, reintroducing exactly the optimism the constraint was
built to remove. Fixing the dynamics is simultaneously what simplifies the algebra
and what makes the answer the true expected reward under real transitions.
Problem 19.5action prior folding
Levine claims a non-uniform action prior p(at∣st) can be absorbed into the
reward, so assuming a uniform prior loses no generality. Prove it: show that
running the backward pass with prior p(at∣st) and reward r gives the
same value function as running it with a uniform prior and reward
r~(st,at)=r(st,at)+logp(at∣st).
Show solution
With a non-uniform prior, the state message is
βt(st)=∫p(at∣st)βt(st,at)dat, so in log space
Vt(st)=log∫exp(Qt(st,at)+logp(at∣st))dat
where Qt=r+logE[exp(Vt+1)]. Define
Q~t(st,at)=r(st,at)+logp(at∣st)+logE[exp(Vt+1)]
— i.e., the Q you would compute from reward r~=r+logp(at∣st).
Then Qt+logp(at∣st)=Q~t exactly, so
Vt(st)=log∫exp(Q~t)dat: the same log-sum-exp a uniform-prior
backward pass would produce from r~ (up to the constant a uniform prior
contributes, which cancels in the policy). Since the V‘s agree at every step by
backward induction (the base case T is the same identity), the two runs produce
identical value functions and identical policies
π=exp(Q~−V). Hence any prior preference — e.g., a lazy monkey
favoring small actions — is just a reward shaping term, and the uniform-prior
assumption is fully general.