5.2.11 · D2Deep & Advanced RL

Visual walkthrough — Soft Actor-Critic (SAC)

1,844 words8 min readBack to topic

Before line one, three words must mean something. Let me build them with pictures, not jargon.


Step 0 — The three words we need (policy, entropy, Q)

WHAT. Three objects live in this story:

  • A policy — read "pi of a given s". It is a recipe for choosing: given a situation (a "state"), it hands you a probability for each possible action . A probability is just a number between and ; all the actions' numbers must add up to (you will do something).
  • The entropy of that recipe — a single number measuring how spread out the choice is. All-eggs-in-one-basket → entropy . Perfectly torn between options → entropy is large.
  • The Q-value — a score saying "how good is action in state , counting all future reward". Bigger = better long-term move.

WHY these three. SAC's whole objective is "pick good actions ( high) and stay unpredictable (entropy high)". You cannot talk about the trade-off until both are pictures.

PICTURE. Below: three bar charts. Left, a policy that dumps all probability on one action (sharp, low entropy). Right, a flat policy (spread, high entropy). The height of each bar is a probability; the bars sum to .

Figure — Soft Actor-Critic (SAC)

Step 1 — Write down what we want to maximize

WHAT. At a single state , we want the policy that scores highest on

Term by term:

  • means "average, weighting each action by how often the policy picks it". So .
  • (Greek "alpha") is the temperature: a positive dial for how much we care about surprise vs. goodness.
  • is the entropy from Step 0.

WHY this exact sum. This is the Maximum Entropy RL idea in miniature: reward-only RL uses just the first term and collapses to one action; adding pays the agent to hedge. We are solving the one-state version of the parent's objective .

PICTURE. Two competing forces on the same policy: the -term is a magnet pulling all probability onto the best action; the entropy term is a spring pushing bars back toward flat. The winner of this tug-of-war is the optimal policy.

Figure — Soft Actor-Critic (SAC)

Step 2 — Add the "must be a probability" constraint

WHAT. We cannot just maximize freely: the bars are probabilities, so they must obey

WHY. Without this rule the entropy magnet would just make every bar enormous (more surprise forever). The constraint that the heights add to is what forces a genuine shape, not just "bigger everything".

PICTURE. Think of the probabilities as water poured across buckets whose total is fixed at litre. You can slosh water between buckets, but never create or destroy it. The optimization = the best way to distribute a fixed litre.

Figure — Soft Actor-Critic (SAC)

Step 3 — The trick for "maximize with a constraint": Lagrange

WHAT. To maximize while keeping , we build one combined quantity, the Lagrangian:

Term by term:

  • The first sum is exactly rewritten (since ).
  • (Greek "lambda") is a new helper number, one price tag attached to the "must sum to " rule.
  • The bracket is zero when the rule holds — so at the valid answer, equals .

WHY this tool and not plain calculus? If we ignored the constraint and just set the derivative of to zero, the answer would drift off the "sums to " surface. Lagrange's method is the standard machine for "optimize on a curved constraint": it lets us do free calculus on , and the term automatically drags the answer back onto the constraint. It answers the question "where is the peak, given we're trapped on the sums-to-one sheet?"

PICTURE. The constraint is a slanted plane (all points that sum to ). is a hill. The best allowed point is where the hill's slope points straight out of the plane — that "straight-out" direction is precisely what measures.

Figure — Soft Actor-Critic (SAC)

Step 4 — Take the derivative and set it to zero

WHAT. We nudge one bar and ask "did change?" At the top, it doesn't — the derivative is zero:

Where each piece came from:

  • — derivative of the term.
  • — derivative of gives (product rule on ; the extra is the "" from ).
  • — derivative of the constraint term.

WHY "set derivative to zero"? The derivative is the slope — how fast climbs as we move probability onto action . If any bar had positive slope we could pour more water there and score higher; if negative, pour less. Equilibrium (the peak) is exactly where every bar has the same, zero, marginal slope. That is the mathematical fingerprint of an optimum.

PICTURE. A ball resting at the bottom of a valley: at rest, tilt the floor any direction and the ball doesn't roll — slope zero. We freeze the policy at that no-roll point.

Figure — Soft Actor-Critic (SAC)

Step 5 — Solve for the policy: an exponential of Q appears

WHAT. Rearrange Step 4 for : Exponentiate both sides (undo the log) and let normalization absorb the constant:

Term by term:

  • — the taller the , the exponentially taller the bar. Dividing by stretches or squashes how sharply differences matter.
  • — the normalizer ("partition function"): the sum of all the un-normalized heights, dividing so the bars total (this is where our constraint from Step 2 gets satisfied).

WHY the exponential and nothing else? Because we set proportional to in Step 5, and the only function whose log is linear in is the exponential. The entropy term is what forced a ; solving the hands us . This exact object is the Boltzmann / softmax policy, and it's identical to the one in Soft Q-Learning.

PICTURE. Feed a bar chart of -values through the machine , then normalize. Watch the tallest balloon and the rest shrink — but never fully vanish (that residual is the surviving exploration).

Figure — Soft Actor-Critic (SAC)

Step 6 — Edge case: (the greedy limit)

WHAT. Shrink the temperature toward zero. Then blows up, and for the single best action dwarfs everything else. The policy becomes a spike on — a deterministic, greedy policy.

WHY it matters. This recovers ordinary reward-only RL — exactly the behaviour of DDPG / TD3. It confirms our formula is consistent: turn surprise off, get the classic greedy answer. It's also why over-small kills exploration.

PICTURE. Same bars, but : one bar reaches the ceiling, all others flatten to the floor.

Figure — Soft Actor-Critic (SAC)

Step 7 — Edge case: (the uniform limit)

WHAT. Grow the temperature large. Then for every action, so for all — every bar equal. The policy becomes uniform: pure, indiscriminate exploration.

WHY it matters. It shows the other end of the dial. Between the Step 6 spike and this flat line lies every useful SAC policy. This continuum is precisely what automatic temperature tuning walks along, nudging to hit a target entropy .

PICTURE. Same bars, : all bars melt to the same height regardless of .

Figure — Soft Actor-Critic (SAC)

The one-picture summary

WHAT. One figure compresses the whole derivation: constraint → Lagrange peak → , with the two limits (greedy) and (uniform) shown as the two ends of one slider.

Figure — Soft Actor-Critic (SAC)
Recall Feynman: the whole walkthrough in plain words

We wanted a way to pick actions that are good but not predictable. "Good" is the -score; "unpredictable" is entropy, the spread of our choice. We wrote one scoreboard adding the two, then remembered our choice-probabilities must add to litre of water. To find the best split of that litre we used Lagrange's trick — attach a price to the "adds to one" rule so we can do plain calculus. Setting the slope to zero everywhere (the ball-at-rest condition) told us of each probability grows straight-line with its -score. Undoing the log turns "straight line" into "exponential", so the best policy is divided by a normalizer. Turn the temperature tiny and it becomes a spike on the single best move (greedy); turn it huge and every move is equally likely (pure exploring). The temperature is literally the slider between certainty and curiosity.

Related tools used here: Bellman Equation (where these -values ultimately come from), the Reparameterization Trick (how real SAC differentiates through samples of this policy), and the stability contrast with PPO.