ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Intermediate Reinforcement Learning Techniques
Chapter 1: Revisiting Reinforcement Learning Fundamentals
The Reinforcement Learning Problem Setup
Markov Decision Processes (MDPs) Recap
Value Functions and Bellman Equations
Tabular Solution Methods: Q-Learning and SARSA
Limitations of Tabular Methods
Quiz for Chapter 1
Chapter 2: Deep Q-Networks (DQN)
Introduction to Function Approximation
Using Neural Networks for Q-Value Approximation
The DQN Algorithm Architecture
Experience Replay Mechanism
Fixed Q-Targets (Target Networks)
Loss Function for DQN Training
Hands-on Practical: Implementing DQN for CartPole
Quiz for Chapter 2
Chapter 3: Improvements and Variants of DQN
The Overestimation Problem in Q-Learning
Double DQN (DDQN)
Dueling Network Architectures
Combining DQN Improvements
Prioritized Experience Replay (Brief Overview)
Practice: Implementing Double DQN
Quiz for Chapter 3
Chapter 4: Policy Gradient Methods
Limitations of Value-Based Methods
Direct Policy Parameterization
The Policy Gradient Theorem
REINFORCE Algorithm
Understanding Variance in Policy Gradients
Baselines for Variance Reduction
Hands-on Practical: Implementing REINFORCE
Quiz for Chapter 4
Chapter 5: Actor-Critic Methods
Combining Policy and Value Estimation
Actor-Critic Architecture Overview
Advantage Actor-Critic (A2C)
Asynchronous Advantage Actor-Critic (A3C)
Implementation Considerations for Actor-Critic
Comparison: REINFORCE vs A2C/A3C
Practice: Developing an A2C Implementation
Quiz for Chapter 5

Baselines for Variance Reduction

The REINFORCE algorithm uses the full Monte Carlo return GtG_tGt​ to scale the gradient ∇θlog⁡π(at∣st;θ)\nabla_\theta \log \pi(a_t|s_t; \theta)∇θ​logπ(at​∣st​;θ). While this provides an unbiased estimate of the policy gradient, the high variance of GtG_tGt​ often leads to noisy updates and slow convergence. Imagine an episode where all rewards are large and positive; GtG_tGt​ will be large for all timesteps, pushing the probabilities of all actions taken higher, even if some actions were much better than others within that successful episode. Conversely, a poor episode might unduly penalize all actions taken.

To mitigate this, we can introduce a baseline function b(s)b(s)b(s) that depends only on the state sts_tst​. We subtract this baseline from the return GtG_tGt​ in the policy gradient update:

∇θJ(θ)≈1N∑i=1N∑t=0Ti−1∇θlog⁡π(ai,t∣si,t;θ)(Gi,t−b(si,t))\nabla_\theta J(\theta) \approx \frac{1}{N} \sum_{i=1}^N \sum_{t=0}^{T_i-1} \nabla_\theta \log \pi(a_{i,t}|s_{i,t}; \theta) (G_{i,t} - b(s_{i,t}))∇θ​J(θ)≈N1​i=1∑N​t=0∑Ti​−1​∇θ​logπ(ai,t​∣si,t​;θ)(Gi,t​−b(si,t​))

Why is this valid? Crucially, subtracting a state-dependent baseline does not introduce bias into the gradient estimate. The expected value of the subtracted term is zero:

Eπθ[∇θlog⁡π(at∣st;θ)b(st)]=∑sdπθ(s)∑aπ(a∣s;θ)[∇θlog⁡π(a∣s;θ)b(s)]\mathbb{E}_{\pi_\theta} [\nabla_\theta \log \pi(a_t|s_t; \theta) b(s_t)] = \sum_{s} d^{\pi_\theta}(s) \sum_{a} \pi(a|s; \theta) [\nabla_\theta \log \pi(a|s; \theta) b(s)]Eπθ​​[∇θ​logπ(at​∣st​;θ)b(st​)]=s∑​dπθ​(s)a∑​π(a∣s;θ)[∇θ​logπ(a∣s;θ)b(s)] =∑sdπθ(s)∑a∇θπ(a∣s;θ)b(s)= \sum_{s} d^{\pi_\theta}(s) \sum_{a} \nabla_\theta \pi(a|s; \theta) b(s)=s∑​dπθ​(s)a∑​∇θ​π(a∣s;θ)b(s) =∑sdπθ(s)b(s)∇θ∑aπ(a∣s;θ)= \sum_{s} d^{\pi_\theta}(s) b(s) \nabla_\theta \sum_{a} \pi(a|s; \theta)=s∑​dπθ​(s)b(s)∇θ​a∑​π(a∣s;θ) =∑sdπθ(s)b(s)∇θ1=0= \sum_{s} d^{\pi_\theta}(s) b(s) \nabla_\theta 1 = 0=s∑​dπθ​(s)b(s)∇θ​1=0

Here, dπθ(s)d^{\pi_\theta}(s)dπθ​(s) is the state distribution under policy πθ\pi_\thetaπθ​. Since the expectation of the term we subtract is zero, the overall expectation of the gradient remains unchanged.

While it doesn't change the expectation, a well-chosen baseline can significantly reduce the variance of the gradient estimate. The intuition is to center the returns around a reference point. Instead of simply scaling the gradient by the total return GtG_tGt​, we scale it by how much better or worse that return was compared to what we typically expect from state sts_tst​. If Gt>b(st)G_t > b(s_t)Gt​>b(st​), the action ata_tat​ led to a better-than-expected outcome, and its probability should be increased. If Gt<b(st)G_t < b(s_t)Gt​<b(st​), the action led to a worse-than-expected outcome, and its probability should be decreased (or increased less strongly).

Choosing the Baseline

What makes a good baseline? Ideally, b(st)b(s_t)b(st​) should be an estimate of the expected return from state sts_tst​.

  1. Simple Constant Baseline: One could use a running average of all returns encountered so far across all episodes. This is very simple but doesn't adapt to the value of specific states.
  2. State-Value Function V(st)V(s_t)V(st​): A much more effective and common choice for the baseline is the state-value function V(st)=Eπθ[Gt∣St=st]V(s_t) = \mathbb{E}_{\pi_\theta}[G_t | S_t = s_t]V(st​)=Eπθ​​[Gt​∣St​=st​]. This represents the expected return if we follow the current policy πθ\pi_\thetaπθ​ starting from state sts_tst​.

Using V(st)V(s_t)V(st​) as the baseline gives rise to the term Gt−V(st)G_t - V(s_t)Gt​−V(st​). Recall that the action-value function is Q(st,at)=Eπθ[Gt∣St=st,At=at]Q(s_t, a_t) = \mathbb{E}_{\pi_\theta}[G_t | S_t = s_t, A_t = a_t]Q(st​,at​)=Eπθ​​[Gt​∣St​=st​,At​=at​], and the advantage function is defined as A(st,at)=Q(st,at)−V(st)A(s_t, a_t) = Q(s_t, a_t) - V(s_t)A(st​,at​)=Q(st​,at​)−V(st​). Since GtG_tGt​ is a Monte Carlo sample of the return starting from (st,at)(s_t, a_t)(st​,at​), the term Gt−V(st)G_t - V(s_t)Gt​−V(st​) is actually an estimate of the advantage function A(st,at)A(s_t, a_t)A(st​,at​).

Using the advantage estimate centers the scaling factor: actions leading to returns better than the average for that state get positive reinforcement, while actions leading to returns worse than average get negative reinforcement. This often results in a significantly lower variance compared to using the raw return GtG_tGt​.

Example showing how subtracting a baseline (V(st)≈10V(s_t) \approx 10V(st​)≈10 in this simplified case) centers the scaling factor around zero and reduces its variance compared to using raw returns GtG_tGt​.

Learning the Value Function Baseline

Of course, we typically don't know the true V(st)V(s_t)V(st​) under the current policy. Therefore, we need to learn it concurrently with the policy. This is usually done using function approximation, often with another neural network. We introduce a value function approximator V(s;w)V(s; w)V(s;w) with parameters www.

This value network V(s;w)V(s; w)V(s;w) is trained to predict the expected return from a given state. Since REINFORCE uses Monte Carlo returns GtG_tGt​, a common approach is to train the value network by minimizing the Mean Squared Error (MSE) between its predictions V(st;w)V(s_t; w)V(st​;w) and the observed returns GtG_tGt​ from the collected trajectories:

L(w)=Eπθ[(Gt−V(st;w))2]L(w) = \mathbb{E}_{\pi_\theta} [(G_t - V(s_t; w))^2]L(w)=Eπθ​​[(Gt​−V(st​;w))2]

So, during training, we perform two main updates in each iteration (after collecting trajectories):

  1. Update Policy Parameters θ\thetaθ: Use the policy gradient with the learned baseline:

    Δθ=αθ∇θlog⁡π(at∣st;θ)(Gt−V(st;w))\Delta \theta = \alpha_\theta \nabla_\theta \log \pi(a_t|s_t; \theta) (G_t - V(s_t; w))Δθ=αθ​∇θ​logπ(at​∣st​;θ)(Gt​−V(st​;w))

    Note that we treat V(st;w)V(s_t; w)V(st​;w) as a fixed baseline value when calculating the policy gradient; we don't backpropagate the policy loss through the value network.

  2. Update Value Function Parameters www: Minimize the MSE loss between predicted values and actual returns:

    Δw=αw∇w(Gt−V(st;w))2=αw⋅2(Gt−V(st;w))(−∇wV(st;w))\Delta w = \alpha_w \nabla_w (G_t - V(s_t; w))^2 = \alpha_w \cdot 2 (G_t - V(s_t; w)) (-\nabla_w V(s_t; w))Δw=αw​∇w​(Gt​−V(st​;w))2=αw​⋅2(Gt​−V(st​;w))(−∇w​V(st​;w))

Here, αθ\alpha_\thetaαθ​ and αw\alpha_wαw​ are the learning rates for the policy and value function, respectively.

This approach of using a learned value function V(s;w)V(s; w)V(s;w) as a baseline for a policy gradient method forms the basis of Actor-Critic algorithms, which we will discuss in detail in the next chapter. The policy network π(a∣s;θ)\pi(a|s; \theta)π(a∣s;θ) is the "Actor," deciding which actions to take, and the value network V(s;w)V(s; w)V(s;w) is the "Critic," evaluating the states visited by the Actor and providing the baseline to reduce variance in the Actor's learning signal.

  • Reinforcement Learning: An Introduction, Richard S. Sutton and Andrew G. Barto, 2018 (MIT Press) - Standard textbook on reinforcement learning. This edition details policy gradient methods, the use of baselines for variance reduction, and the principles of actor-critic algorithms. 2nd edition.
  • Actor-Critic Algorithms, Vijay R. Konda and John N. Tsitsiklis, 1999 Advances in Neural Information Processing Systems 12 (MIT Press) DOI: 10.1137/S0363012901385691 - This paper introduced actor-critic algorithms, an approach that uses baselines for policy gradient variance reduction.
  • Lecture 9: Policy Gradients & Actor-Critic, Emma Brunskill, 2023 CS234: Reinforcement Learning (Stanford University) - Lecture slides from Stanford University's CS234 course. These slides cover policy gradients, the benefits of baselines for variance reduction, and introduce actor-critic methods.

© 2026 ApX Machine Learning