Soft Actor-Critic (SAC)
An off-policy actor-critic that stays curious on purpose: it maximizes reward plus randomness, so one policy covers many good motions instead of one brittle trick.
Why Does This Exist?
Deterministic off-policy methods learn fast from old data but collapse onto one narrow motion. The policy goes near-deterministic early, value errors pile up, and the final controller shatters the first time the world wobbles. On-policy methods stay flexible but throw every batch away after one update, so real robots need millions of extra steps.
Soft Actor-Critic takes the third option. It keeps off-policy data reuse and adds a randomness bonus to the objective, so the policy earns reward for succeeding and for staying broad. The framework behind the bonus is maximum entropy RL, the twin-critic trick it borrows is shared with TD3, and the deterministic method it improves on is DDPG.
The one idea you need first
Entropy measures how spread out a policy is. A policy that always picks one action has low entropy; one that spreads probability across many actions has high entropy. SAC adds times that spread to the reward, where is a temperature trading exploration against return. The full treatment of the objective lives in maximum entropy RL.
Think of It Like This
The Chef Who Keeps Five Good Sauces Ready
A rigid chef perfects one sauce for one dish. It scores top marks until the night the cream delivery fails, and then service collapses because no backup exists.
A soft chef keeps five good sauces ready and rotates them. Each one scores slightly below the rigid chef's best on a perfect night, but when the cream fails the kitchen keeps serving. The menu bonus pays for variety, not just tonight's plate.
SAC is the soft chef. Its entropy bonus pays the policy to keep several good motions alive, and the temperature turns that pay up early and down once the task is nearly solved. Where the analogy stops: a chef tastes and remembers, while SAC writes variety as a number, , inside the Bellman target itself.
How It Actually Works
SAC maximizes reward plus entropy:
Three pieces make it run. Twin critics and fight overestimation by backing up the smaller prediction. A squashed Gaussian actor keeps actions inside through with . And the temperature auto-tunes against a target entropy of minus the action dimension.
The soft target
For a next action sampled from the current policy, with the discount:
The term is the price of certainty: confident actions shrink the target, spread-out actions grow it. Both critics regress toward , and the actor climbs the smaller critic minus its own log probability.
The squashing correction
Because squeezes the whole real line into , probability piles up near the edges, and the raw Gaussian density misstates it. The fix subtracts the squeeze factor per action dimension:
Skip that subtraction and entropy readings near the boundaries are wrong, which you will feel next as a misbehaving temperature.
Worked example
One dimension, so target entropy is . Policy outputs mean and spread , sampled noise , temperature , reward , discount .
Sample: , and .
Densities: latent log probability , squeeze factor , so corrected .
Critics read and , so the backup uses . Soft value: . Target: .
Temperature check: sits above the target by , so the policy holds more randomness than asked and steps down.
Code
The worked numbers in plain Python using only the standard library:
import math
mu, sigma, eps = 1.0, 0.5, 0.0u = mu + sigma * epsa = math.tanh(u)log_p = -0.5 * math.log(2 * math.pi * sigma**2)log_pi = log_p - math.log(1 - a**2)soft_value = min(5.0, 4.2) - 0.2 * log_pitarget = 1.0 + 0.99 * soft_value
print(f"a {a:.4f}") # -> a 0.7616print(f"log_pi {log_pi:.4f}") # -> log_pi 0.6417print(f"target {target:.4f}") # -> target 5.0309Watch Out For
Dropping the tanh correction corrupts the temperature
Computing from the raw Gaussian and skipping the subtraction reads fine near zero but lies near the action limits, where squashing piles mass. The symptom is a temperature that dives toward zero for no reason while boundary actions look more random than they are.
Fix it by always applying the change-of-variables term with a small stabilizer inside the log, and by unit-testing one boundary action such as against the hand values above.
Fixing the temperature by hand wastes the method
Hard-coding works in one environment and silently mistunes the next: too high and the policy never commits, too low and it collapses before exploring. The symptom is a sweep over per task that eats the sample savings SAC promised.
Fix it by enabling automatic tuning against target entropy and watching fall as training shifts from exploring to executing.
The Quick Version
- SAC maximizes reward plus an entropy bonus, so the policy stays broad while reusing old off-policy data.
- Twin critics back up the smaller Q prediction, which curbs the overestimation that breaks deterministic methods.
- The actor samples and must correct for the squash factor.
- In the worked step, action 0.7616 with 0.6417 and Q values 5.0 and 4.2 give soft target 5.0309.
- The temperature auto-tunes toward target entropy , falling as the policy commits.