Value-based methods learn Q(s,a) and obtain a policy through an argmax. Policy-gradient methods instead represent the policy itself:
πθ(a∣s)=Pr(At=a∣St=s;θ).
We optimize its parameters to maximize expected return:
θ∗∈argθmaxJ(θ).
Direct policy optimization is useful when the action space is continuous, smooth changes in action probabilities matter, or the best policy is genuinely stochastic. It also avoids solving
argamaxQ(s,a)
every time the agent acts.
For discrete actions, a neural policy commonly produces logits zθ(s,a) and applies softmax:
πθ(a∣s)=∑a′exp(zθ(s,a′))exp(zθ(s,a)).
For continuous actions, a common policy is
at∼N(μθ(st),Σθ(st)).
Stochasticity is not merely an exploration trick. It is part of the policy class being optimized.
Suppose the same observation can be produced by two hidden states that require different actions. A deterministic observation policy must choose the same action in both. A stochastic policy can assign probability to both possibilities:
πθ(a∣o).
We can also condition on a recurrent summary of the observation history:
ht=fθ(ht−1,ot,at−1),πθ(at∣ht).
The derivation below does not require the policy input to be a fully observed Markov state. It only requires the sampled action probability to be differentiable with respect to θ.
The Policy Objective
For a finite-horizon trajectory
τ=(s0,a0,r0,…,sH−1,aH−1,rH−1,sH),
define the return
R(τ)=t=0∑H−1rt.
The objective is the expected return under trajectories generated by the current policy:
This resembles weighted maximum likelihood. Ordinary maximum likelihood uses
i,t∑∇θlogπθ(at(i)∣st(i)),
while REINFORCE weights each score by its observed return. Positive weights increase the sampled action's probability; negative weights decrease it.
This statement is statistical, not deterministic. A good action can receive a poor return because of a later mistake, and a bad action can receive a good return because of luck. These errors only cancel in expectation.
Reward-to-go
The full return credits an action at time t for rewards that occurred before it. Those past rewards cannot have been caused by at, so they only add noise.
Define reward-to-go
Gt=t′=t∑H−1rt′.
We can replace the episode return by Gt without changing the expected gradient:
Discounting controls the influence of uncertain distant outcomes and makes infinite-horizon returns finite when γ<1. It also changes the objective by preferring earlier rewards.
REINFORCEInitialize policy parameters θ.Repeat:collect N complete trajectories using πθ,GH−1(i)←rH−1(i),Gt(i)←rt(i)+γGt+1(i)backward through each trajectory,g←N1i∑t∑Gt(i)∇θlogπθ(at(i)∣st(i)),θ←θ+αg.
REINFORCE is on-policy: the trajectories must come from the policy whose gradient we estimate unless we add an explicit distribution correction.
Baselines and Advantages
Even reward-to-go varies greatly between trajectories. We can subtract a state-dependent baseline:
∇θJ=E[t∑∇θlogπθ(at∣st)(Gt−b(st))].
The baseline supplies a reference. An action is reinforced when its return is better than expected from that state and discouraged when it is worse.
Why a baseline does not change the gradient
An action-independent baseline contributes zero in expectation.
The baseline may depend on the state, but not on the sampled action.
A constant baseline such as the batch-average return is valid, but it ignores that typical return varies by state. The canonical choice is a learned value function:
Because the baseline does not change the mean gradient, minimizing variance is equivalent to minimizing
E[∥z∥2(G−b)2∣s].
Differentiate with respect to b:
dbdE[∥z∥2(G−b)2∣s]=−2E[∥z∥2(G−b)∣s].
Setting this to zero gives
E[∥z∥2G∣s]−b∗(s)E[∥z∥2∣s]=0,
which yields the stated result.
If the squared score norm is approximately independent of return, then
b∗(s)≈E[G∣s]=Vπ(s).
This explains why the value function works well in practice.
Advantage normalization is another common heuristic:
At=σA+εAt−μA.
It improves numerical conditioning and reduces sensitivity to reward scale, but it is a batch-level optimization heuristic rather than a state-dependent baseline derived from the score identity.
Policy Distributions
The score function determines how a weighted sample changes the policy. Its form depends on the action distribution.
For a multivariate Gaussian with fixed covariance Σ,
∇θlogπθ(a∣s)=(∇θμθ(s))⊤Σ−1(a−μθ(s)).
A diagonal Gaussian often learns both μ and ℓ=logσ. For one dimension,
∂μ∂logπ=σ2a−μ,
and
∂ℓ∂logπ=σ2(a−μ)2−1.
An unexpectedly distant, positively weighted action can increase the variance; an action close to the mean can decrease it. The policy learns both where to act and how much randomness to retain.
The Surrogate Loss
Automatic-differentiation libraries minimize scalar losses, while the desired update is gradient ascent:
This is a surrogate loss. Its numerical value is not the negative expected return; its gradient is constructed to equal the sampled policy-gradient estimator.
Returns and advantages must be treated as fixed weights during the actor update:
∇θstopgrad(At)=0.
Otherwise gradients can flow through the critic or return computation in ways not justified by the likelihood-ratio derivation.
For variable-length episodes, flatten the valid time steps or use a mask mt(i):
Vanilla Policy-Gradient UpdateRoll out πθ to collect an on-policy batch.Compute discounted reward-to-go Gt backward.ϕ←argϕmint∑(Vϕ(st)−Gt)2.At←stopgrad(Gt−Vϕ(st)).Optionally normalize At within the batch.Lactor←−M1t∑logπθ(at∣st)At.θ←θ−α∇θLactor.
Why Policy Gradients Are Difficult
REINFORCE is mathematically clean, but its estimator is noisy. Variance comes from stochastic actions, stochastic dynamics, long horizons, delayed rewards, and using one sampled future to estimate many possible futures.
On-policy sample cost. The gradient is an expectation under the current policy:
∇θJ(θ)=Eτ∼pθ[⋯].
After a substantial update, trajectories from pθold are no longer distributed according to pθnew. Reusing them naively biases the estimate.
Importance sampling can correct the action-distribution mismatch with
ρt(θ)=πθold(at∣st)πθ(at∣st).
But products or large values of these ratios create severe variance. This motivates algorithms that reuse recent data while explicitly limiting policy change.
Sensitivity to step size. A vanilla update is
θk+1=θk+αkgk.
If αk is too small, learning is slow. If it is too large, the policy can collapse after one batch.
Euclidean parameter distance is not a reliable measure of policy change. A small parameter update may drastically change action probabilities in one part of the state space. Adaptive optimizers and normalized advantages help numerical conditioning, but they do not guarantee a safe change in the represented policy.
The Bridge to Actor-Critic
The Monte Carlo advantage
AtMC=Gt−Vϕ(st)
still depends on one complete sampled future. A critic can bootstrap from the next state:
The critic averages over possible futures rather than using one full sampled return, so variance is usually much lower. An inaccurate critic introduces bias.
The target is detached during critic optimization, just as in value-based reinforcement learning.
Method
Actor weight
Bias
Variance
Full-return REINFORCE
R(τ)
Unbiased
Very high
Reward-to-go REINFORCE
Gt
Unbiased
High
REINFORCE with baseline
Gt−Vϕ(st)
Actor remains unbiased
Lower
One-step actor-critic
rt+γVϕ(st+1)−Vϕ(st)
Biased with an inaccurate critic
Usually much lower
Actor-critic methods deliberately trade some estimator bias for lower variance. Proximal and trust-region methods address the second major weakness by controlling how far the policy moves during each update.
Practical Diagnosis
Symptom
Likely cause
Useful response
Returns vary wildly between batches
High Monte Carlo variance
Use reward-to-go, a value baseline, and larger batches
Learning reinforces obviously bad actions
Noisy long-horizon credit
Improve the baseline or use actor-critic estimates
Policy collapses after one update
Policy step is too large
Lower the learning rate or constrain policy change
Learning stalls with tiny gradients
Reward scale or advantage scale is poor
Normalize advantages and inspect reward scaling
Old batches hurt performance
On-policy distribution mismatch
Discard stale data or use explicit importance corrections
Continuous-action variance explodes
Unstable standard deviation
Parameterize log standard deviation and monitor entropy
Actor changes while critic loss backpropagates
Missing gradient separation
Detach advantages and use separate actor/critic losses
The entire derivation can be remembered as one chain:
The likelihood-ratio identity makes the environment differentiable in expectation, temporal causality removes past rewards, and a state-dependent baseline removes predictable variation. Replacing the remaining Monte Carlo return with a learned critic produces actor-critic methods.