Exercises — Soft Actor-Critic (SAC)
This page is a self-test. Each problem states everything you need, then hides a complete worked solution behind a collapsible callout. Try first, then reveal. Problems climb five levels:
- L1 Recognition — can you spot the right term / formula?
- L2 Application — plug numbers into a single formula.
- L3 Analysis — combine several pieces, reason about why.
- L4 Synthesis — build something new from the parts.
- L5 Mastery — corner cases, limits, and traps.
Everything here builds on Soft Actor-Critic (SAC). If a symbol feels unfamiliar, it is defined the first time it appears below — nothing is assumed.
Prerequisite ideas you will lean on: Maximum Entropy RL, Entropy (Information Theory), Bellman Equation, Reparameterization Trick, TD3, DDPG, Soft Q-Learning, PPO. Hinglish version of the parent: 5.2.11 Soft Actor-Critic (SAC) (Hinglish).
Level 1 — Recognition
Problem 1.1
SAC maximizes a sum of two things at every timestep. Name both, and write the one-line objective .
Recall Solution 1.1
SAC maximizes expected reward plus policy entropy. Entropy measures how spread out (unpredictable) the action distribution is. The objective is Here just means "states and actions visited when you follow policy ", and is the temperature knob.
Problem 1.2
Which of these is SAC's soft state value ? (a) (b) (c) .
Recall Solution 1.2
Answer: (b). The extra term is the entropy contribution, because . Option (a) forgets exploration; option (c) is the hard (deterministic) value used by DDPG/TD3, not the soft one.
Problem 1.3
In the critic target, SAC uses . What single problem does the combat, and which earlier algorithm introduced this trick?
Recall Solution 1.3
It combats overestimation bias — a single Q-network tends to over-report values because bootstrapping through a -like operator systematically picks up noisy positive errors. The clipped double-Q trick comes from TD3.
Level 2 — Application
Problem 2.1
Compute the soft target given , , , , , .
Recall Solution 2.1
Step 1 — pick the pessimistic Q. . Step 2 — entropy bonus. . Positive because a more random policy earns more future value. Step 3 — soft next value. . Step 4 — Bellman backup. .
Problem 2.2
Two discrete actions have . Using the Boltzmann policy , compute for .
Recall Solution 2.2
Weights: , . Sum . A strong-but-not-total preference for the higher-Q action — exactly the "hedge" behaviour entropy buys us.
Problem 2.3
For a policy over actions with probabilities , compute the entropy (natural log).
Recall Solution 2.3
. . nats. For comparison, a uniform two-action policy has , the maximum. Our policy is more decided, so its entropy is lower.
Level 3 — Analysis
Problem 3.1
Take the same . Compute the Boltzmann policy at and at . Confirm the two limiting behaviours predicted in the parent note.
Recall Solution 3.1
: exponents , . Weights , . Sum . Near-greedy: small ⇒ the exponent gap explodes ⇒ deterministic. : exponents , . Weights , . Sum . Near-uniform: large flattens the difference ⇒ heavy exploration. Both limits match the " is the exploration knob" claim.
Problem 3.2
Recompute Problem 2.1's target if you (wrongly) used the max of the two Q's instead of the min. By how much does the target change, and why is this the dangerous direction?
Recall Solution 3.2
With : , and . Change: — the target is inflated. Why dangerous: Q-networks are regressed toward these targets. If targets are systematically too high, the critic learns inflated values, the actor chases those illusory rewards, and the error compounds through bootstrapping. The deliberately biases downward to cancel the upward noise — a controlled pessimism.
Problem 3.3
The tanh squashing correction is , where is the pre-squash Gaussian sample and . Suppose one action dimension has pre-squash and Gaussian log-density . Compute the corrected and explain the sign of the correction.
Recall Solution 3.3
, so , and . The term inside the subtraction is . So we subtract a negative number: Sign meaning: since , we always have . Subtracting a non-positive quantity adds to , making it less negative — the transformed log-density is higher than the raw Gaussian log-density. Why? The squash compresses a wide range of into the narrow interval ; probability mass gets concentrated, so density rises. Look at the figure: near the tanh is nearly linear so the correction is small; near the flat tails the squash crushes a wide -range into a tiny -range, concentrating density most.

Level 4 — Synthesis
Problem 4.1
Derive the optimal soft policy for a discrete two-action state where , , by maximizing over . Then plug in and confirm you recover Problem 2.2.
Recall Solution 4.1
Objective as a function of : (The bracket is , so subtracting times it adds .) Differentiate and set to zero: Solve: , giving which is exactly the Boltzmann policy . ✔ Plug in : — matches Problem 2.2.
Problem 4.2
Recall from the symbols box that is the target entropy — a fixed number you pick to say "keep the policy at least this random." Automatic temperature tuning descends , whose gradient is . If the current policy entropy is nats and the target is nats, does gradient descent push up or down? Interpret.
Recall Solution 4.2
Note . So Plug in: . Gradient descent updates , so increases. Interpretation: current entropy () is below target () → the policy is too decisive → raise to reward exploration more, pushing entropy back up. Self-annealing, exactly as advertised.
Problem 4.3
The actor loss is , where (see the symbols box) are the policy-network parameters and are the critic weights of the two Q-networks. For a single sampled action with , , , , compute the loss contribution and say which way the actor is pushed.
Recall Solution 4.3
. . Loss . Minimizing this loss pushes toward more negative values, i.e. higher (the term) and higher entropy / lower (the term, since making more negative lowers the loss). Both goals — be good and stay surprising — pull in the same optimization.
Level 5 — Mastery
Problem 5.1 (limit case)
Show algebraically that as the discrete soft policy from Problem 4.1 becomes deterministic (all mass on the higher-Q action), assuming . Then state what happens at the degenerate tie .
Recall Solution 5.1
From . Let . As , , so , hence . All mass on → deterministic/greedy. This is ordinary reward-only RL, matching the parent's " ⇒ greedy." Degenerate tie : then , so for every , giving . The policy stays uniform regardless of temperature — entropy correctly refuses to break a genuine tie. Even as this stays (the limit and the tie do not commute: you must fix first).
Problem 5.2 (all-cases numeric)
For tabulate the Boltzmann policy (probability of the better action) and entropy at . Confirm increases monotonically toward as grows.
Recall Solution 5.2
Using and :
| (nats) | ||
|---|---|---|
| 0.2 | 0.99995 | 0.00058 |
| 1 | 0.88080 | 0.36537 |
| 5 | 0.59869 | 0.67230 |
| 100 | 0.50500 | 0.69310 |
As grows, and (the maximum for two actions). Monotone increase confirmed. See the curve:

Problem 5.3 (synthesis + trap)
A student claims: "Since SAC is off-policy like DDPG, I can drop the entropy term once training stabilizes and get identical behaviour to TD3, only faster." Give two concrete reasons this breaks SAC, using the machinery above.
Recall Solution 5.3
The student's claim, restated: once the Q-values look stable, set (kill the entropy bonus everywhere) and treat SAC as "TD3 with a stochastic head" — expecting the same policy but with faster convergence from off-policy replay.
Reason 1 — the target is defined with entropy. The critic regresses toward . Drop the term and you change the fixed point of the Bellman operator; the learned no longer equals soft-Q, so the actor (which minimizes KL to ) is now chasing an inconsistent target. This is not "TD3 but faster," it is a mismatched actor–critic pair whose two halves optimize different objectives.
Reason 2 — exploration collapse. As shown in Problem 5.1, without the entropy bonus the optimal policy is deterministic (). That reintroduces exactly the brittleness (TD3/DDPG failure mode) SAC was designed to avoid: one bad Q estimate can lock the policy onto a wrong action with no self-correcting exploration. Auto- (Problem 4.2) exists precisely so you don't have to hand-anneal entropy to zero.
Verdict: the claim is false — entropy is load-bearing for both the critic's target and the actor's continued exploration during training.
Recall One-screen recap of every formula used here
- Objective :::
- Soft value :::
- Soft target :::
- Optimal policy ::: (Boltzmann)
- Temperature gradient :::
- tanh correction ::: (raises since the term is )