Reinforcement Learning1999advanced12 min read
Policy Gradient Methods for Reinforcement Learning with Function Approximation
طرق مُتَّجَه ميل السياسة في التعلُّم المعزَّز مع تقريب الدوال
Sutton, R. S. · McAllester, D. · Singh, S. · Mansour, Y. — NeurIPS
The problem
By the late 1990s, relied on approximating a and deriving a greedily from it. But this approach had a fatal flaw with : a tiny change in estimated values could flip which action is selected, creating discontinuous jumps. Algorithms like and with function approximation had been proven to diverge on simple problems. There was no guarantee for policy improvement when using general function approximators.
The contribution
The Theorem: a closed-form expression for the of expected with respect to policy parameters. The key surprise is that the gradient does not require differentiating through the state distribution — only through the policy itself. This enables unbiased gradient estimation from experience, with or without a learned value function. The paper also proves that an architecture with compatible function approximation converges to a locally optimal policy — the first such guarantee.
The impact
The theoretical foundation of all modern policy optimization. Every major RL breakthrough since — A3C, DDPG, TRPO, PPO, AlphaGo's policy network, RLHF for language models — rests on this theorem. It shifted RL from value-only methods to the policy gradient family, enabling continuous action spaces, stochastic policies, and the actor-critic paradigm that dominates today.
Imagine you're a football coach. The value-function approach is like giving every player a scorecard for every possible move, then telling them: "always pick the highest-scoring move." Problem: if one score changes by 0.01, the player might suddenly switch to a completely different play — chaos.
The policy gradient approach is different. You watch the game, note which tendencies led to goals, and nudge the playbook directly: "pass left a bit more often, dribble right a bit less." Small nudges produce small changes in behavior. No scorecard discontinuity, no chaos — just steady improvement toward winning.
The problem: value functions break under approximation
Before this paper, the dominant paradigm in reinforcement learning was simple: estimate a value function — how good is action in state — then act greedily, always picking the action with the highest estimated value. This works perfectly with lookup tables where each state-action pair has its own entry. But real problems have enormous or continuous state spaces, so you need function approximation — a , a linear model, or any parametric function that generalizes across states.
The moment you introduce function approximation, the greedy approach develops a dangerous discontinuity. The policy is : a tiny change in parameters can shift which action has the highest value, causing the policy to jump discontinuously. These jumps cascade — a different policy visits different states, changing the distribution, which changes the value estimates, which causes more jumps. Q-learning, SARSA, and dynamic programming methods had all been proven to diverge with simple function approximators on simple problems.
The idea: differentiate the policy, not the value
Instead of building a value function and extracting a policy from it, parameterize the policy directly. Let be the probability of taking action in state given parameters . The policy might be a neural network, a over linear features, or any differentiable function that outputs action probabilities.
Define a performance measure — the expected long-term reward under policy . The idea is breathtakingly simple: compute and update parameters in that direction. Small changes in produce small changes in action probabilities, which produce small changes in the state distribution — no discontinuities anywhere.
The question is: can you actually compute this gradient? The performance depends on the policy, which determines which states are visited, which affects the reward. Differentiating through the entire state distribution seems intractable. This is where the Policy Gradient Theorem delivers its surprise.
The Policy Gradient Theorem
The theorem says something remarkable: to compute the gradient of performance, you do not need to differentiate through the state distribution . The gradient can be expressed purely in terms of quantities you can sample from experience. Before seeing the formula, let's set up the pieces.
Consider an interacting with a . At each time step, the agent is in state , takes action according to policy , receives reward , and transitions to the next state. The measures how good it is to take action in state and then follow forever after. The state distribution tells us how often the agent visits each state under policy .
Read that formula in plain words: visit states by following your policy, and for each state, ask "how much does adjusting increase the probability of good actions?" The answer — summed over all states and actions, weighted by how often you visit each state and how good each action is — gives you the exact direction to improve.
The magic is what's missing. Changing changes the policy, which changes which states the agent visits. Naively, you'd need , which involves differentiating through the entire dynamics of the . The theorem shows this term cancels out — the state distribution acts only as a weighting, and you get that weighting for free just by running the policy.
From theorem to algorithm: REINFORCE
The simplest use of the Policy Gradient Theorem is Williams's algorithm. Instead of knowing exactly, use the actual return — the total reward from time onward — as an unbiased sample. This gives the update rule:
The term is called the score function. It points in the direction that increases the probability of the action taken. Multiplying by makes the update larger when the action led to high reward and smaller (or reversed) when it led to low reward. Run a full , compute returns, and update — that's REINFORCE.
The problem? . is a single noisy sample of . One lucky episode might update parameters dramatically in a direction that isn't actually good on average. Learning is slow because the signal-to-noise ratio is low.
Actor-Critic: the best of both worlds
REINFORCE uses full episode returns — a method. This is unbiased but has high variance and requires waiting for the episode to end. What if we could use a learned value function to estimate instead?
This is the actor-critic architecture. The actor is the policy — it decides what to do. The critic is a learned value function — it evaluates how good the actor's choices are. The actor uses the critic's evaluation to compute policy gradients; the critic learns from the actor's experience using temporal-difference methods.
But here's the danger: if the critic's approximation is wrong, the gradient estimate is biased, and the whole thing might converge to the wrong answer. The paper's Theorem 2 resolves this by identifying a compatibility condition — a specific relationship between the critic and the policy parameterization that guarantees the gradient estimate is exact despite the approximation.
The compatibility condition: when approximation is exact
Theorem 2 provides the conditions under which a learned critic can replace the true in the Policy Gradient Theorem without introducing bias. Two conditions must hold:
Condition 1 — Compatible features. The critic's gradient must equal the policy's score function: . This means the critic is linear in the same features that characterize how the policy responds to changes.
Condition 2 — Minimized error. The critic's parameters must minimize the mean squared error weighted by the state-action distribution under . In other words, the critic has been trained to convergence.
When both conditions hold, the approximation error in is orthogonal to the policy gradient direction, so it doesn't corrupt the gradient at all. This is not an "approximately correct" result — it is exact.
Convergence: policy iteration with function approximation works
Theorem 3 ties everything together. It states that if the actor and critic satisfy the compatibility condition, the policy's second derivatives are bounded, and the decreases appropriately, then the sequence of policies converges to a local optimum — .
This was the first proof that with general differentiable function approximation converges at all. Previous value-function methods had been proven to diverge with function approximation. This theorem opened the door to scaling RL with neural networks — exactly what would happen a decade and a half later with .
Inside the proof: where does the state distribution go?
The proof of Theorem 1 reveals why the state distribution disappears from the gradient. The key insight comes from unrolling the value function recursively.
Start from and apply the product rule to . You get two terms: (1) the gradient of the policy times — the direct effect — and (2) the policy times the gradient of — the indirect effect through future states. Expanding using the and unrolling recursively, the indirect terms telescope into a sum over future state visitations. When you sum over the stationary distribution , the future-state terms cancel with the current-state terms (because is stationary), leaving only the direct effect.
In the discounted start-state formulation, the cancellation works differently but achieves the same result: the probability of reaching each future state from in steps, summed over all with discount , defines directly.
The same idea in code
Simplified to show the idea — not the real implementation.
import numpy as np
def softmax(logits):
e = np.exp(logits - logits.max())
return e / e.sum()
def reinforce_with_baseline(env, theta, w, alpha_theta, alpha_w, gamma, episodes):
"""
theta: policy parameters (state_dim x n_actions)
w: baseline parameters (state_dim,) — approximates V(s)
"""
for ep in range(episodes):
states, actions, rewards = [], [], []
s = env.reset()
done = False
# 1. Collect a full episode under current policy
while not done:
logits = s @ theta # linear policy
probs = softmax(logits)
a = np.random.choice(len(probs), p=probs)
s_next, r, done = env.step(a)
states.append(s); actions.append(a); rewards.append(r)
s = s_next
# 2. Compute returns G_t for each timestep
G = 0
returns = []
for r in reversed(rewards):
G = r + gamma * G
returns.insert(0, G)
# 3. Update policy and baseline
for t, (s_t, a_t, G_t) in enumerate(zip(states, actions, returns)):
baseline = s_t @ w # V(s) ≈ s·w
advantage = G_t - baseline # A(s,a) ≈ G_t - V(s)
# Baseline (critic) update: minimize (G_t - V(s))²
w += alpha_w * advantage * s_t
# Policy (actor) update: ∇ln π(a|s) · advantage
probs = softmax(s_t @ theta)
grad_log_pi = s_t[:, None] * (-probs) # ∂ln π / ∂θ
grad_log_pi[:, a_t] += s_t # +1 for chosen action
theta += alpha_theta * (gamma ** t) * advantage * grad_log_piWhy it changed everything
1992
REINFORCE
Williams introduces REINFORCE — the first policy gradient algorithm. Uses full returns as gradient estimates, no value function. High variance made it impractical for most problems.
1999
Policy Gradient Theorem
Sutton et al. prove the Policy Gradient Theorem and the first convergence guarantee for actor-critic with function approximation. The theoretical foundation for everything that follows.
2015
TRPO
Schulman et al. introduce Trust Region Policy Optimization — constraining the policy update size to guarantee monotonic improvement. Built directly on the Policy Gradient Theorem.
2015
DDPG
Lillicrap et al. extend policy gradients to continuous action spaces with deterministic policy gradients. Enabled RL for robotics and continuous control.
2016
A3C
Mnih et al. introduce Asynchronous Advantage Actor-Critic — multiple agents learning in parallel, using the advantage function exactly as Sutton et al. prescribed. Mastered Atari games without experience replay.
2016
AlphaGo
Silver et al. defeat the world Go champion using a policy network trained with policy gradient methods combined with Monte Carlo Tree Search. The policy gradient theorem enabled learning directly from self-play.
2017
PPO
Schulman et al. introduce Proximal Policy Optimization — a simpler, more robust alternative to TRPO that became the default policy gradient algorithm. Used in OpenAI Five, ChatGPT's RLHF, and most modern RL applications.
2020
RLHF for Language Models
Policy gradient methods (via PPO) are used to align language models with human preferences. The Policy Gradient Theorem, applied to the massive action space of text generation, powers the alignment of ChatGPT, Claude, and Gemini.
Every time a language model is fine-tuned with human feedback, every time a robot learns to walk, every time a game agent discovers a new strategy — the Policy Gradient Theorem is running underneath. Sutton et al. did not just solve a convergence problem; they gave reinforcement learning its computational engine.
CitationSutton, McAllester, Singh, Mansour. Policy Gradient Methods for Reinforcement Learning with Function Approximation. NeurIPS, 1999.
Terms in this paper
- Policy Gradientتدرج السياسة التشغيلية
- Actor-Criticبنية الفاعل والناقد
- REINFORCEخوارزمية REINFORCE
- Advantageالميزة
- Function Approximationتقريب الدوال
- Value Functionدالة تقييم العوائد
- Policyالسياسة
- Rewardالمكافأة
- Markov Decision Process (MDP)عملية ماركوف لاتخاذ القرار
- Convergenceالتقارب الحسابي
- Stochastic Gradient Descent (SGD)الانحدار التدريجي العشوائي
- On-Policyخوارزمية التعلم من السياسة الحالية
- Baselineالخط المرجعي
- Trajectoryمسار تتابع الحالات والأفعال
- Discount Factorمُعامل الخصم