Ordinary optimal control chooses actions that maximize cumulative reward:
a1:T∗=arga1:Tmaxt=1∑Tr(st,at),
subject to the environment dynamics. This produces a hard distinction between optimal and non-optimal behavior.
But several behaviors may all be good, demonstrations may contain mistakes, and a controller may benefit from remaining stochastic. Control as inference replaces hard optimality with a probabilistic event.
Introduce a binary optimality variable Ot at every time step and define
p(Ot=1∣st,at)∝exp(αr(st,at)),
where α>0 is a temperature. High-reward state-action pairs make optimality more likely, without forcing lower-reward actions to have zero probability.
The action prior has three equivalent interpretations:
a default behavior before conditioning on optimality;
an implicit reward αlogp0(a∣s);
a reference distribution that the learned policy is penalized for leaving.
Forward Messages and Occupancy
Backward messages say whether a state can lead to high future reward. Forward messages say whether it is reachable from the initial distribution while remaining optimal so far.
The state posterior conditioned on optimality over the entire trajectory is
p(st∣O1:T=1)∝ft(st)βt(st).
This is a forward-backward intersection:
reachable from the startft(st)×can lead to high rewardβt(st).
A state may be promising but unreachable, or reachable but unable to lead to a good outcome. The conditioned occupancy emphasizes states satisfying both conditions.
The Optimism Problem
Exact inference conditions every random variable on optimality, including stochastic next states. The posterior transition becomes
Favorable next states receive greater posterior probability. Unless βt+1 is constant,
p(s′∣s,a,Ot:T=1)=p(s′∣s,a).
The same optimism appears in the exact-inference backup:
Qexact(s,a)=r(s,a)+αlogEs′[eV(s′)/α].
By Jensen's inequality,
αlogE[eV/α]≥E[V].
For small α, even a rare favorable outcome can dominate the log-sum-exp.
Suppose an action leads to values 10 and 0 with equal probability and α=1. Ordinary expected value is
E[V]=5,
while exact inference gives
log(21e10+21e0)≈9.31.
This posterior statement is valid:
given a high-reward trajectory, a favorable transition probably occurred.
But this control assumption is invalid:
choosing the action makes the favorable transition more likely.
A controller may change its action distribution. It cannot change the environment dynamics. We therefore need an inference approximation that keeps transitions fixed.
Control as Variational Inference
Choose a variational trajectory distribution parameterized only by a policy:
Entropy is not rewarded independently of return. Low-value actions remain exponentially unlikely. The objective mainly spreads probability among competitive actions, avoids premature collapse, and preserves multiple good solutions.
The transition expectation is ordinary. The action value includes reward and future soft value; the state value also includes the policy's entropy or KL cost.
Exact inference softens and reweights stochastic transitions. Variational maximum-entropy control keeps transitions fixed and softens only action selection.
Soft Policy IterationInitialize a policy π0.Repeat:evaluate Qπk usingQπk(s,a)←r(s,a)+γEs′Ea′∼πk[Qπk(s′,a′)−αlogp0(a′∣s′)πk(a′∣s′)],improve withπk+1(a∣s)∝p0(a∣s)eQπk(s,a)/α.
For small discrete problems, these steps can be exact. For continuous actions, the log-partition integral and exact soft policy are usually intractable. This motivates a learned actor.
The minimum reduces positive critic bias. The negative log-probability is the sampled entropy bonus.
Each critic minimizes
LQ(θi)=ED[(Qθi(s,a)−stopgrad[y])2].
The targets move slowly through Polyak averaging:
θˉi←ρθˉi+(1−ρ)θi,ρ≈1.
Squashed reparameterized actions
The actor predicts a mean and standard deviation. Sample
ϵ∼N(0,I),u=μϕ(s)+σϕ(s)⊙ϵ,
and squash to the action bounds:
a=tanh(u).
This turns stochastic sampling into a differentiable function of parameter-free noise. Gradients can flow from the critic through the action into the actor.
The transformation changes the action density. Since
In practice, we add a small ε or use an algebraically stable expression. Without this correction, the entropy term describes the unsquashed Gaussian rather than the bounded action distribution actually sent to the environment.
Actor loss
Soft policy improvement fits the actor to the exponentiated-Q distribution. The resulting loss is
A fixed α is sensitive to reward scale and action dimension. SAC can learn it to match a target entropy Htgt:
Lα=E[−α(logπϕ(a∣s)+Htgt)].
Parameterize
α=eη,η=logα,
to guarantee positivity. If entropy is below the target, optimization increases α; if it is above the target, α decreases. The actor's log-probability is detached during the temperature update.
Soft Actor-CriticInitialize πϕ,Qθ1,Qθ2, target critics, and replay D.For each environment step:at∼πϕ(⋅∣st),execute at and store the transition,(s,a,r,s′,d)∼D,a′∼πϕ(⋅∣s′),y←r+γ(1−d)[iminQθˉi(s′,a′)−αlogπϕ(a′∣s′)],fit both critics to the detached target y,a∼πϕ(⋅∣s) by reparameterization,ϕ←argϕminE[αlogπϕ(a∣s)−iminQθi(s,a)],optionally update α,Polyak-update the target critics.
Boundaries and Special Cases
Boltzmann exploration is not maximum-entropy RL. An ordinary Q-learning agent may select actions with
πbeh(a∣s)∝eQordinary(s,a)/α
while still training the critic with
y=r+γa′maxQ(s′,a′).
Here softmax is only an exploration rule. In maximum-entropy RL, entropy changes the objective, value function, critic target, and policy-improvement operator:
The prior can represent a previous policy, safe controller, demonstration policy, skill, or reference model. The learned policy deviates only when reward justifies the KL cost.
Ordinary reinforcement learning. As temperature approaches zero,
Temperature interpolates between greedy reward maximization and following the prior.
Practical Diagnosis
Symptom
Likely cause
Useful response
Critic values are too optimistic
Transition inference or critic overestimation
Keep real dynamics fixed and use twin critics
SAC entropy collapses early
Temperature is too small
Tune or learn α and inspect target entropy
SAC remains random despite learning
Entropy pressure dominates reward
Check reward scale and temperature
Actions reach bounds but log-probabilities look normal
Missing tanh Jacobian correction
Compute density after the action transformation
Q-values explode
Target graph, terminal mask, or reward scale is wrong
Detach targets and verify bootstrapping
Temperature moves in the wrong direction
Sign convention is inconsistent
Check entropy against Htgt
Actor improves Q but not environment return
Critic is being exploited
Monitor realized return and use conservative critics
The full derivation can be remembered as
p(Ot=1∣st,at)∝er(st,at)/α⇓p(τ∣O1:T=1)∝p(τ)eR(τ)/α⇓restrict inference to real dynamicsEπ[t∑r(st,at)−αlogp0(at∣st)π(at∣st)]⇓p0 uniformEπ[t∑r(st,at)+αH(π(⋅∣st))].
Control as inference turns rewards into evidence about optimal behavior. Variational control prevents that inference from cheating through favorable dynamics. Soft Actor-Critic then approximates the resulting soft policy iteration with replay, twin critics, and a reparameterized stochastic actor.