This is a fundamental and very important identity in reinforcement learning, particularly for policy gradient methods.
Let's break down why it's true and why it's so significant.
The Statement
Let π(a∣s;θ) be a stochastic policy parameterized by θ. The policy gives the probability of taking action a in state s. The expression is:
Ea∼π(⋅∣s)[∇θlogπ(a∣s;θ)]=0
This states that the expectation of the score function (the gradient of the log-policy) is the zero vector. The expectation is taken over actions sampled from the policy π itself for a given state s.
The Proof
The proof relies on a common calculus identity known as the log-derivative trick: ∇logf(x)=f(x)∇f(x).
Let's prove it for both discrete and continuous action spaces.
1. Discrete Action Space
If the set of actions A is discrete, the expectation is a sum:
Ea∼π[∇θ
Now, apply the log-derivative trick:
=∑a∈Aπ(a∣s;θ)
The π(a∣s;θ) terms cancel out:
=∑a∈A∇θπ(a∣s;θ)
Since the gradient operator is linear, we can pull it outside the summation:
=∇θ∑a∈Aπ(a∣s;θ)
By the definition of a probability distribution, the sum of probabilities over all possible actions must be 1:
=∇θ(1)
The gradient of a constant (1) is the zero vector:
=0
2. Continuous Action Space
The logic is identical, but we use an integral instead of a sum:
Ea∼π[∇
Apply the log-derivative trick:
=∫a∈Aπ(a∣s;θ)
Cancel the terms:
=∫a∈A∇θπ(a∣s;θ
Move the gradient outside the integral (this is allowed by the Leibniz integral rule under mild conditions that are met here):
=∇θ∫a∈Aπ(a∣s;θ
The integral of a probability density function over its entire domain is 1:
=∇θ(1)
=0
Intuition and Significance
This identity is not just a mathematical curiosity; it's the cornerstone of how policy gradient algorithms work.
Intuition: The term ∇θlogπ(a∣s;θ) is a vector that tells you which direction to move the parameters θ to make action . The identity says that if you average these "suggestion vectors" over all possible actions, weighted by their current probabilities, they all cancel out. For every action you make more likely, you must make other actions less likely, and on average, there is no net direction of change.
log
π
(
a
∣
s
;
θ
)]
=
∑a∈Aπ(a∣s;θ)∇θlogπ(a∣s;θ)
(
π(a∣s;θ)∇θπ(a∣s;θ)
)
θ
log
π
(
a
∣
s
;
θ
)]
=
∫a∈Aπ(a∣s;θ)∇θlogπ(a∣s;θ)da
(π(a∣s;θ)∇θπ(a∣s;θ))
d
a
)
d
a
)
d
a
a
more likely
Significance in Policy Gradients (REINFORCE): The goal of policy gradient methods is to maximize the expected return J(θ)=Eτ∼πθ[R(τ)]. The Policy Gradient Theorem shows that the gradient of this objective is:
∇θJ(θ)=E
where Gt is the return from time step t.
The Foundation for Baselines: This is where the identity E[∇logπ]=0 becomes critical. We can introduce a baselineb(s) that depends on the state but not the action, to reduce the variance of the gradient estimate.
Consider the term Ea∼π[b(s)∇θlogπ(a∣s;θ)]. Since b(s) does not depend on a, we can pull it out of the expectation over a:
Ea∼π[b(s)∇
From our identity, we know the expectation is zero. Therefore:
b(s)⋅0=0
This means we can subtract this zero-valued term from our original policy gradient expression without changing its expected value:
∇θJ(θ)=E
This shows that introducing a baseline is mathematically sound and doesn't introduce bias into the gradient. This is a fundamental technique for making policy gradient methods practical.