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:
- Sample trajectories from our current policy
- Compute returns for those trajectories
- 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 Policy Gradient Theorem
The mathematical foundation for computing policy gradients
The REINFORCE Algorithm
Monte Carlo policy gradients in action
The Variance Problem
Why REINFORCE gradients are noisy and unstable
Baselines
Reducing variance without introducing bias
The Big Picture
REINFORCE follows a simple recipe:
- Collect a complete episode using the current policy
- Compute the return (cumulative reward) from each timestep
- Update the policy to increase the probability of actions that led to high returns
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:
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
- The Policy Gradient Theorem removes the dynamicsGradients of expected return depend only on grad log pi—the environment terms vanish because they carry no theta.
- The log-derivative trick turns gradients into expectationsWhich means we can estimate them by sampling trajectories from the current policy.
- REINFORCE is the direct implementationUpdate theta by alpha * grad log pi(a|s) * G_t, computed from complete episodes.
- Unbiased but noisyMonte Carlo returns make the estimate unbiased and high-variance—the exact opposite trade-off from TD bootstrapping.
- Baselines are free variance reductionSubtracting 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