Policy Evaluation as Linear Algebra
The matrix (I − γP)⁻¹, the Neumann series and conditioning as γ → 1.
Policy evaluation is a linear solve, so numerical linear algebra has a lot to say about it. The inverse is a sum over time that counts discounted visits; its condition number grows like the effective horizon; classical splittings explain exactly why in-place sweeps beat synchronous ones; Krylov methods can beat both, or not at all; and perturbation theory prices a wrong model. This lesson proves each of these statements.
What you’ll learn
- Prove that is invertible for every stochastic matrix , expand the inverse as a Neumann series, and show that is a stochastic matrix of discounted occupancies.
- Locate the spectrum of and prove , with the case of equality.
- Compare Richardson, Jacobi and Gauss–Seidel splittings of policy evaluation with the theory of regular splittings, and explain when Krylov solvers help.
- Derive an exact identity for the value error caused by a wrong model, and bound it in the max norm and through the span of the values.
The inverse as a sum over time
Throughout, is the transition matrix of a fixed policy (row-stochastic: nonnegative entries, rows summing to 1), its reward vector, , and its value. Write ; numerical analysts call it a resolvent of .
gives the eigenvalue 1, and any eigenvalue satisfies . For the partial sums the product telescopes, and the remainder vanishes because :
Every term is nonnegative and the term is , so . Each is stochastic, so and the row sums of are a geometric series. For a nonnegative matrix the max norm is the largest row sum:
for the Markov chain of the policy. Summing with weights and exchanging sum and expectation (all terms are nonnegative) gives the visit count:
So splits a value into where you will go () and what you will find there (). The rows of are Dayan's (1993) successor representation, and is an expectation under the discounted state distribution, the object behind policy gradients and the linear-programming dual (Successor Representations & Features, Occupancy Measures & the Dual View).
In the two-state world under (go, stay) with , and , so and . From , a tenth of the discounted time is spent in (only the first step) and nine tenths in .
Under (stay, go) in the two-state world (), the agent moves from to and then stays in forever. What is , the share of the normalized discounted occupancy from that falls on ?
- 0.9
- 0.5
- 0
- 0.1
Show the answer
D. 0.1
is visited only at , so and . The remaining 0.9 falls on , which is occupied at every step : .
Conditioning as γ → 1
Spectrum. If then , and . The eigenvalue of , with , gives , the smallest possible modulus in the disc.
Norm. Row of has diagonal entry and off-diagonal entries , so its absolute row sum is
The maximum over is attained where is smallest. Multiply by from the previous theorem. Perturbation: gives the absolute bound, and turns it into the relative one.
Some state has no self-transition. What is at ?
Show the answer
199
. In the two-state world under (go, stay) at , has max norm 1.9 and inverse norm 10, so , exactly , because has no self-loop under go.
The ill-conditioned direction is the constant vector , the eigenvector of the eigenvalue . A constant shift changes every state's value equally and never changes which action is greedy, which is why algorithms that track values only up to a constant, such as relative value iteration, can escape the blow-up (Average-Reward Dynamic Programming). Note also that the theorem's bounds are worst cases over all perturbations: errors that are nearly constant across states cost much less in decisions than their size suggests.
Splittings: why in-place sweeps win
Write and split into its strictly lower triangular, diagonal and strictly upper triangular parts (for a chosen ordering of the states). Any splitting with easy to invert gives the iteration , which converges from every start exactly when . The sweeps of policy evaluation are four such splittings:
| Method | As a sweep | ||
|---|---|---|---|
| Richardson | synchronous iterative policy evaluation | ||
| Jacobi | synchronous, but each state's self-transition is solved exactly | ||
| In-place sweep | in-place evaluation in the chosen order | ||
| Gauss–Seidel | in place, with each self-transition solved exactly |
. Each in the table is with lower triangular or diagonal and , so ; and every is nonnegative. All four splittings are regular.
The 's are ordered entrywise, so the spectral radii are ordered the same way. Richardson's is exactly :
The monotonicity behind it: grows entrywise with because , the Perron root of a nonnegative matrix is monotone in its entries, and is increasing. Without self-transitions the Stein–Rosenberg theorem even gives strict inequality, . These are asymptotic rates; the worst-case contraction of one sweep in the max norm stays for every order, as Policy Evaluation proved.
Krylov methods. GMRES chooses in the Krylov space spanned by to minimize the residual, so the residual is for the best polynomial of degree with . For a diagonalizable with eigenvector matrix ,
On the whole disc the min–max equals , attained by , which is Richardson's polynomial: if the spectrum of fills the unit disc, no Krylov method beats plain sweeps by much. When it is clustered, as for chains that mix quickly apart from a few slow modes, GMRES converges in a handful of iterations. Transition matrices are usually far from normal, so can make the bound weak; in practice one tries a Krylov solver and measures.
import scipy.sparse as sp
from scipy.sparse.linalg import gmres
def evaluate_gmres(P_pi, r_pi, gamma):
"""P_pi: sparse S x S transition matrix of the policy; r_pi: rewards."""
A = sp.identity(P_pi.shape[0], format='csr') - gamma * P_pi
V, info = gmres(A, r_pi, restart=50, maxiter=1000)
if info != 0:
raise RuntimeError('GMRES did not reach its tolerance')
return VEach GMRES iteration costs one sparse matrix–vector product, the same as one sweep, plus orthogonalization against up to restart stored vectors.
What a wrong model costs
Subtract the two Bellman equations, and , and add and subtract :
Invert, using for the stochastic matrix . For the span bound, the zero row sums let you subtract any constant from ; take the midpoint :
Finally gives . One factor comes from the size of the values, the other from accumulating the error over the effective horizon: the simulation lemma in its tabular form.
Example. Evaluate (go, stay), at , in a wrong model where stay in slips back to with probability . Then and .
- The crude bound, with , gives .
- The span bound, with , gives .
- The truth: , an error of 1.65.
A model error that moves probability between states of similar value costs little; what matters is applied to , weighted by how often the policy visits the affected states. That observation is the starting point of value-aware model learning in Model-Based RL: Learning to Plan.
Key takeaways
- counts expected discounted visits; scaled by it is a stochastic matrix of discounted occupancies, and is an expectation under them.
- The spectrum of lies in the disc , and , with equality when some state has no self-loop. The bad direction is the constant vector, which never changes a greedy decision.
- Synchronous and in-place sweeps are Richardson, Jacobi and Gauss–Seidel splittings; all are regular, and the comparison theorem orders their asymptotic rates, all at most . Krylov methods help when the spectrum is clustered, not on a spectrum that fills the disc.
- A wrong model changes the value by exactly : the error depends on the span of and grows like at worst.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Which statement about is true for every stochastic and ?
- is symmetric
- Each row of sums to 1
- is the expected discounted number of visits to starting from
- can have negative entries when has zero entries
Show the answer
C. is the expected discounted number of visits to starting from
, and is the probability of being in at time . Every term is nonnegative, the rows sum to , and is the stochastic matrix of normalized discounted occupancies.
In a chain where some state has no self-transition, for which discount is ?
Show the answer
B.
Solve : , so . The condition number roughly doubles the effective horizon .
For a fixed policy and , what does the comparison of regular splittings guarantee about in-place sweeps?
- Their asymptotic rate is at most , the synchronous rate, whatever the order of the states
- They need fewer sweeps than synchronous evaluation from every starting point
- They are faster only if the states are swept in reverse order
- Jacobi always beats Gauss–Seidel
Show the answer
A. Their asymptotic rate is at most , the synchronous rate, whatever the order of the states
The in-place splitting has , so its spectral radius is at most Richardson's, , for any ordering; Gauss–Seidel's is smaller still. These are asymptotic statements: they do not promise fewer sweeps from every start, and the best ordering depends on the problem.
A model moves probability 0.05 of one transition to a wrong next state, so for one and 0 elsewhere. All values lie between 9 and 10, rewards are exact, and . What does the span bound give for ?
- 0.05
- 4.5
- 0.45
- 9
Show the answer
C. 0.45
, and the error is at most . The crude bound with would give .
Further reading
- M. L. Puterman, Markov Decision Processes: Discrete Stochastic Dynamic Programming, ch. 6 (Wiley, 1994).
- R. S. Varga, Matrix Iterative Analysis (Springer, 2nd ed., 2000).
- Y. Saad, Iterative Methods for Sparse Linear Systems (SIAM, 2nd ed., 2003).
- P. Dayan, "Improving generalization for temporal difference learning: the successor representation," Neural Computation 5(4), 613–624 (1993).
- M. Kearns & S. Singh, "Near-optimal reinforcement learning in polynomial time," Machine Learning 49, 209–232 (2002).