Core idea. Policy evaluation asks a precise mathematical question: if the agent follows a fixed policy \(\pi\), what is the long-run value of each state? Once the policy is fixed, the control problem disappears. The Markov decision process becomes a Markov reward process, and the value function is the unique fixed point of a linear Bellman operator.
For a finite discounted MDP, policy evaluation is the problem of computing
be a finite discounted Markov decision process. Here \(\mathcal S\) is the state space, \(\mathcal A(s)\) is the set of admissible actions in state \(s\), \(P(s'\mid s,a)\) is the transition law, \(r(s,a)\) is the expected one-step reward, and \(0\leq \gamma<1\) is the discount factor.
A stationary randomized policy is a collection of probability distributions
Policy evaluation asks for the value of following this fixed policy. The state-value function is
\[
V^\pi(s)=\mathbb E_\pi[G_0\mid S_0=s],
\]
where
\[
G_0=R_1+\gamma R_2+\gamma^2R_3+\cdots.
\]
The key phrase is fixed policy. We are not yet trying to improve the policy. We are only measuring it.
Policy evaluation is the mathematical bridge between Markov reward processes and control. It is also the inner subroutine of policy iteration, actor-critic methods, approximate dynamic programming, and many modern reinforcement learning algorithms.
9.3 6.2 From an MDP and a policy to an MRP
Once the policy \(\pi\) is fixed, the agent’s action randomness is absorbed into the transition and reward model. Define the policy-induced transition matrix
This formula has a direct probabilistic meaning: \(P_\pi^t r_\pi\) is the expected reward \(t\) steps in the future under policy \(\pi\), and \(\gamma^t\) discounts that future contribution.
Review 30.599306
Practice 36.976881
Mastery 41.624929
Name: V_exact, dtype: float64
The values are large because \(\gamma=0.90\) means the agent cares about many future rewards. The effective horizon is roughly
\[
\frac{1}{1-\gamma}=10.
\]
9.5.2 Interactive: exact values for different policies and discount factors
The interactive below shows how \(V^\pi\) changes when the policy becomes more likely to choose the Challenge action and when the discount factor changes.
Thus \(T^\pi\) is a contraction under the sup norm.
The contraction proof is one of the cleanest mathematical arguments in discounted reinforcement learning. It gives existence, uniqueness, and convergence of iterative algorithms in one step through the Banach fixed point theorem.
9.7 6.6 Iterative policy evaluation
Instead of solving a linear system directly, we can use the fixed-point iteration
This often converges faster in practice because new information is propagated immediately.
An asynchronous update only updates selected states at each step. Under appropriate conditions, if every state is updated infinitely often and \(0\leq\gamma<1\), asynchronous policy evaluation still converges to \(V^\pi\).
9.8.1 Python example: Jacobi vs Gauss-Seidel
def jacobi_evaluation(P, r, gamma, num_sweeps=30): V = np.zeros_like(r, dtype=float) residuals = []for _ inrange(num_sweeps): V_new = r + gamma * P @ V residuals.append(np.max(np.abs(V_new - V_exact))) V = V_newreturn np.array(residuals)def gauss_seidel_evaluation(P, r, gamma, num_sweeps=30): V = np.zeros_like(r, dtype=float) residuals = [] n =len(r)for _ inrange(num_sweeps):for i inrange(n): V[i] = r[i] + gamma * P[i, :] @ V residuals.append(np.max(np.abs(V - V_exact)))return np.array(residuals)comparison = pd.DataFrame({"sweep": np.arange(1, 31),"Jacobi error": jacobi_evaluation(P_pi, r_pi, gamma),"Gauss-Seidel error": gauss_seidel_evaluation(P_pi, r_pi, gamma)})comparison.head()
sweep
Jacobi error
Gauss-Seidel error
0
1
35.724929
35.052352
1
2
31.278479
30.028823
2
3
27.699784
26.161008
3
4
24.694373
23.312094
4
5
22.101288
20.870528
9.8.2 Interactive: residual decay under different update schedules
If \(\bar r(s)\) is the sample average reward following visits to state \(s\), then the plug-in value estimator is
\[
\widehat V=(I-\gamma \widehat P_\pi)^{-1}\widehat r.
\]
This estimator is intuitive, but it is nonlinear in \(\widehat P_\pi\). Estimation error in \(\widehat P_\pi\) can be amplified when \(\gamma\) is close to one, because the inverse \((I-\gamma P_\pi)^{-1}\) becomes more sensitive.
In finite problems, model-based plug-in evaluation may be statistically efficient when enough data are available for every state. In large problems, rare states and function approximation become central. Later chapters replace the table \(V(s)\) by an approximating family \(V_\theta(s)\).
9.12 6.11 A preview of approximate policy evaluation
In large state spaces, storing one value per state is impossible. We may approximate the value function by
\[
V_\theta(s)=\phi(s)^T\theta,
\]
where \(\phi(s)\in\mathbb R^d\) is a feature vector. A common statistical target is the weighted least-squares projection
where \(d_\pi\) is a state weighting distribution, often related to the stationary or discounted occupancy distribution under \(\pi\).
This leads to projected Bellman equations and stochastic approximation algorithms. These topics are developed in detail in Chapter 13 on function approximation and Chapter 14 on stochastic approximation.
9.13 6.12 AI-assisted learning components
Modern AI tools can be helpful in this chapter, but they should be used as mathematical assistants rather than as black boxes.
AI prompt: checking a Bellman equation
Give an AI system a finite policy-induced transition matrix \(P_\pi\), reward vector \(r_\pi\), and discount factor \(\gamma\). Ask it to:
write the Bellman expectation equation in scalar form;
write the same equation in matrix form;
check whether each row of \(P_\pi\) sums to one;
solve the linear system;
verify the solution by computing the Bellman residual.
Then independently verify the output in Python.
AI prompt: debugging iterative policy evaluation
Paste a short implementation of iterative policy evaluation and ask:
Find any mathematical or programming mistakes. In particular, check whether the update uses the old value vector or accidentally mixes old and new values. Also check whether the stopping rule controls the Bellman residual or only the change between iterates.
This prompt helps students distinguish Jacobi, Gauss-Seidel, and residual-based stopping criteria.
AI prompt: explaining assumptions
Ask:
In discounted finite-state policy evaluation, why does \(0\leq\gamma<1\) guarantee a unique value function? Which parts of the proof fail if \(\gamma=1\)?
The expected answer should mention contraction, invertibility of \(I-\gamma P_\pi\), and the need for additional recurrence or average-reward assumptions in the undiscounted case.
9.14 6.13 Summary
Policy evaluation is one of the foundational problems in reinforcement learning.
A fixed policy \(\pi\) turns an MDP into an MRP with transition matrix \(P_\pi\) and reward vector \(r_\pi\).
The value function satisfies
\[
V^\pi=r_\pi+\gamma P_\pi V^\pi.
\]
In finite discounted problems,
\[
V^\pi=(I-\gamma P_\pi)^{-1}r_\pi.
\]
The Bellman expectation operator is a contraction:
Implement iterative policy evaluation for the study-planning MDP using \(\gamma=0.50,0.80,0.90,0.97\). Compare the number of iterations required for a fixed tolerance.
Implement Gauss-Seidel policy evaluation and compare it with Jacobi iteration.
Simulate trajectories under the fixed policy and estimate \(V^\pi\) using first-visit Monte Carlo.
Implement TD(0) for the same policy. Compare different learning rates.
Estimate \(\widehat P_\pi\) and \(\widehat r_\pi\) from simulated data, then compute the plug-in value estimate. Repeat the experiment many times and estimate the sampling distribution of \(\widehat V(s)\).
9.15.4 AI-assisted exercises
Ask an AI system to derive the Bellman expectation equation from the return identity \(G_t=R_{t+1}+\gamma G_{t+1}\). Check every conditional expectation step manually.
Ask an AI system to generate a small four-state policy-induced Markov reward process. Verify that the transition matrix is stochastic and compute the value function in Python.
Ask an AI system to explain why TD(0) is called a bootstrapping method. Compare the explanation with the update formula.
Ask an AI system to create a bug in policy evaluation code. Then identify and fix the bug.
Ask an AI system to compare direct linear algebra, iterative dynamic programming, and sample-based TD evaluation for large state spaces. Identify which statements are mathematical facts and which are practical heuristics.
9.16 Notes for instructors
This chapter is a good place to slow down and emphasize mathematical structure. For MA Applied Math students, focus on fixed points, contractions, linear systems, and iterative methods. For MS Statistics students, emphasize conditional expectations, Monte Carlo estimation, plug-in estimators, sampling variability, and the statistical meaning of the TD error.
A useful lecture sequence is:
derive \(P_\pi\) and \(r_\pi\);
solve \(V^\pi=(I-\gamma P_\pi)^{-1}r_\pi\);
prove contraction;
implement iterative policy evaluation;
compare exact, iterative, Monte Carlo, and TD estimates.