Chapter 202
📝Draft

REINFORCE

The foundational policy gradient algorithm

What You'll Learn

  • State and explain the Policy Gradient Theorem
  • Implement the REINFORCE algorithm from scratch
  • Understand the log-derivative trick and why we use log probabilities
  • Identify and explain the variance problem in REINFORCE
  • Implement baselines to reduce gradient variance

We want to improve our policy by gradient ascent. But there’s a problem: the gradient of expected return involves the environment dynamics, which we don’t know. The Policy Gradient Theorem resolves this - we can compute the gradient using only samples from our policy.

Why REINFORCE?

In value-based methods like Q-learning, we learned a value function and derived a policy from it. REINFORCE takes a fundamentally different approach: optimize the policy directly.

What makes this possible is that we can compute policy gradients without knowing how the environment works. We just need to:

  1. Sample trajectories from our current policy
  2. Compute returns for those trajectories
  3. Update the policy to make high-return actions more likely

Chapter Overview

This chapter derives the Policy Gradient Theorem and introduces REINFORCE, the simplest policy gradient algorithm. We’ll also tackle its main weakness - high variance - and introduce baselines as a solution.

The Big Picture

REINFORCE follows a simple recipe:

  1. Collect a complete episode using the current policy
  2. Compute the return (cumulative reward) from each timestep
  3. Update the policy to increase the probability of actions that led to high returns
📖Policy Gradient

The gradient of the expected return with respect to the policy parameters. It tells us how to adjust the policy to increase expected reward.

The Policy Gradient Theorem shows us that this gradient takes a strikingly usable form:

θJ(θ)=Eτπθ[t=0Tθlogπθ(atst)Gt]\nabla_\theta J(\theta) = \mathbb{E}_{\tau \sim \pi_\theta} \left[ \sum_{t=0}^{T} \nabla_\theta \log \pi_\theta(a_t|s_t) \cdot G_t \right]

High-return actions get reinforced; low-return actions get suppressed. That’s the essence of REINFORCE.

Throughout this chapter our test bed is CartPole, the running example: the algorithm sections train a REINFORCE agent to balance the pole, and the variance section measures exactly how noisy those gradient estimates are on it.

Prerequisites

This chapter assumes familiarity with:

  • The policy gradient objective from Introduction to Policy Gradients
  • Stochastic policies and probability distributions over actions
  • Basic calculus (gradients, chain rule)

Check Your Understanding

Check your understanding
1. Why does the policy gradient theorem let us avoid knowing the environment dynamics?
2. REINFORCE is a Monte Carlo method. What does that imply about its estimates?
3. Why does subtracting a baseline b(s) from the return not bias the gradient?
4. Why use reward-to-go G_t instead of the full trajectory return R(tau) when weighting the gradient at step t?
5. On CartPole, why does plain REINFORCE typically need more episodes than DQN to solve the task?
  1. The Policy Gradient Theorem removes the dynamics
    Gradients of expected return depend only on grad log pi—the environment terms vanish because they carry no theta.
  2. The log-derivative trick turns gradients into expectations
    Which means we can estimate them by sampling trajectories from the current policy.
  3. REINFORCE is the direct implementation
    Update theta by alpha * grad log pi(a|s) * G_t, computed from complete episodes.
  4. Unbiased but noisy
    Monte Carlo returns make the estimate unbiased and high-variance—the exact opposite trade-off from TD bootstrapping.
  5. Baselines are free variance reduction
    Subtracting any state-dependent b(s) leaves the expected gradient unchanged while shrinking its variance.

Primary Sources

  • Williams (1992), “Simple Statistical Gradient-Following Algorithms for Connectionist Reinforcement Learning,” Machine Learning 8 — the original REINFORCE paper, including the baseline idea. Springer page
  • Sutton, McAllester, Singh & Mansour (1999), “Policy Gradient Methods for Reinforcement Learning with Function Approximation,” NeurIPS 1999 — the general policy gradient theorem, including the function-approximation case
Next ChapterActor-Critic Methods