Introduction
Supervised learning and unsupervised learning are two paradigms of machine learning. We now turn to a third.
Reinforcement Learning (RL) is a framework in which an agent interacts with an environment
to learn a behavior that maximizes a scalar reward signal over time.
Formally, the environment is typically modeled as a Markov Decision Process (MDP), defined by a tuple
\[
(\mathcal{S}, \mathcal{A}, \mathcal{T}, r, \gamma).
\]
Here \(\mathcal{S}\) is the state space, \(\mathcal{A}\) is the action space, \(\mathcal{T}\) is the transition kernel (a
conditional distribution \(\mathcal{T}(s' \mid s, a)\)), \(r\) is the reward function, and \(\gamma\) is the discount factor.
The MDP definition below gives a more detailed probabilistic formulation. It writes the transition kernel as
\(p_T\), separates the stochastic reward kernel \(p_R\) from the expected reward function \(R\), and includes the
initial state distribution explicitly. The discount factor \(\gamma\) is then treated as part of the objective
rather than of the environment.
At each time step, the agent observes a state \(s_t \in \mathcal{S}\) and selects an action \(a_t \in \mathcal{A}\).
The environment then transitions to a new state \(s_{t+1}\) according to the transition dynamics \(\mathcal{T}(s_{t+1} \mid s_t, a_t)\)
and emits a reward \(r_t\).
The goal of the agent is to learn a policy \(\pi(a \mid s)\) that maximizes the expected cumulative reward:
\[
\mathbb{E}_\pi \left[ \sum_{t=0}^\infty \gamma^t r_t \right].
\]
Reinforcement learning differs fundamentally from other machine learning paradigms:
- Supervised learning trains models on ground-truth input-output pairs with explicit correct labels for each input.
- Unsupervised learning discovers hidden structure or representations in unlabeled data without any feedback signal.
- Reinforcement learning uses only a scalar reward signal that provides evaluative feedback based on the agent's interaction with an environment.
In RL, learning is typically driven by trial-and-error interaction rather than by labeled examples, and the objective
is a policy that maximizes expected cumulative reward rather than a model of the data. The offline (or batch) setting,
in which an agent learns from a fixed pre-collected dataset instead of interacting, is a notable exception.
RL has been successfully applied in domains such as robotics, recommendation systems, and game-playing. RL has also been used
in the training of large language models (LLMs). In particular, a method called
Reinforcement Learning from Human Feedback (RLHF) has been used to fine-tune LLMs to follow
human preferences, aiming to make outputs more helpful, safe, and better aligned with user intent.
Classification of RL Algorithms
Model-Based vs Model-Free Methods
The most fundamental distinction in RL concerns whether the agent learns an explicit model of the environment.
Model-based RL methods estimate the following from data:
- the transition dynamics \(p_T(s' \mid s, a)\), and
- the reward model \(p_R(r \mid s, a, s')\).
Once the model is learned, the agent uses planning algorithms to compute a policy that is optimal for
that model. Classical planning is based on dynamic programming such as value iteration (VI) and
policy iteration (PI). The main advantage is environment-sample efficiency. The agent can
simulate many trajectories using the learned model without additional environment interaction. However, model learning
introduces model bias. If the learned model is inaccurate, the agent may perform well in simulation but
poorly in the real environment.
Model-free RL methods bypass explicit environment modeling and directly learn value functions or policies
from experience. These methods are generally simpler to implement and more robust to model errors, but typically require
more environment interactions than model-based approaches.
Value-Based vs Policy-Based
This taxonomy classifies algorithms based on what they learn within model-free RL.
Value-based methods learn an action-value function from experience, either the optimal one \(Q_*\) directly
or the action-value function \(Q_\pi\) of the policy \(\pi\) being followed, often through an approximator \(Q_{\mathbf{w}}\)
(typically a neural network trained iteratively). They then act greedily, or nearly greedily to keep exploring, with respect
to the estimate. Acting greedily with respect to \(Q_*\) itself gives an optimal policy,
\(\pi_*(s) \in \arg\max_a Q_*(s, a)\). To learn \(Q_*\), we define the temporal difference (or
TD error) of a transition \((s, a, r, s')\) as
\[
r + \gamma \max_{a'} Q_{\mathbf{w}}(s', a') - Q_{\mathbf{w}}(s, a),
\]
whose conditional expectation given \((s, a)\) is the Bellman optimality residual at \((s, a)\). When
\(Q_{\mathbf{w}} = Q_*\), the TD error is zero on average by Bellman's optimality equation (stated in the Value Functions
section below), so a non-zero expected TD error provides a learning signal.
Examples include Q-learning, SARSA, and Deep Q-Networks (DQN).
These methods differ in their bootstrap target. For instance, SARSA replaces the \(\max_{a'}\) above with the
actually-taken next action \(a'\). The precise update rules are given in the TD-learning sections below.
Policy-based methods directly optimize the expected-return objective
\[
J(\pi_{\boldsymbol{\theta}}) := \mathbb{E}_{\pi_{\boldsymbol{\theta}}} \left[ \sum_{t=0}^{\infty} \gamma^t r_t \right]
\]
with respect to the policy parameter \(\boldsymbol{\theta}\) using policy gradient, and can naturally handle
continuous action spaces and stochastic policies.
Examples include REINFORCE, Trust Region Policy Optimization (TRPO), and actor-critic methods
such as Advantage Actor-Critic (A2C), Deep Deterministic Policy Gradient (DDPG), Soft Actor-Critic (SAC),
and Proximal Policy Optimization (PPO).
On-Policy vs Off-Policy Methods
This taxonomy concerns the data usage strategy during learning.
On-policy methods learn from data generated by the current policy that is being improved.
The agent explores the environment and makes updates to its policy based on the actions it has taken.
(Examples include SARSA, REINFORCE, A2C, and PPO.)
Off-policy methods learn from data generated by a policy different from the one being
improved. This allows the agent to reuse old data or learn from data collected by other agents. The policy used to
collect data is called the behavioral policy, and the policy being learned is called the target policy.
Off-policy methods typically offer higher sample efficiency than on-policy methods. Some of them must
correct for the mismatch between the behavioral and target distributions, for example with importance-sampling weights
in off-policy policy-gradient estimators. One-step Q-learning needs no such correction, because its target does not
depend on the behavioral policy.
(Examples include Q-learning, DQN, DDPG, and SAC.)
Exploration vs. Exploitation
The exploration-exploitation tradeoff is fundamental to reinforcement learning. An agent must
balance between:
- Exploitation. Choosing actions that yield high rewards based on current knowledge.
- Exploration. Trying new actions to potentially discover better strategies.
All strategies in this section assume access to action-value estimates \(Q(s, a)\), the action-value function
formally defined in the Value Functions section below. Here we use it operationally as "the agent's current estimate
of how good action \(a\) is in state \(s\)."
\(\varepsilon\)-Greedy Strategy
The simplest exploration strategy chooses:
\[
a_t = \begin{cases}
\arg\max_a Q(s_t, a) & \text{with probability } 1-\varepsilon \\
\text{uniformly random action over } \mathcal{A} & \text{with probability } \varepsilon
\end{cases}
\]
where \(\varepsilon \in [0,1]\) controls the exploration rate. Often \(\varepsilon\) is decayed over time.
Note that the random branch samples uniformly from all actions (including the greedy one),
so, when the greedy action is unique, it is selected with total probability \(1 - \varepsilon + \varepsilon / |\mathcal{A}|\).
Softmax Action Selection
A more sophisticated approach uses the Boltzmann (softmax) distribution:
\[
P(a_t = a \mid s_t) = \frac{\exp(Q(s_t, a)/\tau)}{\sum_{a'} \exp(Q(s_t, a')/\tau)}
\]
where \(\tau \gt 0\) is the temperature parameter. Higher temperatures lead to more exploration.
When the action set \(\mathcal{A}\) is finite, the softmax rule has an exact optimality property. Among all
distributions \(\pi(\cdot \mid s_t)\) on \(\mathcal{A}\), the distribution that the rule assigns to the state \(s_t\) is
the only one that maximizes
\[
\sum_{a \in \mathcal{A}} \pi(a \mid s_t)\, Q(s_t, a) - \tau \sum_{a \in \mathcal{A}} \pi(a \mid s_t) \log \pi(a \mid s_t),
\]
the expected action value plus \(\tau\) times the
entropy of the action
distribution, where \(\log\) is the natural logarithm, with the convention \(0 \log 0 = 0\).
In the Gibbs variational principle with temperature,
we take the uniform distribution on \(\mathcal{A}\) as the reference and the action values \(Q(s_t, a)\) as the scores. The
objective of the principle then differs from the displayed one only by the constant \(\tau \log |\mathcal{A}|\), because the
KL divergence of the action
distribution from the uniform distribution is \(\log |\mathcal{A}|\) minus the entropy. The two objectives therefore have the
same unique maximizer, and the principle gives it as the softmax distribution above.
Optimistic Initialization
Initializing Q-values optimistically (to values higher than realistic ones) encourages exploration
of all actions early in learning, as the agent will be "disappointed" by actual rewards
and try other actions. This technique is most effective in the tabular setting. With neural-network
function approximators, a uniform "optimistic" initialization is harder to enforce,
and the trick does not transfer cleanly to deep RL.
The choice of exploration strategy significantly affects learning performance and is often
problem-dependent. More advanced methods like UCB (Upper Confidence Bound) and Thompson
sampling provide principled approaches to this tradeoff.
Markov Decision Process (MDP)
Before we turn to RL algorithms, this section presents a detailed probabilistic formulation of Markov Decision Processes
(MDPs), where both transitions and rewards are modeled as random variables. This perspective extends the classical
formulation, which often takes the reward function to be deterministic, and is particularly useful for analyzing trajectory
distributions and gradient-based learning methods used in reinforcement learning.
An agent sequentially interacts with an initially unknown environment to obtain a trajectory
or multiple trajectories. A trajectory of length \(T\) (that is, consisting of \(T\) transitions) is defined as:
\[
\boldsymbol{\tau} = (s_0, a_0, r_0, s_1, a_1, r_1, s_2, \ldots, a_{T-1}, r_{T-1}, s_T),
\]
where \(s_t\) is a state, \(a_t\) is an action, and \(r_t\) is a reward.
The objective is to optimize the agent's action-selection policy so as to maximize the expectation
\(\mathbb{E}[G_0]\) of the discounted cumulative reward
\[
G_0 = \sum_{t = 0}^{T -1} \gamma^t r_t,
\]
where \(\gamma \in [0, 1]\) is the discount factor. We assume the environment follows a
Markov Decision Process (MDP), where the trajectory distribution can be factored into
single-step transition and reward models. The process of estimating an optimal policy from trajectories
is referred to as learning.
Definition: Markov Decision Process (MDP)
An MDP is a tuple
\(\left\langle \mathcal{S}, \mathcal{A}, p_T, p_R, p_0 \right\rangle\)
where:
- \(\mathcal{S}\): set of environment states
- \(\mathcal{A}\): set of available actions
- \(p_T(s' \mid s, a)\): transition model (next-state distribution)
- \(p_R(r \mid s, a, s')\): reward model (stochastic reward distribution)
- \(p_0(s_0)\): initial state distribution
At time \(t = 0\), the initial state is sampled as \(s_0 \sim p_0\). At each step \(t \geq 0\), the agent observes
state \(s_t \in \mathcal{S}\), selects action \(a_t \sim \pi(\cdot \mid s_t)\), and receives reward
\(r_t \sim p_R(\cdot \mid s_t, a_t, s_{t+1})\), where the next state \(s_{t+1}\) is drawn from \(p_T(\cdot \mid s_t, a_t)\).
The agent's decision-making is governed by a stochastic policy \(\pi(a \mid s)\).
This interaction at each step is called a transition, represented as the tuple:
\[
(s_t, a_t, r_t, s_{t+1}),
\]
where:
- \(a_t \sim \pi(\cdot \mid s_t)\)
- \(s_{t+1} \sim p_T(\cdot \mid s_t, a_t)\)
- \(r_t \sim p_R(\cdot \mid s_t, a_t, s_{t+1})\)
The transition kernel \(p_T(s_{t+1} \mid s_t, a_t)\) depends only on the current state and action, not on prior history.
This is the first-order Markov property
in its state-action form, and it makes the trajectory distribution factorize cleanly.
Sharpened to hold at random stopping times, the same idea becomes the strong Markov property. The probability section develops
it rigorously in continuous time, as the
strong Markov property of Itô diffusions.
Under policy \(\pi\), the joint distribution of a trajectory \(\boldsymbol{\tau}\) of length \(T\) is given by:
\[
p(\boldsymbol{\tau}) = p_0(s_0) \prod_{t = 0}^{T -1}
\pi(a_t \mid s_t) \, p_T(s_{t+1} \mid s_t, a_t) \, p_R(r_t \mid s_t, a_t, s_{t+1}).
\]
We define the expected reward function from the reward model \(p_R\) as the marginal average immediate reward
for taking action \(a\) in state \(s\), integrating over possible next states:
\[
R(s, a) = \mathbb{E}_{p_T(s' \mid s, a)} \left[
\mathbb{E}_{p_R(r \mid s, a, s')}[r]
\right].
\]
While classical RL literature often starts with a deterministic reward function \(r(s, a)\) as a primitive,
our probabilistic formulation derives \(R(s, a)\) by taking the expectation under the stochastic reward kernel \(p_R\).
Writing the trajectory distribution out in full is also useful for gradient-based RL methods. The environment
factors \(p_0\), \(p_T\), and \(p_R\) do not depend on the policy, which is why only policy terms survive in the
policy gradient derived below.
Value Functions and Bellman Equations
Definition: Return
Let \(\boldsymbol{\tau}\) be a trajectory. The return at time \(t\) is the total accumulated reward
from that point forward, discounted by a factor \(\gamma \in [0, 1]\). For an episodic task of finite horizon \(T\),
\[
\begin{align*}
G_t &= r_t + \gamma r_{t+1} + \gamma^2 r_{t+2} + \cdots + \gamma^{T - t - 1} r_{T - 1} \\\\
&= \sum_{k = 0}^{T - t - 1} \gamma^k r_{t + k} \\\\
&= \sum_{j = t}^{T - 1} \gamma^{j - t} r_j.
\end{align*}
\]
For a continuing task (\(T = \infty\)), the upper limit becomes \(\infty\):
\[
G_t = \sum_{k = 0}^{\infty} \gamma^k r_{t + k},
\]
which converges absolutely whenever \(\gamma \in [0, 1)\) and the rewards are bounded.
Convention. Throughout this page, the subscript on \(\mathbb{E}\) names the distribution being averaged
over. In particular, the notation \(\mathbb{E}_\pi[\,\cdot\,]\) abbreviates expectation over full trajectories generated by
\(\pi\), while \(\mathbb{E}_{\pi(a \mid s)}[\,\cdot\,]\) is expectation over the action variable alone, drawn from
\(\pi(\cdot \mid s)\).
For the exact results on this page (the Bellman equations, the dynamic-programming analysis, the convergence results for TD
methods, and the policy gradient theorem), we also make three standing assumptions: \(\mathcal{S}\) and \(\mathcal{A}\) are
finite, rewards are bounded, and \(\gamma \in [0, 1)\). An episodic task fits this setting when its terminal state is treated
as absorbing with zero reward, so the return of an episode that ends at time \(T\) is the finite sum in the definition of the
return. These assumptions make every value function below well defined and bounded.
Definition: State-Value Function
Given a stochastic policy \(\pi(a \mid s)\), the state-value function
(or value function) under the policy \(\pi\) is defined as:
\[
\begin{align*}
V_{\pi}(s) &= \mathbb{E}_{\pi}\left[G_0 \mid s_0 = s\right] \\\\
&= \mathbb{E}_{\pi}\left[\sum_{t = 0}^{\infty} \gamma^t r_t \mid s_0 = s\right],
\end{align*}
\]
where the expectation is over trajectories induced by the policy \(\pi\) starting from state \(s\).
Definition: Action-Value Function (Q-Function)
The action-value function (or Q-function) under the policy \(\pi\) is defined as
\[
\begin{align*}
Q_{\pi}(s, a) &= \mathbb{E}_{\pi} \left[ G_0 \mid s_0 = s, \, a_0 = a \right] \\\\
&= \mathbb{E}_{\pi} \left[ \sum_{t = 0}^{\infty} \gamma^t r_t \mid s_0 = s, \, a_0 = a \right],
\end{align*}
\]
the expected return when starting in state \(s\), taking action \(a\), and thereafter following \(\pi\).
Definition: Advantage Function
The advantage function is the difference between the action-value and state-value functions:
\[
A_{\pi}(s, a) = Q_{\pi}(s, a) - V_{\pi}(s).
\]
This measures how much better action \(a\) is in state \(s\) than the average value of actions drawn from
\(\pi(\cdot \mid s)\).
Under the standing assumptions the discount factor keeps the return finite even for infinite-horizon problems. It also gives
higher weight to short-term rewards, thereby encouraging the agent to achieve goals sooner.
A policy \(\pi_*\) is called an optimal policy if it yields the highest value for every state:
\[
\forall s \in \mathcal{S}, \quad V_{\pi_*}(s) \geq V_{\pi}(s), \quad \forall \pi.
\]
Although multiple optimal policies may exist, their value functions are the same: \(V_*(s) = V_{\pi_*}(s)\) and \(Q_*(s, a) = Q_{\pi_*}(s, a)\).
Moreover, since the action space \(\mathcal{A}\) is finite, the maximum in the Bellman optimality equation (stated immediately below)
is attained at every state, so selecting any maximizer
\[
\pi_*(s) \in \arg\max_a \left[ R(s, a) + \gamma \, \mathbb{E}_{p_T(s' \mid s, a)} \left[ V_*(s') \right] \right]
\]
yields a deterministic optimal policy. Indeed, \(V_*\) then solves the Bellman expectation equation of this policy
(stated below). That equation has a unique solution by the policy-evaluation analysis below, so the policy's value
function is \(V_*\).
Theorem: Bellman's Optimality Equations
\[
\begin{align*}
V_*(s) &= \max_a \left[ R(s, a) + \gamma \, \mathbb{E}_{p_T(s' \mid s, a)} \left[ V_*(s') \right] \right] \\\\
Q_*(s, a) &= R(s, a) + \gamma \, \mathbb{E}_{p_T(s' \mid s, a)} \left[ \max_{a'} Q_*(s', a') \right].
\end{align*}
\]
Under the standing assumptions above, the optimal value functions \(V_*\) and \(Q_*\) are the unique fixed points of
these equations. The right-hand side of each equation defines a \(\gamma\)-contraction in the supremum norm, and
uniqueness follows from the Banach Fixed-Point Theorem (used explicitly in the value-iteration analysis below).
We state these equations without proof. For \(V_*\), uniqueness follows from the contraction argument carried out for value
iteration below. For \(Q_*\), the same computation applies, with the inequality
\(|\max_{a'} f(a') - \max_{a'} g(a')| \leq \max_{a'} |f(a') - g(a')|\) used inside the expectation over \(s'\). The fact
that \(V_*\) and \(Q_*\) satisfy the equations rests on Bellman's principle of optimality (discussed below), which we also
take as given.
An optimal policy is then given by:
\[
\begin{align*}
\pi_*(s) &\in \arg \max_a Q_*(s, a) \\\\
&= \arg \max_a \left[ R(s, a) + \gamma \, \mathbb{E}_{p_T(s' \mid s, a)} \left[ V_*(s') \right] \right].
\end{align*}
\]
Solving for \(V_*\), \(Q_*\), or \(\pi_*\) is known as policy optimization, while computing
\(V_{\pi}\) or \(Q_{\pi}\) for a given policy \(\pi\) is called policy evaluation.
Both the Bellman optimality equations and the Bellman expectation equations follow the same recursive structure. The value of
a state equals the immediate reward plus the discounted value of successor states. The two families differ only in how the
action is chosen. The optimality equations maximize over it, \(\max_a[\,\cdot\,]\), and so give the value of acting
optimally. In the expectation equations, the action is averaged over \(\pi\), \(\mathbb{E}_{\pi(a \mid s)}[\,\cdot\,]\), and
the result is the value of following the fixed policy \(\pi\).
Theorem: Bellman's Expectation Equations
For a fixed policy \(\pi\), the state-value function satisfies:
\[
V_{\pi}(s) = \mathbb{E}_{\pi(a \mid s)} \left[ R(s, a) + \gamma \, \mathbb{E}_{p_T(s' \mid s, a)} \left[ V_{\pi}(s') \right] \right].
\]
The action-value function satisfies:
\[
Q_{\pi}(s, a) = R(s, a) + \gamma \, \mathbb{E}_{p_T(s' \mid s, a)} \left[ \mathbb{E}_{\pi(a' \mid s')} \left[ Q_{\pi}(s', a') \right] \right].
\]
We only sketch the proof of these equations. Each follows by conditioning the return \(G_0\), with \(s_0 = s\), on the first
transition \((s_0, a_0, r_0, s_1)\). By the Markov property, the conditional expectation of the return from time \(1\)
onward, given this transition, depends only on \(s_1\), and it equals \(V_{\pi}(s_1)\). For \(Q_{\pi}\), we also use
\(V_{\pi}(s') = \mathbb{E}_{\pi(a' \mid s')}[Q_{\pi}(s', a')]\).
Dynamic Programming Algorithms for RL
Dynamic programming (DP) is a technique for solving optimization problems by breaking them down into
simpler subproblems and storing the results to avoid redundant computations. In the context of reinforcement learning, DP methods
solve MDPs when the complete model (transition probabilities and rewards) is known.
The key insight of DP for MDPs is that optimal policies have the property that whatever the initial state and initial decision are,
the remaining decisions must constitute an optimal policy with regard to the state resulting from the first decision.
This is known as Bellman's principle of optimality, which leads to the recursive Bellman equations.
Value Iteration (VI) and Policy Iteration (PI) are the two classical dynamic programming methods for solving MDPs. These
algorithms are fundamental to model-based reinforcement learning, where an agent first learns the MDP model
from experience and then applies these DP methods to compute policies that are optimal for the learned model.
Value Iteration (VI)
Let the initial estimate be \(V_0\). We update it as follows:
\[
V_{k+1}(s) = \max_a \left[ R(s, a) + \gamma \sum_{s'} p_T(s' \mid s, a) V_k (s') \right].
\]
This is called a Bellman backup. The backup operator is a \(\gamma\)-contraction in the
\(\ell_\infty\) norm, and in particular each iterate satisfies
\[
\| V_{k+1} - V_* \|_\infty \leq \gamma \| V_k - V_* \|_\infty
\]
where \( \| V \|_\infty = \max_{s \in \mathcal{S}} |V(s)| \).
Proof of contraction.
Fix any \(s \in \mathcal{S}\). Let \(F_k(s, a) := R(s, a) + \gamma \sum_{s'} p_T(s'\mid s, a) V_k(s')\) and
\(F_*(s, a) := R(s, a) + \gamma \sum_{s'} p_T(s'\mid s, a) V_*(s')\). Then \(V_{k+1}(s) = \max_a F_k(s, a)\) and
\(V_*(s) = \max_a F_*(s, a)\) (the latter by Bellman optimality). Using the elementary inequality
\(|\max_a f(a) - \max_a g(a)| \leq \max_a |f(a) - g(a)|\), we obtain
\[
\begin{align*}
|V_{k+1}(s) - V_*(s)| &\leq \max_a |F_k(s, a) - F_*(s, a)| \\\\
&= \max_a \gamma \left| \sum_{s'} p_T(s'\mid s, a)\, [V_k(s') - V_*(s')] \right| \\\\
&\leq \gamma \max_a \sum_{s'} p_T(s'\mid s, a)\, |V_k(s') - V_*(s')| \\\\
&\leq \gamma \|V_k - V_*\|_\infty,
\end{align*}
\]
where the last step uses \(\sum_{s'} p_T(s'\mid s, a) = 1\) and \(|V_k(s') - V_*(s')| \leq \|V_k - V_*\|_\infty\).
Taking \(\max_s\) on the left gives the claim.
The same computation with \(V_k\) and \(V_*\) replaced by any two functions \(U, W : \mathcal{S} \to \mathbb{R}\) shows
that the backup operator contracts every pair of functions by the factor \(\gamma\).
Because \( 0 \leq \gamma \lt 1 \) and \(\mathbb{R}^{|\mathcal{S}|}\) is
complete
under \(\| \cdot \|_\infty\), the
Banach Fixed-Point Theorem
guarantees that the backup operator has a unique fixed point and that \(V_k\) converges to it as \(k \to \infty\). By
Bellman's optimality equation, this fixed point is \(V_*\). The inequality above gives the rate
\(\| V_k - V_* \|_\infty \leq \gamma^k \| V_0 - V_* \|_\infty\).
For all possible states \(s\), value iteration approximates \(V_*(s)\) and \(\pi_*(s)\), averaging over all possible
next states \(s'\) at each iteration. (Note: If we need the value and policy for only certain starting states, other
methods, such as real-time dynamic programming, can be used.)
The pseudocode below overwrites \(V(s)\) in place, a form of asynchronous value iteration.
This variant also converges to \(V_*\), which we state without proof.
VALUE_ITERATION
Input: \(M = \left\langle \mathcal{S}, \mathcal{A}, p_T(s' | s, a), R(s, a), \gamma \right\rangle\)
Output: \(V \approx V_*\), greedy policy \(\pi\)
begin
Initialize \(V(s)\) arbitrarily for all \(s \in \mathcal{S}\) (typically \(V(s) = 0\))
repeat:
\(\Delta \leftarrow 0\)
for each \(s \in \mathcal{S}\):
\(V^{\text{old}}(s) \leftarrow V(s)\)
\(V(s) \leftarrow \max_a \left[R(s,a) + \gamma \sum_{s'} p_T(s'|s,a) V(s')\right]\)
\(\Delta \leftarrow \max(\Delta, |V^{\text{old}}(s) - V(s)|)\)
until \(\Delta \lt \theta\) (small threshold)
// Extract greedy policy
for each \(s \in \mathcal{S}\):
\(\pi(s) \leftarrow \arg\max_a \left[R(s,a) + \gamma \sum_{s'} p_T(s'|s,a) V(s')\right]\)
end
Policy Iteration (PI)
Let \(\mathbf{v} \in \mathbb{R}^{|\mathcal{S}|}\) be the value function vector where \(v_i = V_{\pi}(s_i)\).
We define the expected reward vector \(\mathbf{r}\) and the state transition matrix \(\mathbf{T}\) as:
\[
\begin{align*}
\mathbf{r}(s) &= \sum_a \pi(a \mid s) R(s, a), \\\\
\mathbf{T}(s' \mid s) &= \sum_a \pi(a \mid s) p_T(s' \mid s, a).
\end{align*}
\]
The Bellman expectation equation for policy evaluation then forms a linear system:
\[
\mathbf{v} = \mathbf{r} + \gamma \mathbf{T}\mathbf{v}.
\]
Theoretically, the exact solution is \(\mathbf{v} = (\mathbf{I} - \gamma \mathbf{T})^{-1} \mathbf{r}\).
Since \(\mathbf{T}\) is a row-stochastic matrix, its maximum absolute row sum is \(1\), which bounds every eigenvalue
in modulus, so the spectral radius \(\rho(\gamma \mathbf{T}) = \gamma \rho(\mathbf{T}) \leq \gamma \lt 1\). This guarantees that
\(\mathbf{I} - \gamma \mathbf{T}\) is non-singular and that the Neumann series
\(\sum_{k=0}^{\infty} (\gamma \mathbf{T})^k = (\mathbf{I} - \gamma \mathbf{T})^{-1}\) converges.
In practice, we solve this iteratively using the update \(\mathbf{v}_{k+1} = \mathbf{r} + \gamma \mathbf{T} \mathbf{v}_k\).
Once \(V_{\pi}\) is evaluated, the policy improvement step sets
\[
\pi'(s) \in \arg \max_a \left\{ R(s, a) + \gamma \, \mathbb{E}_{p_T(s' \mid s, a)} [V_{\pi}(s')] \right\}.
\]
This guarantees \(V_{\pi'} \geq V_{\pi}\) componentwise.
To see why, write \(\mathbf{r}', \mathbf{T}'\) for the
reward vector and transition matrix induced by \(\pi'\) (analogous to \(\mathbf{r}, \mathbf{T}\) for \(\pi\)).
By the definition of \(\pi'\) as the greedy improvement,
\(\mathbf{r}' + \gamma \mathbf{T}' \mathbf{v} \geq \mathbf{r} + \gamma \mathbf{T} \mathbf{v} = \mathbf{v}\)
componentwise, where the equality is the Bellman expectation equation for \(\pi\). Iterating this inequality,
using that \(\mathbf{T}'\) has non-negative entries (so it preserves componentwise inequalities), gives
\[
\begin{align*}
\mathbf{v} &\leq \mathbf{r}' + \gamma \mathbf{T}'\mathbf{v} \\\\
&\leq \mathbf{r}' + \gamma \mathbf{T}'(\mathbf{r}' + \gamma \mathbf{T}'\mathbf{v}) \\\\
&\leq \cdots \leq \sum_{k=0}^{n-1} (\gamma \mathbf{T}')^k \mathbf{r}' + (\gamma \mathbf{T}')^n \mathbf{v}.
\end{align*}
\]
Let \(n \to \infty\). The partial sum converges to \((\mathbf{I} - \gamma \mathbf{T}')^{-1}\mathbf{r}' = \mathbf{v}'\)
by the Neumann-series argument above (since \(\rho(\gamma \mathbf{T}') \lt 1\)), and the residual \((\gamma \mathbf{T}')^n \mathbf{v} \to \mathbf{0}\)
for the same reason. Therefore \(\mathbf{v} \leq \mathbf{v}'\), that is, \(V_{\pi} \leq V_{\pi'}\) componentwise.
POLICY_ITERATION
Input: \(M = \left\langle \mathcal{S}, \mathcal{A}, p_T(s' | s, a), R(s, a), \gamma \right\rangle\)
Output: policy \(\pi\) (optimal when policy evaluation is exact)
begin
Initialize \(V_{\pi}(s)\) arbitrarily for all \(s \in \mathcal{S}\) (typically \(V_{\pi}(s) = 0\))
Initialize \(\pi(s)\) arbitrarily for all \(s \in \mathcal{S}\)
repeat:
// Policy Evaluation
repeat:
\(\Delta \leftarrow 0\)
for each \(s \in \mathcal{S}\):
\(V_{\pi}^{\text{old}}(s) \leftarrow V_{\pi}(s)\)
\(V_{\pi}(s) \leftarrow \sum_a \pi(a|s) \left[R(s,a) + \gamma \sum_{s'} p_T(s'|s,a) V_{\pi}(s')\right]\)
\(\Delta \leftarrow \max(\Delta, |V_{\pi}^{\text{old}}(s) - V_{\pi}(s)|)\)
until \(\Delta \lt \theta\) (small threshold)
// Policy Improvement
\(\text{policy-stable} \leftarrow \text{true}\)
for each \(s \in \mathcal{S}\):
\(\text{old-action} \leftarrow \pi(s)\)
if \(\text{old-action} \notin \arg\max_a \left[R(s,a) + \gamma \sum_{s'} p_T(s'|s,a) V_{\pi}(s')\right]\) then
\(\pi(s) \leftarrow\) an element of this \(\arg\max\)
\(\text{policy-stable} \leftarrow \text{false}\)
until \(\text{policy-stable} = \text{true}\)
end
In the policy iteration algorithm, starting from an initial policy, we alternate between the policy evaluation step and the
policy improvement step. Assume \(\mathcal{S}\) and \(\mathcal{A}\) are finite. There are at most
\(|\mathcal{A}|^{|\mathcal{S}|}\) deterministic policies. Suppose ties in the \(\arg\max\) are broken consistently, as the
pseudocode does by keeping the current action whenever it is among the maximizers. Then every iteration either strictly
improves the policy or leaves it unchanged, so the algorithm terminates after finitely many iterations. When the policy is
unchanged, Bellman optimality holds at every state, so the final policy is optimal. These guarantees assume exact policy
evaluation. The pseudocode stops evaluating at the threshold \(\theta\), so these arguments do not apply to it as written.
Monte Carlo Control
Having established the theoretical foundations of MDPs and dynamic programming, we now turn to model-free methods that
learn directly from experience. We begin with Monte Carlo (MC) control, a fundamental value-based method
that estimates value functions by sampling complete episodes and using actual returns. The averaging of sampled returns
is an instance of the general Monte Carlo estimator,
and, for a fixed policy, its convergence is guaranteed by
Monte Carlo consistency
(an application of the strong law of large numbers).
Monte Carlo control implements generalized policy iteration (GPI). GPI is a unifying name for
schemes that interleave policy evaluation and policy improvement at any granularity. At iteration \(k\),
with current policy \(\pi_k\), the three steps are:
- Rollout. Starting from state \(s\), take action \(a\), and sample the rest of the trajectory by following
policy \(\pi_k\) until a terminal state is reached.
- MC Q-estimate. Compute the realized return \(G_0 = \sum_{t=0}^{T-1} \gamma^t r_t\) from this rollout and
average it (over many such rollouts) into the running estimate \(Q_k(s, a)\) of \(Q_{\pi_k}(s, a)\). Steps 1 and 2 together perform
policy evaluation.
- Policy improvement. Update the policy greedily with respect to the current Q-estimate,
\[
\pi_{k+1}(s) \in \arg \max_{a} Q_k (s, a),
\]
where \(Q_k\) is the MC estimate of \(Q_{\pi_k}\) accumulated so far.
To keep exploring every action, the rollouts can follow an
\(\varepsilon\)-greedy policy built from the current Q-estimate. With a fixed
\(\varepsilon\), the method can at best find the optimal policy among \(\varepsilon\)-greedy ones. Letting \(\varepsilon\)
decay to zero while every state-action pair is still visited infinitely often (the GLIE condition discussed with SARSA below)
is a common way to target \(\pi_*\) itself.
For a fixed policy \(\pi\), the average of complete returns from rollouts started at \((s, a)\) is an
unbiased estimate of \(Q_\pi(s, a)\). However, MC methods can be inefficient for value-based RL because
they require unrolling complete trajectories whose returns are sums of random rewards generated by stochastic state
transitions. The resulting value estimates can have high variance. Moreover, MC methods are most natural
for episodic tasks (or for continuing tasks via finite-horizon truncation), since they need a complete trajectory to form
each update. This makes them unsuitable for step-by-step online updates.
These limitations motivate bootstrapping, which updates estimates from other
estimates. This sense of the word is distinct from the statistical bootstrap used in other areas of machine learning.
Temporal Difference Learning
Temporal Difference (TD) learning methods address the limitations of Monte Carlo methods through
bootstrapping. Each update uses a single transition plus the current estimate of the successor state's
value, rather than waiting for a complete return.
Theoretical Foundation
The TD target \(r_t + \gamma V(s_{t+1})\) is a single-sample approximation of the right-hand side of the
Bellman expectation equation introduced above,
\[
V_{\pi}(s) = \mathbb{E}_{\pi(a \mid s)} \left[ R(s, a) + \gamma \, \mathbb{E}_{p_T(s' \mid s, a)} \left[ V_{\pi}(s') \right] \right].
\]
The target is obtained by replacing the expectations with a single observed transition \((s_t, a_t, r_t, s_{t+1})\) drawn
from the agent's actual interaction. The TD update then adjusts the current estimate \(V(s_t)\) toward this target. This
establishes TD learning as a method for solving the Bellman equations through successive approximation, without requiring
knowledge of transition probabilities.
Under the standing assumptions, tabular TD(0), the one-step update given below, converges with probability \(1\) to the true
value function \(V_{\pi}(s)\) of the policy being followed. The result holds provided that every state is visited infinitely
often and that the step sizes \(\alpha_n(s)\) (where \(n\) counts the visits to \(s\)) satisfy the Robbins-Monro conditions
\(\sum_{n=1}^{\infty} \alpha_n(s) = \infty\) and \(\sum_{n=1}^{\infty} \alpha_n(s)^2 \lt \infty\) for every state \(s\). We
state this stochastic-approximation result without proof.
TD(0): One-Step Temporal Difference
The simplest TD method, TD(0), updates value estimates after each single step. Suppose the agent learns
the value function \(V_\pi\) for a fixed policy \(\pi\).
Given a state transition \((s_t, a_t, r_t, s_{t+1})\) where \(a_t \sim \pi(\cdot \mid s_t)\), we update the estimate \(V(s_t)\) as follows:
TD(0) Update
\[
V(s_t) \leftarrow V(s_t) + \alpha\,\delta_t
\]
where:
- \(\alpha \in (0,1]\) is the learning rate (the convergence result above uses step sizes
\(\alpha_n(s)\) that decay with the visits to each state, instead of a constant),
- \(\delta_t = r_t + \gamma V(s_{t+1}) - V(s_t)\) is the TD error,
- \(r_t + \gamma V(s_{t+1})\) is the TD target.
n-Step TD Methods
TD methods can be generalized to look ahead multiple steps. The n-step return is defined as:
\[
G_{t:t+n} = r_t + \gamma r_{t+1} + \cdots + \gamma^{n-1} r_{t+n-1} + \gamma^n V(s_{t+n}).
\]
If the episode ends at a time \(T \leq t + n\), the sum stops at \(r_{T-1}\) and the bootstrap term is dropped,
so \(G_{t:t+n} = G_t\). The corresponding n-step TD update becomes:
\[
V(s_t) \leftarrow V(s_t) + \alpha [G_{t:t+n} - V(s_t)].
\]
Varying \(n\) provides a spectrum of methods. The case \(n=1\) recovers TD(0), with target \(G_{t:t+1} = r_t + \gamma V(s_{t+1})\).
As \(n\) increases toward the episode length, the method approaches Monte Carlo behavior by using longer actual return sequences.
TD(\(\lambda\)) and \(\lambda\)-returns
Rather than using a fixed n-step lookahead, TD(\(\lambda\)) methods use a weighted average of all n-step returns.
The \(\lambda\)-return is defined as:
\[
G_t^{\lambda} = (1-\lambda) \sum_{n=1}^{\infty} \lambda^{n-1} G_{t:t+n}
\]
where \(\lambda \in [0,1]\) controls the weighting between different n-step returns.
The parameter \(\lambda\) creates a type of interpolation different from that of n-step methods:
- When \(\lambda = 0\): Only the 1-step return is used, so the method reduces to TD(0).
- When \(\lambda = 1\): For episodic tasks, \(G_t^{\lambda} \to G_t\) as \(\lambda \to 1\) by the convention above,
and \(G_t^{1}\) is taken to be \(G_t\). This gives Monte Carlo behavior.
- For \(0 \lt \lambda \lt 1\): The \(\lambda\)-return is a weighted blend that emphasizes shorter-term returns but includes
longer-term effects.
For episodic tasks with \(\lambda = 1\), the \(\lambda\)-return is the full return \(G_t\), so TD(1), defined through the
\(\lambda\)-return, is exactly Monte Carlo. TD(\(\lambda\)) is usually implemented with eligibility traces, a
backward-view mechanism (not developed on this page) that updates at every step, even in continuing tasks. With conventional
traces, these step-by-step updates match updates toward the \(\lambda\)-return only approximately, for small step sizes.
The \(\lambda\)-return provides a principled way to interpolate between the typically low-variance but biased estimates of
TD(0) and the typically high-variance but unbiased estimates of Monte Carlo methods.
Function Approximation
More generally, for function approximation where \(V_\mathbf{w}(s)\) is parameterized by weights \(\mathbf{w}\),
the TD(0) update becomes:
\[
\mathbf{w} \leftarrow \mathbf{w} + \alpha [ r_t + \gamma V_{\mathbf{w}}(s_{t+1}) - V_{\mathbf{w}}(s_t)]\nabla_{\mathbf{w}}V_{\mathbf{w}}(s_t).
\]
Note that with function approximation, TD methods may not always converge, unlike in the tabular case
under the conditions above.
Key Advantages
TD methods offer several key advantages:
- Online learning. Updates occur after each time step, enabling continuous learning without waiting for episode completion.
- Computational efficiency. No need to store or process entire episode returns.
- Lower variance. The TD(0) target typically has lower variance than the full return, at the cost of bias.
- Applicability to continuing tasks. Can learn in non-episodic environments where episodes never terminate.
TD Control Methods: Q-Learning & SARSA
The previous section used TD learning for policy evaluation (learning \(V_\pi\)). TD control algorithms
extend it to the control problem by estimating action-value functions and deriving policies from them.
Both Q-learning and SARSA are temporal difference methods that bootstrap using single-step transitions,
but they differ fundamentally in their approach to policy learning. Q-learning learns the optimal Q-function directly
(off-policy), while SARSA learns the Q-function of the policy it follows (on-policy).
SARSA (On-Policy TD Control)
The agent follows policy \(\pi\) at every step to select actions, and learns its Q-function from the resulting transitions.
Under a transition \((s, a, r, s')\), the TD update rule is:
SARSA Update
\[
Q(s, a) \leftarrow Q(s, a) + \alpha\left[r + \gamma Q(s', a') - Q(s, a)\right]
\]
where \(a' \sim \pi(\cdot \mid s')\) is the action that the agent will take in state \(s'\). This makes SARSA on-policy.
SARSA is named after the transition tuple \((s, a, r, s', a')\).
Q-Learning (Off-Policy TD Control)
Instead of the sampled next action \(a' \sim \pi(\cdot \mid s')\) in SARSA, Q-learning uses the greedy action in \(s'\):
Q-Learning Update
\[
Q(s, a) \leftarrow Q(s, a) + \alpha\left[r + \gamma \max_b Q(s', b) - Q(s, a)\right].
\]
The max operator \(\max_b Q(s', b)\) makes this off-policy.
The update targets the optimal Q-function regardless of the behavioral policy.
Key Differences
- Convergence. Under the standing assumptions, Q-learning provably converges to the optimal action-value
function \(Q_*\) in the tabular case, provided every state-action pair is visited infinitely often and, for each pair
\((s, a)\), the step sizes \(\alpha_k(s, a)\) (where \(k\) counts the visits to the pair) satisfy the Robbins-Monro
conditions. Under the same visit and step-size conditions, SARSA, viewed as pure policy evaluation, converges to \(Q_\pi\)
for the policy \(\pi\) being followed. SARSA also converges to \(Q_*\), and its greedy policy becomes optimal, when
combined with a GLIE (Greedy in the Limit with Infinite Exploration) policy. One example is
\(\varepsilon\)-greedy with \(\varepsilon\) at each state decaying as \(c/n\), where \(0 \lt c \lt 1\) and \(n\) is the
number of visits to that state.
- Policy dependence. SARSA accounts for the behavioral policy in its updates, while Q-learning's target
\(\max_b Q(s', b)\) ignores it entirely.
- Behavioral differences. In some environments, SARSA and Q-learning may learn different policies, because
SARSA takes into account the actions that the behavioral policy actually selects, while Q-learning optimizes under the
assumption of greedy action selection.
Policy Gradient Methods
Unlike value-based methods that learn value functions and derive policies implicitly,
policy-based methods directly parameterize and optimize policies without necessarily
learning value functions. These methods address fundamental limitations of value-based approaches,
particularly in continuous action spaces and when stochastic policies are desired.
Our objective is the expected return of a policy:
\[
\begin{align*}
J(\pi) &= \mathbb{E}_{p_0(s_0)}[V_{\pi}(s_0)] \\\\
&= \mathbb{E}_{p_0(s_0)\pi(a_0 \mid s_0)}[Q_{\pi}(s_0, a_0)].
\end{align*}
\]
Let \(\pi_{\boldsymbol{\theta}}\) be parameterized by \(\boldsymbol{\theta}\). Differentiating the objective with
respect to \(\boldsymbol{\theta}\) gives
\[
\begin{align*}
\nabla_{\boldsymbol{\theta}} J(\pi_{\boldsymbol{\theta}})
&= \mathbb{E}_{p_0(s_0)} \left[\nabla_{\boldsymbol{\theta}} \left(\sum_{a_0}\pi_{\boldsymbol{\theta}}(a_0 \mid s_0)Q_{\pi_{\boldsymbol{\theta}}}(s_0, a_0) \right) \right] \\\\
&= \mathbb{E}_{p_0(s_0)} \left[\sum_{a_0} \nabla_{\boldsymbol{\theta}} \pi_{\boldsymbol{\theta}}(a_0 \mid s_0)Q_{\pi_{\boldsymbol{\theta}}}(s_0, a_0) \right]
+ \mathbb{E}_{p_0(s_0)\pi_{\boldsymbol{\theta}}(a_0 \mid s_0)} [\nabla_{\boldsymbol{\theta}}Q_{\pi_{\boldsymbol{\theta}}}(s_0, a_0)].
\end{align*}
\]
Here, since \(R(s_0, a_0)\) does not depend on \(\boldsymbol{\theta}\), we have
\[
\begin{align*}
\nabla_{\boldsymbol{\theta}}Q_{\pi_{\boldsymbol{\theta}}}(s_0, a_0)
&= \nabla_{\boldsymbol{\theta}}\left[R(s_0, a_0) + \gamma \mathbb{E}_{p_T(s_1 \mid s_0, a_0)} [V_{\pi_{\boldsymbol{\theta}}}(s_1)]\right] \\\\
&= \gamma \nabla_{\boldsymbol{\theta}} \mathbb{E}_{p_T(s_1 \mid s_0, a_0)} [V_{\pi_{\boldsymbol{\theta}}}(s_1)].
\end{align*}
\]
We sketch the remaining step. Substituting this back, we unroll the recursion across all timesteps. Each level of
recursion contributes a factor of \(\gamma\) and shifts the state distribution one step forward under
\(\pi_{\boldsymbol{\theta}}\). Collapsing the resulting infinite sum with the discounted state-visitation distribution
\(p_{\pi_{\boldsymbol{\theta}}}^\infty\), we obtain the policy gradient theorem:
Theorem: Policy Gradient Theorem
Let \(\mathcal{S}\) and \(\mathcal{A}\) be finite, let the rewards be bounded and \(\gamma \in [0, 1)\), and let
\(\pi_{\boldsymbol{\theta}}(a \mid s)\) be positive and differentiable in \(\boldsymbol{\theta}\) for every \((s, a)\).
Then the gradient of the expected return is:
\[
\begin{align*}
\nabla_{\boldsymbol{\theta}}J(\pi_{\boldsymbol{\theta}})
&= \sum_{t = 0}^{\infty} \gamma^t \mathbb{E}_{p_t(s)} \left[\sum_a \nabla_{\boldsymbol{\theta}}\pi_{\boldsymbol{\theta}}(a \mid s) Q_{\pi_{\boldsymbol{\theta}}}(s, a)\right] \\\\
&= \frac{1}{1 -\gamma} \mathbb{E}_{p_{\pi_{\boldsymbol{\theta}}}^{\infty}(s)} \left[ \sum_a \nabla_{\boldsymbol{\theta}}\pi_{\boldsymbol{\theta}}(a \mid s) Q_{\pi_{\boldsymbol{\theta}}}(s, a) \right] \\\\
&= \frac{1}{1 -\gamma} \mathbb{E}_{p_{\pi_{\boldsymbol{\theta}}}^{\infty}(s) \pi_{\boldsymbol{\theta}}(a \mid s)} \left[ \nabla_{\boldsymbol{\theta}} \log \pi_{\boldsymbol{\theta}}(a \mid s) Q_{\pi_{\boldsymbol{\theta}}}(s, a) \right]
\end{align*}
\]
where \(p_t(s)\) is the probability of visiting state \(s\) at time \(t\) if the agent starts from \(s_0 \sim p_0\) and follows \(\pi_{\boldsymbol{\theta}}\), and
\[
p_{\pi_{\boldsymbol{\theta}}}^\infty(s) = (1-\gamma)\sum_{t=0}^{\infty}\gamma^t p_t(s)
\]
is the normalized discounted state visitation distribution.
The third equality uses the log-derivative trick
\(\nabla_{\boldsymbol{\theta}} \pi_{\boldsymbol{\theta}}(a \mid s) = \pi_{\boldsymbol{\theta}}(a \mid s) \nabla_{\boldsymbol{\theta}} \log \pi_{\boldsymbol{\theta}}(a \mid s)\).
The trick converts the gradient of a probability into an expectation under that probability. The quantity
\(\nabla_{\boldsymbol{\theta}} \log \pi_{\boldsymbol{\theta}}(a \mid s)\) is precisely the conditional
score function
of the policy distribution. This identification makes the policy gradient an instance of score-function estimation.
The theorem is stated for finite \(\mathcal{A}\), where the inner sums range over actions. For a continuous
action space the sums become integrals against a policy density, and the same identity holds under
integrability and differentiability conditions that we do not develop here.
To reduce the high variance of policy-gradient estimates, we can subtract a state-dependent baseline \(b(s)\)
from \(Q_{\pi_{\boldsymbol{\theta}}}(s, a)\) inside the expectation. A key invariance property is that this subtraction does not change the gradient in expectation,
because \(\mathbb{E}_{a \sim \pi_{\boldsymbol{\theta}}(\cdot \mid s)}[\nabla_{\boldsymbol{\theta}} \log \pi_{\boldsymbol{\theta}}(a \mid s)] = \mathbf{0}\) for any \(s\),
so the baseline term integrates to zero. The policy gradient theorem then becomes:
\[
\nabla_{\boldsymbol{\theta}}J(\pi_{\boldsymbol{\theta}})
= \frac{1}{1 -\gamma} \mathbb{E}_{p_{\pi_{\boldsymbol{\theta}}}^{\infty}(s) \pi_{\boldsymbol{\theta}}(a \mid s)} \left[ \nabla_{\boldsymbol{\theta}} \log \pi_{\boldsymbol{\theta}}(a \mid s) (Q_{\pi_{\boldsymbol{\theta}}}(s, a) - b(s)) \right].
\]
A common choice is \(b(s) = V_{\pi_{\boldsymbol{\theta}}}(s)\), which makes the multiplier the
advantage function
\(A_{\pi_{\boldsymbol{\theta}}}(s, a) = Q_{\pi_{\boldsymbol{\theta}}}(s, a) - V_{\pi_{\boldsymbol{\theta}}}(s)\).
Intuitively, this re-centers each action's value relative to the policy's average performance at that state.
In practice this choice often reduces variance substantially, although \(V_{\pi_{\boldsymbol{\theta}}}\) is not in
general the variance-minimizing baseline.
REINFORCE is the fundamental policy gradient algorithm that uses Monte Carlo estimation:
\[
\begin{align*}
\nabla_{\boldsymbol{\theta}} J(\pi_{\boldsymbol{\theta}})
&= \frac{1}{1 -\gamma} \mathbb{E}_{p_{\pi_{\boldsymbol{\theta}}}^{\infty}(s) \pi_{\boldsymbol{\theta}}(a \mid s)} \left[ \nabla_{\boldsymbol{\theta}} \log \pi_{\boldsymbol{\theta}}(a \mid s) Q_{\pi_{\boldsymbol{\theta}}}(s, a) \right]\\\\
&\approx \sum_{t=0}^{T-1} \gamma^t G_t \nabla_{\boldsymbol{\theta}} \log \pi_{\boldsymbol{\theta}}(a_t \mid s_t)
\end{align*}
\]
where \(G_t\) is the return from time \(t\):
\[
G_t = r_t + \gamma r_{t+1} + \gamma^2 r_{t+2} + \cdots + \gamma^{T-t-1} r_{T-1}.
\]
The factor \(\gamma^t\) comes from the discount on the state at time \(t\) in \(p_{\pi_{\boldsymbol{\theta}}}^\infty\).
Using a baseline in the gradient estimate, we obtain the REINFORCE update rule:
\[
\boldsymbol{\theta} \leftarrow \boldsymbol{\theta} + \alpha \sum_{t = 0}^{T -1} \gamma^t (G_t - b(s_t)) \nabla_{\boldsymbol{\theta}} \log \pi_{\boldsymbol{\theta}} (a_t \mid s_t).
\]
REINFORCE (with baseline)
begin
Set initial policy parameters \(\boldsymbol{\theta}\), and baseline parameters \(\mathbf{w}\)
repeat:
Sample an episode \(\boldsymbol{\tau} = (s_0, a_0, r_0, s_1, \ldots, s_T)\) using the policy \(\pi_{\boldsymbol{\theta}}\)
Compute \(G_t\) for all \(t \in \{0, 1, \ldots, T-1\}\)
for \(t = 0, 1, \ldots, T-1\) do
\(\delta = G_t - V_\mathbf{w}(s_t)\)
\(\mathbf{w} \leftarrow \mathbf{w} + \alpha_{\mathbf{w}} \delta \nabla_{\mathbf{w}}V_{\mathbf{w}}(s_t)\)
\(\boldsymbol{\theta} \leftarrow \boldsymbol{\theta} + \alpha_{\boldsymbol{\theta}} \gamma^t \delta \nabla_{\boldsymbol{\theta}} \log \pi_{\boldsymbol{\theta}}(a_t \mid s_t) \)
until converged
end
Actor-Critic Methods
Actor-critic methods are hybrid algorithms that combine both policy-based and value-based approaches
to address the high variance problem of pure policy gradient methods like REINFORCE. These methods maintain
two separate function approximators that work together:
- Actor \(\pi_{\boldsymbol{\theta}}(a \mid s)\): A parameterized policy that selects actions, where \(\boldsymbol{\theta}\) are the policy parameters.
- Critic \(V_{\mathbf{w}}(s)\): In the methods below, a parameterized state-value function that evaluates states, where \(\mathbf{w}\) are the value function parameters.
The actor updates the policy parameters \(\boldsymbol{\theta}\) using gradients weighted by the advantage estimates
provided by the critic, while the critic updates the value function parameters \(\mathbf{w}\) to more accurately
estimate expected returns through temporal difference learning.
Consider the use of the one-step TD(0) method to estimate the return in the episodic case.
Specifically, we replace the Monte Carlo return \(G_t\) (used in REINFORCE) with the 1-step TD target
\[
G_{t:t+1} = r_t + \gamma V_{\mathbf{w}} (s_{t+1}),
\]
and use \(V_{\mathbf{w}}(s_t)\) as the baseline. The REINFORCE update from the previous section then becomes:
\[
\boldsymbol{\theta} \leftarrow \boldsymbol{\theta} + \alpha \sum_{t=0}^{T-1} \gamma^t (G_{t:t+1} - V_{\mathbf{w}}(s_t))\nabla_{\boldsymbol{\theta}} \log \pi_{\boldsymbol{\theta}}(a_t \mid s_t).
\]
Here, the TD error \(r_t + \gamma V_{\mathbf{w}}(s_{t+1}) - V_{\mathbf{w}}(s_t)\), which multiplies
\(\gamma^t \nabla_{\boldsymbol{\theta}} \log \pi_{\boldsymbol{\theta}}(a_t \mid s_t)\) above, is a single-sample
approximation to the advantage function
\[
A_{\pi_{\boldsymbol{\theta}}}(s_t, a_t) = Q_{\pi_{\boldsymbol{\theta}}}(s_t, a_t) - V_{\pi_{\boldsymbol{\theta}}}(s_t),
\]
and its conditional expectation given \((s_t, a_t)\) equals this advantage when \(V_{\mathbf{w}} = V_{\pi_{\boldsymbol{\theta}}}\).
This method is therefore called the advantage actor-critic (or A2C).
A2C (Advantage Actor-Critic)
begin
Set initial actor parameters \(\boldsymbol{\theta}\), and critic parameters \(\mathbf{w}\)
repeat:
Sample starting state \(s_0\) of a new episode
for \(t = 0, 1, \ldots\) do
Sample action \(a_t \sim \pi_{\boldsymbol{\theta}}(\cdot \mid s_t)\)
Observe next state \(s_{t+1}\) and reward \(r_t\)
\(\delta = r_t + \gamma V_\mathbf{w}(s_{t+1}) - V_\mathbf{w}(s_t)\), with \(V_\mathbf{w}(s_{t+1})\) replaced by \(0\) if \(s_{t+1}\) is terminal
\(\mathbf{w} \leftarrow \mathbf{w} + \alpha_{\mathbf{w}} \delta \nabla_{\mathbf{w}}V_{\mathbf{w}}(s_t)\)
\(\boldsymbol{\theta} \leftarrow \boldsymbol{\theta} + \alpha_{\boldsymbol{\theta}} \gamma^t \delta \nabla_{\boldsymbol{\theta}} \log \pi_{\boldsymbol{\theta}}(a_t \mid s_t) \)
if \(s_{t+1}\) is terminal then end the episode
until converged
end
Note that the n-step advantage estimate can be expressed as:
\[
A_{\pi_{\boldsymbol{\theta}}}^{(n)}(s_t, a_t) = G_{t:t+n} - V_{\mathbf{w}}(s_t)
\]
where
\[
G_{t:t+n} = r_t + \gamma r_{t+1} + \gamma^2 r_{t+2} + \cdots + \gamma^{n-1} r_{t+n-1} + \gamma^n V_{\mathbf{w}}(s_{t+n}).
\]
We can control the bias-variance tradeoff by adjusting \(n\).
Actor-critic methods have three main advantages:
- Reduced variance. Typically lower variance than REINFORCE, because the bootstrapped TD target replaces the Monte Carlo return, at the cost of bias.
- Sample efficiency. Often more sample-efficient than Monte Carlo methods, through bootstrapping.
- Broad applicability. Can handle both discrete and continuous action spaces with online learning capability.
Among the many actor-critic methods developed in the deep reinforcement learning literature,
Proximal Policy Optimization (PPO) deserves special mention. PPO clips the probability ratio between the new
and old policies in its surrogate objective, which discourages updates that move far from the old policy. This first-order
substitute for the trust region of TRPO is simple to implement. PPO became a standard baseline in continuous-control
benchmarks and was the reinforcement-learning algorithm used in the original RLHF pipelines for large language models.