Worked examples — Soft Actor-Critic (SAC)
This is a do-the-numbers companion to Soft Actor-Critic (SAC). The parent note tells you what the soft Bellman equations are; here we grind through every kind of input those equations can meet — every sign of the log-probability, the extreme temperatures and , the degenerate deterministic policy, the tanh-squashing trap, and an exam-style twist. If you can reproduce all of these by hand, you understand SAC operationally.
Before we compute anything, five symbols must be earned (the parent used them; we re-anchor them so line one is readable):
The scenario matrix
Every soft-Bellman / policy computation you'll ever be asked lands in one of these cells. The examples that follow are labelled with the cell they cover. The figure just below draws the single relationship that powers half of them: how the bonus climbs as the policy grows unsure.
| Cell | Case class | What's extreme / tricky | Example |
|---|---|---|---|
| A | Ordinary soft target | positive reward, moderate entropy | Ex 1 |
| B | Confident policy | , bonus vanishes | Ex 2 part B |
| C | Very uncertain policy | , bonus dominates | Ex 2 part C |
| D | Twin-Q disagreement | which Q wins the , both orderings | Ex 3 |
| E | Temperature limit | Boltzmann → greedy (deterministic) | Ex 4 |
| F | Temperature limit | Boltzmann → uniform | Ex 4 |
| G | tanh squashing correction | density change of variables | Ex 5 |
| H | Automatic update sign | entropy below/above target | Ex 6 |
| I | Real-world word problem | translate a task into | Ex 7 |
| J | Exam twist | negative reward + terminal state (-cutoff) | Ex 8 |
The red curve below is the entropy bonus as a function of (at ). Read it left-to-right: at the far right (, a certain policy) the bonus is zero; sliding left toward (a very spread policy) the red curve rises. Every "Case B vs Case C" contrast in this page is just two points on this one line.

Example 1 — the ordinary soft target (Cell A)
Forecast: Guess whether is bigger or smaller than , and by roughly how much.
- Take the pessimistic Q: (recall = smaller of the two twin critics). Why this step? Like TD3, the smaller of the twin Qs fights overestimation bias (the in a single Q over-reports).
- Entropy bonus: . Why this step? This is the piece of the soft value (parent Step 1). It is positive because .
- Soft next-state value: . Why this step? ; here we use the sampled .
- Discount and add reward: . Why this step? Soft Bellman Equation backup: immediate reward plus discounted soft future.
Verify: , exactly as forecast — the entropy bonus pushed the future value above the raw -Q, then discounting by shrank it slightly, and reward pulled it back up. Sanity: dropping the bonus gives , and ✓.
Example 2 — how confident vs uncertain policies change the bonus (Cells B & C)
Forecast: In which case is larger? Why should "less sure" mean "more valuable"?
- Part B (Cell B) bonus: . Why this step? means near-zero entropy, so almost no exploration reward.
- Part B (Cell B) target: .
- Part C (Cell C) bonus: . Why this step? A very spread policy has high entropy; SAC pays a big bonus for it.
- Part C (Cell C) target: .
Verify: ✓ — the uncertain policy (Cell C) is worth twice as much here purely from the entropy term. This is the self-annealing exploration mechanism: high-entropy states get inflated value, so the critic keeps them attractive until Q evidence overwhelms the bonus. Both and are just two heights on the red curve of the scenario-matrix figure.
Example 3 — twin-Q disagreement, both orderings (Cell D)
Forecast: Does swapping which network is bigger change ?
- Bonus (shared): .
- Case (i): . Why this step? ignores the optimistic ; it always trusts the stricter judge.
- Case (ii): identical .
Verify: Both orderings give the same ✓. The is symmetric — only the value of the smaller Q matters, never its index . This is the point of clipped double-Q: the optimistic estimate () is discarded no matter which head produced it.
Example 4 — the two temperature limits (Cells E & F)
Forecast: Sketch the bar chart of for each before computing. Which becomes a single spike? Which becomes flat?
- : weights , sum . . Why this step? Moderate temperature → clear preference but real probability mass on all actions.
- : exponents → the term dominates by factors of and . — essentially . Why this step? Small = greedy: this is exactly reward-only RL / DDPG behaviour (Cell E limit).
- : exponents → , sum . . Why this step? Large = uniform, maximal exploration (Cell F limit).
Verify: Each row sums to (the normalizer guarantees this). collapses to a one-hot vector; is nearly flat ✓. This reproduces the parent's claim: ⇒ greedy, ⇒ uniform. Compare with Soft Q-Learning, where this same Boltzmann form is the policy itself.
The figure below draws all three probability vectors as bar groups; the red bars are the greedy case — notice the single red spike on action while the faded moderate/uniform cases spread mass across all three actions.

Example 5 — the tanh squashing correction (Cell G)
Forecast: Will the correction make larger (closer to ) or smaller (more negative) than the raw Gaussian value?
- Raw Gaussian log-density at : . Why this step? This is the density of the pre-squash variable, using the Reparameterization Trick sample.
- Squash Jacobian term: the change of variables is . With , , so and . Why this step? compresses the real line into ; a change of variables multiplies the density by . In log-space that adds , a positive number.
- Corrected log-prob: . Why this step? Forgetting the term (the parent's [!mistake]) would report and corrupt entropy and -tuning.
Verify: The correction added , so the corrected is larger (closer to ) than the raw ✓. That is the expected direction: since always, the correction can only raise toward — never below the raw Gaussian value. (Intuition check: near the flat edges of , a wide band of maps to a narrow band of , concentrating probability, which raises the density there.)
Example 6 — the automatic- update sign (Cell H)
Forecast: Current entropy is ; the target entropy magnitude is . We are below target — intuitively, should grow (explore more) or shrink?
- Write the gradient of the loss w.r.t. . appears linearly in , so using and . Why this step? This single, clean expression is the entire sign story: it compares current entropy to the target magnitude, nothing else.
- Apply gradient descent: . Why this step? We minimize , so we step against the gradient. Read the sign of to get the direction of .
- Under-explored case (): , so — increases. Why this step? Entropy is below target, so raise the exploration knob. Matches intuition ✓.
- Over-explored case (): , so — decreases. Why this step? Too much entropy, so shrink the knob. Also matches intuition ✓.
Verify: The fixed point is : stops moving exactly when measured entropy equals the target. Under-explored () raises ; over-explored () lowers it ✓. So gradient descent on automatically self-anneals exploration — the sign works out to the intuitive direction in both cases.
Recall Clean rule to memorize
Sign rule ::: . Gradient descent then raises when entropy target, lowers it when entropy target. Fixed point: entropy .
Example 7 — real-world word problem (Cell I)
Forecast: The many-good-angles fact should raise through the bonus. Estimate before computing.
- Pessimistic Q: . Why this step? Overestimation control — trust the stricter critic.
- Entropy bonus: . Why this step? "Many equally good arm angles" = high entropy = large bonus, exactly the situation SAC rewards.
- Soft next value: .
- Backup: . Why this step? Reward for touching now, plus discounted flexible future.
Verify: Without the flexibility bonus, would be . The extra credits the robot for having many working strategies ✓ — a concrete instance of the parent's candy-robot intuition.
Example 8 — exam twist: negative reward at a terminal state (Cell J)
Forecast: At a terminal state, what happens to the whole block? Does the entropy bonus survive?
- Terminal mask: the bootstrap term is multiplied by with (done). So . Why this step? There is no future after termination, so both the future Q and the entropy bonus vanish — you cannot be paid for future exploration that never happens.
- Non-terminal contrast (): bonus ; ; . Why this step? Same negative reward, but now the future exists, so the bonus and discounted Q reappear.
Verify: Terminal (pure reward, no bonus) vs non-terminal ✓. The exam trap is forgetting the mask and leaving an entropy bonus on a terminal transition — that would leak fictitious future value into a state that has no future. Note the entropy bonus is inside the block, so it is correctly zeroed by termination.
See also PPO for the on-policy contrast the parent draws, and Reparameterization Trick for how Ex 5's sample lets gradients flow.