SAC
Topics: Reinforcement Learning
Introduction
Soft Actor-Critic (SAC) is a model-free, actor-critic, off-policy, RL algorithm that trains a stochastic policy following the Entropy Maximization framework in an Entropy-Regularized Reinforcement Learning environment. It is targeted at environments with continuous action spaces.
Objective
Standard RL agents maximize the expected return, whereas the goal of the SAC agent is to maximize both the expected return and the policy entropy. In other words, the agent aims to succeed at the task while acting as randomly as possible.
In a finite horizon setting, the objective function, augmented by the entropy term is as follows (1):
where is the temperature parameter, also known as the entropy regularization coefficient.
In an infinite horizon setting, the objective becomes (1):
where is the discount factor.
Temperature Parameter
The temperature parameter is used to adjust the effect of the entropy term with respect to the environment reward in the return equation. It is a hyperparameter which needs to be carefully tuned, as it can degrade the performance of SAC significantly. It controls the level of exploration vs. exploitation.
If the temperature parameter is too high, then the entropy term will dominate the return and the policy will progress towards a highly stochastic policy, almost uniform. This means that the agent explores most of the time and does not exploit enough. On the other hand, if the temperature parameter is too small, the reward will dominate the return and the policy will progress towards a more deterministic policy. This means that the agent exploits most of the time and does not explore enough, which can lead to convergence to local optima.
There are 2 approaches when it comes to the temperature parameter in SAC (3): one that uses a fixed temperature parameter (1), which needs to be tuned, and another that includes a constrained formulation that automatically tunes the temperature hyperparameter (2). A fixed results in a simpler algorithm but requires tuning, whereas the second approach is more complex and is generally preferred by practitioners (3).
Algorithm Details
The derivation of the algorithm starts from the soft policy iteration algorithm, which is the general form for learning optimal maximum entropy policies that alternates between policy evaluation and policy improvement in the maximum entropy framework. It works for discrete action spaces
In policy evaluation, the soft Q-value is computed iteratively by applying the following Bellman backup operator (1):
where
In the policy improvement step, the policy is updated towards the exponential of the new Q-function, which can guarantee that the new policy is an improvement over the previous one. In more detail, the Kullback-Leibler divergence is used to project the new policy into a constraint set. I NEED TO GO INTO THIS IN MORE DETAIL!
The SAC algorithm is for continuous action spaces, so the above soft policy iteration algorithm is approximated using neural networks. There are 2 main variations of the SAC algorithm: one that uses a value network (1) and one that does not (2). They both start from the same equations above. The first version keeps the value function in the equations whereas the second one replaces the value function with an expression of Q-function, and hence eliminates the need for a value network.
SAC with Value Network
The version of SAC with value network requires the following neural networks:
- value network:
- target value network:
- 2 critic networks: and
- actor network:
The updates of the networks follow directly from the equations of the soft policy iteration algorithm.
The **soft value network is trained to minimize the squared residual error (1):
where is the replay buffer. Also, the minimum Q-value from the 2 critic networks is taken, a technique similar to double Q-learning and TD3.
The target value network can be updated using polyak averaging or periodic hard updates.
The soft Q-function networks can be trained to minimize the soft Bellman residual (1):
with
Finally, the actor network update relies on the reparameterization trick and has the following objective (1):
I NEED TO RESEARCH THE REPARAMETERIZATION TRICK!
Similarly to the value network update, the minimum of the Q-values from the critic networks is used in the actor network update.
SAC without Value Network
This version of SAC requires the following neural networks:
- 2 critic networks: and
- 2 target critic networks: and
- actor network:
The derivation starts from the same soft Q-function loss as above:
then replace the value equation by its definition (2):
The minimum of the target Q-values is used in the equation above.
The actor network is updated similarly to the first method.
Finally, the weights of the critic target networks are updates via polyak averaging or periodic hard updates.
Pseudocode

References
- T. Haarnoja, A. Zhou, P. Abbeel, and S. Levine, “Soft Actor-Critic: Off-Policy Maximum Entropy Deep Reinforcement Learning with a Stochastic Actor,” Aug. 08, 2018, arXiv: arXiv:1801.01290. doi: 10.48550/arXiv.1801.01290.
- T. Haarnoja et al., “Soft Actor-Critic Algorithms and Applications,” Jan. 29, 2019, arXiv: arXiv:1812.05905. doi: 10.48550/arXiv.1812.05905.
- https://spinningup.openai.com/en/latest/algorithms/sac.html
Backlinks
Notes that reference this page.
Connections
Direct relationships to this note.