TL;DR
Standard reinforcement learning asks an agent to maximise its total reward, the sum of the rewards it collects over time. Maximum entropy RL asks for a little more: maximise the reward and also keep the agent's policy as random as it can be while still doing well. A bonus proportional to the Entropy of the policy (a measure of how spread out its action probabilities are) is added to every step's reward. The result is a set of Bellman equations with a soft maximum in place of the hard one, and policies that keep trying several good options instead of collapsing onto one.
Where you'll see it: in the Soft Actor-Critic family of robot-control algorithms, where the policy must stay broad enough to recover from surprises, and in the derivation of soft Q-learning.
Intuition
Start from a choice you already make
You are choosing a lunch spot. Your favourite place is good, but the second-best place is nearly as good and you have not tried it lately. A strictly greedy chooser always goes to the favourite. A chooser who values variety picks the favourite most of the time and sometimes the other place. The second chooser is not being irrational. They have found more information and a backup plan, and they will still eat well on average.
Maximum entropy RL builds this preference into the objective. The agent is paid for reward and paid a little for not being sure what it will do next.
Why the idea exists
A greedy policy has two problems. First, it explores too little. If the agent always takes the action its current estimates favour, it never learns that an unvisited action might be better. Second, it is brittle. A policy that has collapsed onto one action has no alternative when the world changes slightly, such as a robot finding its path blocked.
Adding an entropy bonus addresses both at once. The policy stays spread over the good actions, so it keeps sampling them, and the learned behaviour degrades gracefully when conditions shift. A coefficient sets the price of randomness: a large favours variety, a small recovers ordinary greedy reward maximisation.
- reward + entropy bonus
The math
The objective
Let be the reward at step and let be the policy, the distribution over actions in state . The maximum entropy objective is
where is the Entropy of the action distribution in state , and is the temperature that sets how much the bonus counts. Here is the natural logarithm (see Logarithm), so entropy is measured in nats. The expectation is over trajectories generated by in the environment, which is a Markov decision process. Setting gives back the ordinary objective.
The soft value function
In ordinary RL the value of a state is the maximum over actions of the action value, . The soft version replaces the maximum with a smooth, log-sum-exp form:
Here is the action value, the expected return from taking in . The exponential means high-value actions dominate the sum, but every action contributes something. As shrinks towards 0, the expression approaches the hard maximum.
The optimal policy is a softmax
The best policy under the objective picks each action with probability proportional to the exponential of its value:
This is the Softmax of the action values with temperature . Every action has positive probability, and the probabilities sum to 1 because is exactly the normaliser. Large flattens the distribution; small sharpens it onto the best action.
The soft Bellman equation
Taking one step and then following the soft value gives the soft Bellman equation, with the discount factor from the Bellman equation:
The only change from the ordinary Bellman equation is that has become . Iterating this update is soft value iteration, and it converges to and that satisfy the two equations above.
Worked examples
A single state with two actions. Action 1 gives reward 1, action 2 gives reward 0, and the temperature is . Let be the probability of action 1.
- Objective for one step: .
- Soft policy from the formula: .
- Check by setting the derivative to zero: , so , which gives . The same answer from two routes.
- Value of the objective at this : .
- Soft value: .
Interpretation: the best policy plays action 1 about 73 percent of the time, not 100 percent. The agent gives up a little reward to keep action 2 alive, and the objective value equals the soft value of the state.
One state with , , , and .
- Exponentials: , , . Their sum is .
- Soft value: .
- Policy: , , .
- Check: .
- Compare with the hard maximum: , so the soft value is 0.4076 higher than the best single action value.
Interpretation: the soft value is above the best action value because it counts the entropy of mixing the choices. The policy puts most weight on action 1, but action 2 gets 24 percent and action 3 gets 9 percent. Setting to 0.1 would shrink the weights on the worse actions to about for action 2 and for action 3, so the hard maximum is recovered in the limit.
A robot joint is controlled by a torque , and the policy outputs a Gaussian over torques. For a continuous action the sum in the entropy becomes an integral, called differential entropy, and for a Gaussian it equals
Take and compare two policies with the same mean torque.
- Broad policy, : nats. Bonus: .
- Narrow policy, : nats. Bonus: .
- Difference in bonus: in favour of the broad policy.
Interpretation: differential entropy can be negative, and that is fine, because only differences matter for the objective. The narrow policy is penalised heavily. Unless the narrow policy earns at least 0.46 more reward per step, the entropy term keeps the controller broad. This is the mechanism behind Soft Actor-Critic (an off-policy method, meaning it can learn from older experience stored in a replay buffer), which also tunes during training so that the entropy stays near a chosen target.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| too large | The policy is nearly uniform and learns slowly, because it rarely exploits what it has learned | Decrease , or tune it toward a target entropy |
| too small | The policy collapses early and stops exploring, as in ordinary greedy RL | Increase , or use an entropy schedule |
| The task needs one fixed best answer, with no randomness at test time | A stochastic policy adds noise to the final behaviour | Act with the mode of the policy at evaluation time |
| Rewards are sparse and deterministic | The entropy bonus can dominate the rare reward signal | Scale the reward, or combine with a [[sparse-reward-problem |
| Simple discrete problems with tabular values | The soft machinery adds complexity for little gain | Plain Q-learning, or -greedy exploration |
Choosing is the central practical question. Too much entropy wastes reward, and too little brings back the brittleness the method was meant to fix.
History
The idea of picking the most random distribution consistent with constraints comes from statistical physics and from Edwin Jaynes's principle of maximum entropy. In reinforcement learning, Brian Ziebart and colleagues used the same principle in 2008 for inverse reinforcement learning, to recover a reward function from demonstrations. Emanuel Todorov and Hilbert Kappen had earlier shown that some control problems become linear when the cost of deviating from a default policy is measured with a relative entropy. Haarnoja and colleagues brought the soft Bellman equation to deep RL in 2017 as soft Q-learning, and their 2018 Soft Actor-Critic paper made it a practical, off-policy method for continuous control. It caught on because it was stable across tasks and needed less tuning than many alternatives.
Recap
Maximum entropy RL adds times the policy entropy to each step's reward. The value function becomes a log-sum-exp instead of a maximum, and the optimal policy becomes a Softmax of the action values with temperature . That policy keeps every good action in play, which helps exploration and robustness. The Bellman equation keeps its one-step form, so the usual algorithms carry over. Practical systems such as Soft Actor-Critic build directly on this, and the policy-gradient view of the same objective appears in Policy Gradient.
Check yourself
QuestionWhat does the temperature alpha control in the maximum entropy objective, and what happens as alpha goes to 0?Show answer
Alpha sets the weight of the entropy bonus relative to reward. A large alpha favours randomness and a small alpha favours reward. As alpha goes to 0 the bonus vanishes, the soft value approaches , and the policy approaches the greedy policy of ordinary RL.
QuestionA state has Q values 3, 1 and 1 with alpha = 1. Compute the soft value V(s) to three decimals.Show answer
. The hard maximum is 3, and the soft value is slightly higher because the two lower actions add to the sum.
QuestionIn Example 1, why is the best policy not to play action 1 with probability 1, even though it gives reward 1?Show answer
The objective adds the entropy of the policy. Putting all probability on action 1 gives entropy 0, so the objective would be 1. Putting probability on action 1 gives reward plus entropy , a total of 1.313, which is higher. Some randomness is worth more than the small reward it costs.
QuestionA designer sees a robot policy's standard deviation shrink from 0.5 to 0.05 during training and worries that the policy has become too precise. Using the entropy formula and alpha = 0.2, explain how the objective changes and what the designer should do.Show answer
Differential entropy falls by nats when drops tenfold, so the bonus falls by per step. The objective now favours the narrow policy less, so it must earn at least 0.46 more reward per step to justify the collapse. The designer should check whether reward improved enough to justify it, and if not, raise alpha or set a target entropy that keeps the spread from collapsing.