Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 71

Soft Actor-Critic

Maximize both return and action entropy, so a continuous policy keeps several good actions alive. One example is on this page.

Intermediate12 min
Soft Actor-Critic MahiDev

What You Will Learn

  • Idea
  • Example
  • When to use it

Idea

Soft Actor-Critic adds an entropy bonus to the critic target. The agent is paid for return and for staying uncertain when several actions are fine. A temperature, alpha, sets how much that randomness is worth. Two critics still contribute the minimum Q, as in TD3.

Example

python
import math

log_pi = math.log(0.8)
q1, q2, alpha, gamma, reward = 1.2, 1.0, 0.2, 0.9, 0.0
soft = reward + gamma * (min(q1, q2) - alpha * log_pi)
print(f"sac target: {soft:.3f}")

Output:

text
sac target: 0.940

When to use it

  • Use it for continuous control when a brittle deterministic policy is a problem.
  • The entropy term - alpha * log pi raises the target when the action was not a certainty.
  • Alpha can be fixed or learned. Higher alpha explores more.

Loading playground…