Maximum entropy formulation

What if we could find a distribution over near-optimal solutions?

Entropy

Entropy = measure of uncertainty over random variable X. Here, X is discrete.

It also describes the ideal average number of bits needed to encode an outcome of X.

ℋ(X)=∑i p(xi) ↑ Probability log21p(xi) ↑ Information (bits) =−∑ip(xi)log2p(xi)

For a fair coin, each result has probability 0.5 and brings log₂(2) = 1 bit, so the entropy is 0.5 × 1 + 0.5 × 1 = 1 bit. If the result is certain, its probability is 1 and log₂(1) = 0, so the entropy is 0.

The base-2 logarithm makes the unit bits. Zero-probability outcomes contribute 0. With efficient coding of long sequences of independent outcomes, entropy is the limit on the minimum average number of bits per outcome.

Examples

Binary random variable

Let p = Pr(X = 1), so Pr(X = 0) = 1 − p.

ℋ(X)=−plog2p−(1−p)log2(1−p)
Binary entropy curve: entropy is zero at probabilities zero and one and reaches one bit at probability one half.

At p = 0 or p = 1, the result is certain and entropy is 0. At p = 0.5, both results are equally likely, so uncertainty is greatest and entropy reaches 1 bit. The curve is symmetric: swapping the two outcomes does not change the entropy.

Five-outcome distributions

Five outcomes with probabilities 0.25, 0.25, 0.25, 0.125, and 0.125.
More balanced: H = 2.25 bits
Five outcomes with probabilities 0.75, 0.0625, 0.0625, 0.0625, and 0.0625.
More concentrated: H ≈ 1.3 bits
p(S)={0.25,0.25,0.25,0.125,0.125}
H=3×0.25×log24+2×0.125×log28=1.5+0.75=2.25bits

Three outcomes have probability 0.25, giving 2 bits each; two have probability 0.125, giving 3 bits each. The factors 3 and 2 count the repeated probabilities.

p(S)={0.75,0.0625,0.0625,0.0625,0.0625}
H=0.75×log2(43)+4×0.0625×log216≈0.3+1=1.3bits

The most likely outcome has probability 0.75, so its information is log₂(4/3). The four rare outcomes each have probability 1/16 and bring 4 bits. The exact entropy is about 1.3113 bits. This distribution is easier to predict because one outcome dominates, so its entropy is lower.

Maximum Entropy MDP

Regular formulation:

maxπE[∑t=0Hrt]

Find the policy π with the highest expected total reward. The sum adds rewards rₜ from time 0 through H, and E averages over the trajectories produced by the policy and the environment. This finite-horizon formula uses undiscounted rewards.

Max-ent formulation:

maxπE[∑t=0H ( rt ↑ Reward + β ↑ Weight ℋ(π(·|st)) ↑ Policy entropy ) ]

At every time step, add an entropy bonus to the reward, then sum both terms over time. This favors policies that earn reward while keeping a more diverse action distribution.

H in the sum is the horizon’s last time index; ℋ is the entropy function. They have different meanings.

Example

Consider a one-step task with two actions, each giving reward 1. Always choosing the first action gives entropy 0, so the max-ent objective is 1. Choosing each action with probability 0.5 gives entropy 1 bit, so the objective is 1 + β. With β > 0, the second policy is preferred. If the actions have different rewards, their reward difference also affects the choice.

Max-ent for 1-step problem

The state is fixed and there is one decision. We choose a probability for each action; there are finitely many actions, their rewards are finite, and β>0.

Here, log=ln, so entropy is measured in nats. Using base-2 logarithms changes the scale of β.

  1. Choose the distribution

    maxπ(a) E[r(a)]+βℋ(π(a))

    The unknowns are the action probabilities. The objective balances expected reward with the entropy of their distribution.

  2. Expand reward and entropy

    maxπ(a) ∑aπ(a)r(a) −β∑aπ(a)logπ(a)

    Expected reward weights each reward by its action probability. Entropy supplies the second sum. Valid probabilities must satisfy:

    π(a)≥0∀a, ∑aπ(a)=1
  3. Enforce normalization

    maxπ(a)minλ ℒ(π(a),λ)= maxπ(a)minλ[ ∑aπ(a)r(a) −β∑aπ(a)logπ(a) +λ(∑aπ(a)−1) ]

    λ is a constraint multiplier. It can be any real number: if the probabilities do not sum to 1, it can make the Lagrangian arbitrarily negative. When they sum to 1, its added term is 0.

  4. Differentiate one probability

    ∂ℒ∂π(a)=0

    With positive β, the optimal probabilities are positive. Set the derivative for each action probability to 0, treating the other probabilities and λ as fixed.

  5. Expand the derivative

    ∂∂π(a) [ ∑aπ(a)r(a) −β∑aπ(a)logπ(a) +λ(∑aπ(a)−1) ]=0

    Vary one component π(a) of the distribution. Only that action’s term in each sum changes.

  6. Apply the product rule

    r(a)−βlogπ(a) −β↑Product rule +λ=0

    The reward term gives r(a). Since d(xlogx)dx=logx+1, the entropy term gives both negative terms. The constraint term gives λ.

  7. Isolate the log probability

    βlogπ(a)=r(a)−β+λ

    Move the log term to the other side; the same λ applies to every action.

  8. Exponentiate

    π(a)=exp[1β(r(a)−β+λ)]

    Divide by β, then apply exp to undo the natural logarithm. The factor C=exp(λ−ββ) is common to every action.

  9. Differentiate the multiplier

    ∂ℒ∂λ=0

    Only the normalization term contains λ, so this derivative recovers the probability constraint.

  10. Make the probabilities sum to 1

    ∑aπ(a)−1=0

    Let Z be the sum of the exponential reward weights. Each weight is multiplied by the same C, so their total probability is CZ. Normalization gives CZ=1⇒C=1Z.

  11. Normalize the exponential weights

    π(a)=1Zexp(1βr(a))

    Divide every positive weight by their common total. The result is a valid action distribution, with higher-reward actions receiving higher probability.

  12. Define the partition function

    Z=∑aexp(1βr(a))

    Z is the total exponential weight across all actions. It is positive and finite under the stated assumptions.

For two actions with rewards 1 and 0, β=1 gives probabilities approximately 0.731 and 0.269. A smaller β favors higher-reward actions more strongly; a larger β makes the probabilities more even.

Max-ent for 1-step problem: value

Use the optimal policy derived above, with β>0 and natural logarithms.

π(a)=1Zexp(1βr(a)),Z=∑aexp(1βr(a))
V=∑a1Zexp(1βr(a))r(a)−β∑a1Zexp(1βr(a))log[1Zexp(1βr(a))]

Substitute the optimal policy into the reward plus entropy objective. V is the maximized value of this full objective.

V=∑a1Zexp(1βr(a))[r(a)−βlog(exp(1βr(a)))]−β∑a1Zexp(1βr(a))log(1Z)

Use log(uv)=log(u)+log(v) to split the logarithm, then combine the reward with the exponential term. log(1Z) is the same for every action.

V=0↑Reward terms cancel−βlog(1Z)∑a1Zexp(1βr(a))↑Probabilities sum to 1

The logarithm reverses the exponential, so r(a)−β1βr(a)=0. Pull the remaining constant factor outside the sum.

V=−βlog(1Z)

The probabilities are normalized: ∑aπ(a)=1. The remaining sum therefore becomes 1.

V=βlog∑aexp(1βr(a))

Use log(1Z)=−log(Z), then replace Z with its defining sum.

The policy probabilities form a softmax distribution. V is a scalar soft maximum: beta times log-sum-exp.

Max-ent Value Iteration

For a finite action set, the one-step solution also works when an action’s score includes the future. Here, β > 0 and log means the natural logarithm.

1. Count the remaining decision steps

Here k counts remaining decision steps; H is the last time index. A sum from time 0 through H contains H + 1 decisions. With no decisions left, the value is 0:

V0(s)=0

Vₖ(s) is the best expected total reward plus entropy bonus over the last k decisions, starting from state s:

Vk(s)= maxπE[ ∑t=H−k+1H (r(st,at)+βℋ(π(·|st))) |sH−k+1=s]

The expectation averages over action choices and environment transitions. ℋ applies to the full action distribution, and its bonus is included at every decision. In the sum, π denotes a sequence of policies, with π(·|sₜ) meaning the distribution used at time t. Each policy can depend on how many steps remain.

Separate the current decision from the remaining k − 1 decisions:

Vk(s)= maxπE[ r(s,a)+βℋ(π(·|s))+ Vk−1(s′)]

Sample a from π(·|s), then sample s′ from P(·|s,a). The three terms are immediate reward, current entropy bonus, and the best future soft value. Starting from V₀, compute this for k = 1, …, H + 1. This formulation is undiscounted.

2. Define the action value

Qk(s,a)= E[r(s,a)↑Reward now+ Vk−1(s′)↑Future soft value|s,a]

Fix the current state and action. Only the next-state transition is averaged here. Qₖ includes the current reward and optimal future rewards and entropy bonuses; it leaves the current entropy bonus outside.

3. Reuse the one-step solution

Vk(s)= maxπE[ Qk(s,a)+βℋ(π(·|s))]

Here max over π chooses the current state’s action distribution; the future is already optimized by Vₖ₋₁. The expectation is only over a ∼ π(·|s). The entropy is the same for every sampled action. Replace the reward score r(s,a) in the one-step derivation with Qₖ(s,a): it already accounts for the optimal soft future.

4. Compute the soft value and policy

Vk(s)=βlog ∑aexp(1βQk(s,a))

Ordinary value iteration uses the largest action value, maxₐ Qₖ(s,a). The entropy bonus replaces that maximum with log-sum-exp, which combines all action scores.

πk(a|s)=1Z exp(1βQk(s,a))
Z=∑aexp(1βQk(s,a)) =exp(Vk(s)β)

Z depends on s and k and makes the action probabilities sum to 1. Instead of an argmax action, πₖ is a softmax distribution: higher Qₖ gets higher probability. Use πₖ when k steps remain; after one action, k decreases by 1. As β approaches 0 from above, the policy concentrates on greedy actions.