Policy Gradient Methods
Every method so far learned values and read a policy off them. Policy gradient methods drop the intermediary: parameterize the policy directly and climb the performance gradient.
╌╌╌╌
Everything up to here has learned a value and read a policy off it. Even the approximate control methods, which never tabulate anything, still estimate and then act -greedily with respect to it. The policy is always a derived quantity.
Policy gradient methods drop the intermediary. They learn a parameterized policy directly, selecting actions without consulting any value estimate. A value function may still be learned and used to help learn the policy weights, but it is no longer required for action selection.1 The learner holds a parameter vector , defines a scalar performance measure, and moves up the gradient of that performance:
where is a stochastic estimate whose expectation approximates . Every method in this lesson is an instance of this gradient ascent on performance; they differ only in how the gradient estimate is constructed.
The one requirement on the parameterization is that be differentiable in — the gradient vector must exist and be finite for every state and action.2 To preserve exploration we also require the policy to stay stochastic: rather than committing hard to one action.
Why parameterize the policy directly
Learning rather than has three advantages.
Stochastic optima are reachable. With -greedy action selection
over values, the policy is always deterministic plus a uniform
random tail — there is no way to express take
Yet the best policy is sometimes genuinely stochastic. In card games with
imperfect information the optimal play mixes two actions with specific
probabilities (bluffing in poker is the canonical case), and under function
approximation, where distinct states can look identical to the approximator, a
stochastic policy can be strictly better than any deterministic one.3
A softmax over action preferences can represent any such mixture; a value-greedy
policy cannot.right with probability .
In Sutton and Barto's short-corridor task the
reward is per step and all three nonterminal states look identical to the
approximator, so the policy must pick a single probability of going right and use
it everywhere. With , an -greedy value method can
only commit to right with probability or to left
with the same probability. Those two extremes reach start-state values worse than
and worse than respectively. A policy that instead selects right with
probability near reaches roughly — a four-fold improvement over the
better -greedy option, obtained purely by holding a genuinely
stochastic policy the value method cannot express.
Continuous action spaces are handled directly. Value-based control must, in the end, compute , which is a search over the action set on every step. When actions are real-valued that maximization is itself an optimization problem. A policy can instead output the parameters of a distribution over actions (a mean and spread), sidestepping the max entirely — the last section builds exactly this.
Smoothness and stronger guarantees. With a continuous parameterization the action probabilities change smoothly as changes. Under -greedy the selected action can flip discontinuously the moment one estimated value nudges past another, however small the change. That continuity is precisely what lets policy-gradient methods approximate true gradient ascent, and it is why they enjoy stronger convergence guarantees than action-value methods.4 Finally, on some problems the policy is simply a simpler function to represent than the value function, so a policy-based method has less to learn.
Softmax in action preferences
For a discrete, not-too-large action space the standard parameterization forms a numerical preference for each state-action pair and passes the preferences through an exponential softmax:
The denominator normalizes the probabilities in each state to sum to one. The preferences can be computed by any differentiable function — a deep network whose weights are (the AlphaGo route), or a plain linear form in features,
with feature vectors built by any of the function-approximation recipes.
That last point is the key contrast with value methods. A softmax over action values would converge to fixed probabilities determined by the true values, never reaching determinism. Preferences have no such anchor: they are free to diverge to push one action's probability toward one, or to settle at whatever interior mixture is optimal.
The eligibility vector in closed form
Every algorithm below reduces to one vector, the eligibility vector. For the linear-softmax parameterization it has an exact, cheap form worth deriving once. Start from the log of the softmax,
and differentiate. The first term contributes ; the log-sum-exp term contributes a probability-weighted average of the preference gradients:
With linear preferences we have , and the eligibility vector collapses to the feature of the taken action minus the expected feature under the current policy:
The interpretation is geometric: raising means pushing toward the taken action's feature and away from the average feature. Actions that already have high probability contribute heavily to the average, so the update naturally discounts them — the same self-correction that the division supplied in the REINFORCE derivation.
A worked increment. Take a two-action state with features
and
, and current parameters
. The preferences are
and , so
and
. The averaged feature is
.
If the agent takes right, the eligibility vector is
; if it takes left it is
. A positive return after
right therefore raises and lowers , widening the gap toward
right — exactly the direction that increases on the next
visit.
The policy gradient theorem
To do gradient ascent we need . In the episodic case, assuming every episode starts in a fixed state , performance is the value of that start state:
where is the true value function for the policy . The difficulty is that performance depends on through two channels: the action probabilities (easy to differentiate, since they are the parameterized policy) and the distribution of states in which those actions are taken (a function of the environment's dynamics, and typically unknown). Nudging changes which states are visited, and we have no model of how.
The policy gradient theorem resolves this. It gives an exact expression for that involves the derivative of the policy but not the derivative of the state distribution:
Read it as a weighted sum: over states in the proportion the policy actually visits them (), and over actions weighted by how good they are (), push each action's probability up in the direction . The unknown does not appear; that is the value of the theorem.
Derivation sketch
The gradient of the state-value function unrolls into the theorem with nothing more than the product rule and the Bellman equation. Leaving the dependence on implicit, start from :
The first term is the direct effect through the action probabilities; the second term expands through the Bellman equation, exposing at the successor states. Substituting that expansion back into itself — unrolling — replaces by the same pattern one step further out, and again, and again. After repeated unrolling the recursion collapses into a sum over all states weighted by the probability of reaching from in any number of steps:
where is the probability of transitioning from to in exactly steps under . Setting and collecting the multi-step reaching probabilities into the on-policy distribution (a normalized count of how often each state is visited per episode) turns the double sum over into , leaving
The reaching-probability sum made concrete
The intermediate identity the proof reaches before normalizing,
is worth running on real numbers, because the — the expected number of
times is visited per episode — is the quantity that later normalizes into
.5 Take the smallest chain that still has two states and a choice at
each: an episodic MDP with a start state , one intermediate state , and
a terminal state, undiscounted (). Each state offers two actions,
up and dn, and every action from lands in while every action from
terminates, so an episode is exactly two steps, . The
rewards are
Parameterize each state with a single preference gap: at state set and , so is logistic and the two policy gradients with respect to are and . Fix the current policy at (so ) and (so ).
Step 1 — action values, working back from the terminal state. At each action ends the episode, so and , giving . At each action pays its immediate reward and then continues from : and , so . That is the performance we are about to differentiate.
Step 2 — reaching probabilities. Every episode visits once and once,
so the multi-step reaching sums collapse to and (and
after normalizing). The chain is short enough that no
infinite series is needed — the sum over
is a single term at each state.
Step 3 — the inner per-state gradient sum. Because affects only the policy at and only the policy at , each state contributes one component of . At , with :
At , with :
Step 4 — assemble. Weighting each by its reaching count gives the two components of the gradient:
Both are positive, and both point in the expected direction: raising
raises , and up is the better action at
( versus ); the same holds at . A gradient-ascent step
nudges both states
toward up, which is optimal here — the greedy policy takes up everywhere for
. Nowhere did the derivative of the state distribution
appear: the are plain visit counts, as the theorem states.
REINFORCE: Monte Carlo policy gradient
The theorem gives an expression proportional to the gradient; a learning algorithm still needs a way to sample something whose expectation equals that expression. The right-hand side is a sum over states weighted by how often visits them, so if we simply follow , the states we encounter arrive in exactly those proportions. The state sum becomes an expectation under the policy:
The inner sum over actions is not yet an expectation under , because its terms are not weighted by . Multiply and divide each term by , then replace the sum over by the single sampled action :
where the last line uses : the sampled return is an unbiased sample of the action value. This is a quantity we can compute on every time step from experience alone, and its expectation is the gradient. Instantiating the gradient-ascent step gives the REINFORCE update:6
The fraction is compactly the gradient of the log-probability, by the identity :
This vector is the eligibility vector — the only place the policy parameterization enters the algorithm. It is the direction in parameter space that most increases the probability of repeating on future visits to .
- 1input: a differentiable policy , step size
- 2arbitrary (e.g. )
- 3for each episode do
- 4generate an episode following :
- 5for do
- 6
- 7
Each increment is the product of a return and the eligibility vector. The vector points where the parameters must move to make more likely; scaling by pushes hardest in the directions that favored high-return actions. Dividing by inside the eligibility vector corrects for the fact that frequently selected actions accrue updates more often — without it, common actions would gain an unearned advantage.
Because is the complete return to the end of the episode, REINFORCE is a Monte Carlo method: every update waits for the episode to finish, and the algorithm is only well defined for episodic tasks. As a stochastic gradient method it has good convergence properties — the expected update points along the true gradient, so it improves for small enough and converges to a local optimum — but like all Monte Carlo methods it can suffer high variance and therefore learn slowly. The factor in the boxed update handles discounting in the general case; with it disappears.
REINFORCE with a baseline
The variance can be reduced without introducing bias. The policy gradient theorem generalizes to include a comparison of each action value against an arbitrary baseline :7
The baseline can be any function — even a random variable — as long as it does not depend on the action . Subtracting it leaves the gradient unchanged, because the extra term integrates to zero:
So the baseline introduces no bias. What it can change is variance. Carrying it through the same derivation gives a baselined REINFORCE update:
The natural choice is an estimate of the state value, , learned by any of the value-approximation methods with its own weight vector . The reason it cuts variance is a matter of scale: in a state where all actions are good, the raw returns are all large, so every update is large and most of the movement cancels noisily. Subtracting recenters the returns so the update responds to whether an action did better or worse than the state's average, not to the absolute level of return. Where actions differ sharply the baseline is high; where they are uniform it is low — a single number could not track that, but a state-dependent baseline can.
- 1input: a differentiable policy , a differentiable
- 2parameters: step sizes ,
- 3arbitrary (e.g. )
- 4for each episode do
- 5generate an episode following :
- 6for do
- 7
- 8
- 9
- 10
Note that the state-value weights are used only as a baseline here — to recenter the return for the state whose estimate is being updated. They are not used to estimate the values of later states. That distinction matters for the next step.
Footnotes
- Sutton & Barto, Reinforcement Learning: An Introduction (2nd ed.), Ch. 13 — introduction: policy gradient methods learn a parameterized policy that selects actions without a value function, updating by stochastic gradient ascent on a scalar performance measure (13.1). ↩
- Sutton & Barto, §13.1 — Policy Approximation and its Advantages: the differentiability requirement on , the softmax-in-action-preferences parameterization (13.2), linear preferences (13.3), and why preferences (unlike a softmax over action values) can approach a deterministic policy. ↩
- Sutton & Barto, §13.1, Example 13.1 (Short corridor with switched actions): a task where states are indistinguishable to the approximator, the optimal policy is stochastic with , and both -greedy extremes are far worse — the case for representing stochastic optima. ↩
- Sutton & Barto, §13.2 — The Policy Gradient Theorem: the theoretical advantage that continuous parameterization changes action probabilities smoothly (unlike the discontinuous -greedy switch), the episodic performance measure (13.4), the theorem (13.5) and its first-principles proof by unrolling the Bellman recursion for . ↩
- Sutton & Barto, §13.2 — proof of the Policy Gradient Theorem (box, p. 325) and the on-policy-distribution box (p. 199): is the expected number of visits to per episode, and is its normalization into the on-policy distribution; the identity is the step before normalizing to . ↩
- Sutton & Barto, §13.3 — REINFORCE: Monte Carlo Policy Gradient: rewriting the theorem as an expectation under (13.6), the sampling step that introduces and the return , the REINFORCE update (13.8), the eligibility vector , and the boxed episodic algorithm with its factor (Williams, 1992). ↩
- Sutton & Barto, §13.4 — REINFORCE with Baseline: the generalized theorem with baseline (13.10), the zero-subtraction argument that leaves the gradient unbiased, the baselined update (13.11), the choice , and the boxed algorithm with separate step sizes and . ↩
╌╌ END ╌╌