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 Q(s,a)Q(s, a) — how good is action aa in state ss — 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 arg⁡max⁡aQ(s,a)\arg\max_a Q(s, a): 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.

Open in Lab
Left: the greedy value-function approach — a tiny parameter change flips the selected action. Right: the policy gradient approach — the same change produces a smooth shift in action probabilities.
The demo wakes as you arrive…

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 π(s,a,θ)\pi(s, a, \theta) be the probability of taking action aa in state ss given parameters θ\theta. The policy might be a neural network, a over linear features, or any differentiable function that outputs action probabilities.

Define a performance measure ρ(π)\rho(\pi) — the expected long-term reward under policy π\pi. The idea is breathtakingly simple: compute ∂ρ∂θ\frac{\partial \rho}{\partial \theta} and update parameters in that direction. Small changes in θ\theta 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 ρ\rho 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 dπ(s)d^\pi(s). 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 ss, takes action aa according to policy π(s,a,θ)\pi(s, a, \theta), receives reward rr, and transitions to the next state. The Qπ(s,a)Q^\pi(s, a) measures how good it is to take action aa in state ss and then follow π\pi forever after. The state distribution dπ(s)d^\pi(s) tells us how often the agent visits each state under policy π\pi.

∂ρ∂θ=∑sdπ(s)∑a∂π(s,a)∂θ Qπ(s,a)\frac{\partial \rho}{\partial \theta} = \sum_{s} d^{\pi}(s) \sum_{a} \frac{\partial \pi(s, a)}{\partial \theta}\, Q^{\pi}(s, a)
The Policy Gradient Theorem — This theorem provides a direct way to improve a policy by increasing the probability of actions that lead to higher long-term rewards and decreasing the probability of actions that lead to poorer outcomes. Remarkably, the update can be computed using the states and actions actually experienced by the agent, without explicitly modeling how policy changes would alter the future distribution of visited states. This insight forms the foundation of modern policy-gradient reinforcement learning methods.

Read that formula in plain words: visit states by following your policy, and for each state, ask "how much does adjusting θ\theta 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 θ\theta changes the policy, which changes which states the agent visits. Naively, you'd need ∂dπ(s)∂θ\frac{\partial d^\pi(s)}{\partial \theta}, 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.

Open in Lab
Follow the information flow of the Policy Gradient Theorem: states are sampled by running the policy, the gradient pushes action probabilities toward higher-value actions.
The demo wakes as you arrive…

From theorem to algorithm: REINFORCE

The simplest use of the Policy Gradient Theorem is Williams's algorithm. Instead of knowing Qπ(s,a)Q^\pi(s, a) exactly, use the actual return RtR_t — the total reward from time tt onward — as an unbiased sample. This gives the update rule:

Δθt∝∂ln⁡π(st,at)∂θRt\Delta \theta_t \propto \frac{\partial \ln \pi(s_t, a_t)}{\partial \theta} R_t

The term ∂ln⁡π∂θ\frac{\partial \ln \pi}{\partial \theta} is called the score function. It points in the direction that increases the probability of the action taken. Multiplying by RtR_t 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? . RtR_t is a single noisy sample of QπQ^\pi. 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.

Δθt∝∂ln⁡π(st,at)∂θ(Rt−b(st))\Delta \theta_t \propto \frac{\partial \ln \pi(s_t, a_t)}{\partial \theta} \bigl(R_t - b(s_t)\bigr)
REINFORCE with baseline — Rather than rewarding or penalizing actions based on their raw return, this method compares each outcome against what was expected in that situation. Actions that achieve better-than-expected results become more likely in the future, while actions that perform worse than expected become less likely. This relative comparison greatly reduces the noise in learning signals, making policy optimization faster and more stable without changing the final objective being optimized.
Open in Lab
Compare gradient estimates with and without a baseline. Without: all updates are positive (just different magnitudes). With: updates center around zero, dramatically reducing variance.
The demo wakes as you arrive…

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 QπQ^\pi instead?

This is the actor-critic architecture. The actor is the policy π(s,a,θ)\pi(s, a, \theta) — it decides what to do. The critic is a learned value function fw(s,a)f_w(s, a) — 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.

Open in Lab
The actor-critic loop: the actor selects actions, the environment returns rewards, the critic evaluates, and the actor improves. Click each component to see its role.
The demo wakes as you arrive…

The compatibility condition: when approximation is exact

Theorem 2 provides the conditions under which a learned critic fwf_w can replace the true QπQ^\pi 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: ∂fw(s,a)∂w=∂ln⁡π(s,a)∂θ\frac{\partial f_w(s,a)}{\partial w} = \frac{\partial \ln \pi(s,a)}{\partial \theta}. 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 ww must minimize the mean squared error weighted by the state-action distribution under π\pi. In other words, the critic has been trained to convergence.

When both conditions hold, the approximation error in fwf_w 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.

∂fw(s,a)∂w=1π(s,a)∂π(s,a)∂θ\frac{\partial f_w(s, a)}{\partial w} = \frac{1}{\pi(s, a)} \frac{\partial \pi(s, a)}{\partial \theta}
The compatibility condition — The critic's features must be the score function of the policy. This ensures the critic approximates the advantage — the relative value of actions — rather than absolute values.
Open in Lab
See how the compatibility condition works: the critic features are derived from the policy's score function. Adjust the policy parameters and watch both update together.
The demo wakes as you arrive…

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 — lim⁡k→∞∂ρ(πk)∂θ=0\lim_{k \to \infty} \frac{\partial \rho(\pi_k)}{\partial \theta} = 0.

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 ∂Vπ(s)∂θ\frac{\partial V^\pi(s)}{\partial \theta} and apply the product rule to ∑aπ(s,a)Qπ(s,a)\sum_a \pi(s,a) Q^\pi(s,a). You get two terms: (1) the gradient of the policy times QπQ^\pi — the direct effect — and (2) the policy times the gradient of QπQ^\pi — the indirect effect through future states. Expanding QπQ^\pi using the and unrolling recursively, the indirect terms telescope into a sum over future state visitations. When you sum over the stationary distribution dπd^\pi, the future-state terms cancel with the current-state terms (because dπd^\pi 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 s0s_0 in kk steps, summed over all kk with discount γk\gamma^k, defines dπ(s)d^\pi(s) directly.

Open in Lab
Step through the proof: see how the recursive unrolling creates terms that cancel when summed over the stationary distribution.
The demo wakes as you arrive…

The same idea in code

REINFORCE with baseline — the Policy Gradient Theorem in actionpython

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_pi

Why it changed everything

  1. 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.

  2. 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.

  3. 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.

  4. 2015

    DDPG

    Lillicrap et al. extend policy gradients to continuous action spaces with deterministic policy gradients. Enabled RL for robotics and continuous control.

  5. 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.

  6. 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.

  7. 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.

  8. 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