Simple Algorithm
Reinforcement Learning · Fixed Point · 26 min

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 (I−γPπ)−1(I-\gamma P^\pi)^{-1} 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 I−γPI-\gamma P is invertible for every stochastic matrix PP, expand the inverse as a Neumann series, and show that (1−γ)(I−γP)−1(1-\gamma)(I-\gamma P)^{-1} is a stochastic matrix of discounted occupancies.
  • Locate the spectrum of I−γPI-\gamma P and prove κ∞(I−γP)≤(1+γ)/(1−γ)\kappa_\infty(I-\gamma P)\le(1+\gamma)/(1-\gamma), 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, PP is the transition matrix of a fixed policy (row-stochastic: nonnegative entries, rows summing to 1), rr its reward vector, γ∈[0,1)\gamma\in[0,1), and V=(I−γP)−1rV=(I-\gamma P)^{-1}r its value. Write M=(I−γP)−1M=(I-\gamma P)^{-1}; numerical analysts call it a resolvent of PP.

DerivationProof
  1. (I−γP) Sn=I−γn+1Pn+1 → n→∞  I⟹M=∑t≥0γtPt(I-\gamma P)\,S_n=I-\gamma^{n+1}P^{n+1}\ \xrightarrow{\ n\to\infty\ }\ I\qquad\Longrightarrow\qquad M=\sum_{t\ge0}\gamma^tP^t

    P1=1P\mathbf 1=\mathbf 1 gives the eigenvalue 1, and any eigenvalue satisfies ∣λ∣≤∥P∥∞=1\abs{\lambda}\le\norm{P}_\infty=1. For the partial sums Sn=∑t=0nγtPtS_n=\sum_{t=0}^n\gamma^tP^t the product telescopes, and the remainder vanishes because ∥Pn+1∥∞=1\norm{P^{n+1}}_\infty=1:

  2. M1=∑t≥0γt 1=11−γ 1,∥M∥∞=11−γM\mathbf 1=\sum_{t\ge0}\gamma^t\,\mathbf 1=\frac{1}{1-\gamma}\,\mathbf 1,\qquad\norm{M}_\infty=\frac{1}{1-\gamma}

    Every term is nonnegative and the t=0t=0 term is II, so M≥IM\ge I. Each PtP^t is stochastic, so Pt1=1P^t\mathbf 1=\mathbf 1 and the row sums of MM are a geometric series. For a nonnegative matrix the max norm is the largest row sum:

  3. M(s,s′)=∑t≥0γtPr⁡(St=s′∣S0=s)=E[∑t≥0γt 1{St=s′} ∣ S0=s]M(s,s')=\sum_{t\ge0}\gamma^t\Pr(S_t=s'\mid S_0=s)=\E\Big[\sum_{t\ge0}\gamma^t\,\mathbf 1\{S_t=s'\}\ \Big|\ S_0=s\Big]

    Pt(s,s′)=Pr⁡(St=s′∣S0=s)P^t(s,s')=\Pr(S_t=s'\mid S_0=s) for the Markov chain of the policy. Summing with weights γt\gamma^t and exchanging sum and expectation (all terms are nonnegative) gives the visit count:

So V=MrV=Mr splits a value into where you will go (MM) and what you will find there (rr). The rows of MM are Dayan's (1993) successor representation, and V(s)=11−γ∑s′D(s,s′) r(s′)V(s)=\frac{1}{1-\gamma}\sum_{s'}D(s,s')\,r(s') 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 γ=0.9\gamma=0.9, P=(0101)P=\begin{pmatrix}0&1\\0&1\end{pmatrix} and r=(0,2)r=(0,2), so M=(19010)M=\begin{pmatrix}1&9\\0&10\end{pmatrix} and V=Mr=(18,20)V=Mr=(18,20). From s1s_1, a tenth of the discounted time is spent in s1s_1 (only the first step) and nine tenths in s2s_2.

Check your understanding

Under (stay, go) in the two-state world (γ=0.9\gamma=0.9), the agent moves from s2s_2 to s1s_1 and then stays in s1s_1 forever. What is D(s2,s2)D(s_2,s_2), the share of the normalized discounted occupancy from s2s_2 that falls on s2s_2?

  1. 0.9
  2. 0.5
  3. 0
  4. 0.1
Show the answer

D. 0.1

s2s_2 is visited only at t=0t=0, so M(s2,s2)=1M(s_2,s_2)=1 and D(s2,s2)=(1−γ)⋅1=0.1D(s_2,s_2)=(1-\gamma)\cdot1=0.1. The remaining 0.9 falls on s1s_1, which is occupied at every step t≥1t\ge1: (1−γ)∑t≥1γt=γ(1-\gamma)\sum_{t\ge1}\gamma^t=\gamma.

Conditioning as γ → 1

DerivationProof
  1. Spectrum. If Px=λxPx=\lambda x then (I−γP)x=(1−γλ)x(I-\gamma P)x=(1-\gamma\lambda)x, and ∣(1−γλ)−1∣=γ∣λ∣≤γ\abs{(1-\gamma\lambda)-1}=\gamma\abs\lambda\le\gamma. The eigenvalue λ=1\lambda=1 of PP, with x=1x=\mathbf 1, gives 1−γ1-\gamma, the smallest possible modulus in the disc.

  2. (1−γP(s,s))+γ(1−P(s,s))=1+γ−2γP(s,s)\big(1-\gamma P(s,s)\big)+\gamma\big(1-P(s,s)\big)=1+\gamma-2\gamma P(s,s)

    Norm. Row ss of I−γPI-\gamma P has diagonal entry 1−γP(s,s)≥01-\gamma P(s,s)\ge0 and off-diagonal entries −γP(s,s′)-\gamma P(s,s'), so its absolute row sum is

  3. The maximum over ss is attained where P(s,s)P(s,s) is smallest. Multiply by ∥M∥∞=1/(1−γ)\norm{M}_\infty=1/(1-\gamma) from the previous theorem. Perturbation: δV=M δr\delta V=M\,\delta r gives the absolute bound, and ∥r∥∞≤∥I−γP∥∞∥V∥∞\norm{r}_\infty\le\norm{I-\gamma P}_\infty\norm{V}_\infty turns it into the relative one.

Predict before you look

Some state has no self-transition. What is κ∞(I−γP)\kappa_\infty(I-\gamma P) at γ=0.99\gamma=0.99?

Show the answer

199

(1+0.99)/(1−0.99)=1.99/0.01=199(1+0.99)/(1-0.99)=1.99/0.01=199. In the two-state world under (go, stay) at γ=0.9\gamma=0.9, I−γP=(1−0.900.1)I-\gamma P=\begin{pmatrix}1&-0.9\\0&0.1\end{pmatrix} has max norm 1.9 and inverse norm 10, so κ∞=19\kappa_\infty=19, exactly (1+γ)/(1−γ)(1+\gamma)/(1-\gamma), because s1s_1 has no self-loop under go.

The ill-conditioned direction is the constant vector 1\mathbf 1, the eigenvector of the eigenvalue 1−γ1-\gamma. 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 1/(1−γ)1/(1-\gamma) 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 A=I−γPA=I-\gamma P and split P=L+D+UP=L+D+U into its strictly lower triangular, diagonal and strictly upper triangular parts (for a chosen ordering of the states). Any splitting A=M−NA=\mathsf M-\mathsf N with M\mathsf M easy to invert gives the iteration Vk+1=M−1(NVk+r)V_{k+1}=\mathsf M^{-1}(\mathsf NV_k+r), which converges from every start exactly when ρ(M−1N)<1\rho(\mathsf M^{-1}\mathsf N)<1. The sweeps of policy evaluation are four such splittings:

MethodM\mathsf MN\mathsf NAs a sweep
RichardsonIIγP\gamma Psynchronous iterative policy evaluation
JacobiI−γDI-\gamma Dγ(L+U)\gamma(L+U)synchronous, but each state's self-transition is solved exactly
In-place sweepI−γLI-\gamma Lγ(D+U)\gamma(D+U)in-place evaluation in the chosen order
Gauss–SeidelI−γ(L+D)I-\gamma(L+D)γU\gamma Uin place, with each self-transition solved exactly
Without self-transitions (D=0D=0) Richardson and Jacobi coincide, and so do the in-place sweep and Gauss–Seidel. Solving a self-transition exactly means setting V(s)=(r(s)+γ∑s′≠sP(s,s′)V(s′))/(1−γP(s,s))V(s)=\big(r(s)+\gamma\sum_{s'\ne s}P(s,s')V(s')\big)/\big(1-\gamma P(s,s)\big).
DerivationApplying it to policy evaluation
  1. A−1=M≥0A^{-1}=M\ge0. Each M\mathsf M in the table is I−γBI-\gamma B with B≥0B\ge0 lower triangular or diagonal and ρ(γB)<1\rho(\gamma B)<1, so M−1=∑j(γB)j≥0\mathsf M^{-1}=\sum_j(\gamma B)^j\ge0; and every N\mathsf N is nonnegative. All four splittings are regular.

  2. γU≤γ(D+U)≤γP,γU≤γ(L+U)≤γP⟹ρGS≤ρin-place≤ρRichardson=γ,ρGS≤ρJacobi≤γ\gamma U\le\gamma(D+U)\le\gamma P,\quad\gamma U\le\gamma(L+U)\le\gamma P\qquad\Longrightarrow\qquad\rho_{\text{GS}}\le\rho_{\text{in-place}}\le\rho_{\text{Richardson}}=\gamma,\quad\rho_{\text{GS}}\le\rho_{\text{Jacobi}}\le\gamma

    The N\mathsf N's are ordered entrywise, so the spectral radii are ordered the same way. Richardson's is exactly γ\gamma:

  3. The monotonicity behind it: A−1NA^{-1}\mathsf N grows entrywise with N\mathsf N because A−1≥0A^{-1}\ge0, the Perron root of a nonnegative matrix is monotone in its entries, and τ↦τ/(1+τ)\tau\mapsto\tau/(1+\tau) is increasing. Without self-transitions the Stein–Rosenberg theorem even gives strict inequality, ρGS<ρJacobi=γ\rho_{\text{GS}}<\rho_{\text{Jacobi}}=\gamma. These are asymptotic rates; the worst-case contraction of one sweep in the max norm stays γ\gamma for every order, as Policy Evaluation proved.

Krylov methods. GMRES chooses VkV_k in the Krylov space spanned by r,Ar,…,Ak−1rr,Ar,\dots,A^{k-1}r to minimize the residual, so the residual is pk(A) rp_k(A)\,r for the best polynomial of degree kk with pk(0)=1p_k(0)=1. For a diagonalizable AA with eigenvector matrix XX,

∥r−AVk∥2≤κ2(X) min⁡pk(0)=1 max⁡λ∈σ(A)∣pk(λ)∣ ∥r∥2.\norm{r-AV_k}_2\le\kappa_2(X)\,\min_{p_k(0)=1}\ \max_{\lambda\in\sigma(A)}\abs{p_k(\lambda)}\ \norm{r}_2 .

On the whole disc ∣z−1∣≤γ\abs{z-1}\le\gamma the min–max equals γk\gamma^k, attained by pk(z)=(1−z)kp_k(z)=(1-z)^k, which is Richardson's polynomial: if the spectrum of PP 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 κ2(X)\kappa_2(X) can make the bound weak; in practice one tries a Krylov solver and measures.

python
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 V

Each 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

DerivationProof
  1. V^−V=Δr+γP^(V^−V)+γ(P^−P)V⟹(I−γP^)(V^−V)=Δr+γ ΔP V\hat V-V=\Delta r+\gamma\hat P(\hat V-V)+\gamma(\hat P-P)V\quad\Longrightarrow\quad(I-\gamma\hat P)(\hat V-V)=\Delta r+\gamma\,\Delta P\,V

    Subtract the two Bellman equations, V^=r^+γP^V^\hat V=\hat r+\gamma\hat P\hat V and V=r+γPVV=r+\gamma PV, and add and subtract γP^V\gamma\hat PV:

  2. (ΔP V)(s)=∑s′ΔP(s,s′)(V(s′)−c)⟹∣(ΔP V)(s)∣≤∥ΔP(s,⋅)∥1⋅12sp⁡(V)(\Delta P\,V)(s)=\sum_{s'}\Delta P(s,s')\big(V(s')-c\big)\quad\Longrightarrow\quad\abs{(\Delta P\,V)(s)}\le\norm{\Delta P(s,\cdot)}_1\cdot\tfrac12\operatorname{sp}(V)

    Invert, using ∥(I−γP^)−1∥∞=1/(1−γ)\norm{(I-\gamma\hat P)^{-1}}_\infty=1/(1-\gamma) for the stochastic matrix P^\hat P. For the span bound, the zero row sums let you subtract any constant cc from VV; take the midpoint c=12(max⁡V+min⁡V)c=\frac12(\max V+\min V):

  3. Finally 0≤V≤Rmax⁡/(1−γ)0\le V\le R_{\max}/(1-\gamma) gives sp⁡(V)≤Rmax⁡/(1−γ)\operatorname{sp}(V)\le R_{\max}/(1-\gamma). One factor 1/(1−γ)1/(1-\gamma) 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), V=(18,20)V=(18,20) at γ=0.9\gamma=0.9, in a wrong model where stay in s2s_2 slips back to s1s_1 with probability 0.10.1. Then ΔP(s2,⋅)=(0.1,−0.1)\Delta P(s_2,\cdot)=(0.1,-0.1) and (ΔP V)(s2)=0.1⋅18−0.1⋅20=−0.2(\Delta P\,V)(s_2)=0.1\cdot18-0.1\cdot20=-0.2.

  • The crude bound, with ∥ΔP∥∞∥V∥∞=0.2⋅20\norm{\Delta P}_\infty\norm{V}_\infty=0.2\cdot20, gives 0.9⋅4/0.1=360.9\cdot4/0.1=36.
  • The span bound, with sp⁡(V)=2\operatorname{sp}(V)=2, gives 0.9⋅0.2/0.1=1.80.9\cdot0.2/0.1=1.8.
  • The truth: V^(s2)=2/(0.1+0.09⋅0.1)≈18.35\hat V(s_2)=2/(0.1+0.09\cdot0.1)\approx18.35, an error of 1.65.

A model error that moves probability between states of similar value costs little; what matters is ΔP\Delta P applied to VV, 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

  • (I−γP)−1=∑tγtPt(I-\gamma P)^{-1}=\sum_t\gamma^tP^t counts expected discounted visits; scaled by 1−γ1-\gamma it is a stochastic matrix of discounted occupancies, and V=(I−γP)−1rV=(I-\gamma P)^{-1}r is an expectation under them.
  • The spectrum of I−γPI-\gamma P lies in the disc ∣z−1∣≤γ\abs{z-1}\le\gamma, and κ∞≤(1+γ)/(1−γ)\kappa_\infty\le(1+\gamma)/(1-\gamma), 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 γ\gamma. Krylov methods help when the spectrum is clustered, not on a spectrum that fills the disc.
  • A wrong model changes the value by exactly (I−γP^)−1(Δr+γΔP V)(I-\gamma\hat P)^{-1}(\Delta r+\gamma\Delta P\,V): the error depends on the span of VV and grows like 1/(1−γ)21/(1-\gamma)^2 at worst.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Which statement about M=(I−γPπ)−1M=(I-\gamma P^\pi)^{-1} is true for every stochastic PπP^\pi and γ∈[0,1)\gamma\in[0,1)?

  1. MM is symmetric
  2. Each row of MM sums to 1
  3. M(s,s′)M(s,s') is the expected discounted number of visits to s′s' starting from ss
  4. MM can have negative entries when PπP^\pi has zero entries
Show the answer

C. M(s,s′)M(s,s') is the expected discounted number of visits to s′s' starting from ss

M=∑tγt(Pπ)tM=\sum_t\gamma^t(P^\pi)^t, and (Pπ)t(s,s′)(P^\pi)^t(s,s') is the probability of being in s′s' at time tt. Every term is nonnegative, the rows sum to 1/(1−γ)1/(1-\gamma), and (1−γ)M(1-\gamma)M is the stochastic matrix of normalized discounted occupancies.

Question 2

In a chain where some state has no self-transition, for which discount is κ∞(I−γP)=39\kappa_\infty(I-\gamma P)=39?

  1. γ=0.9\gamma=0.9
  2. γ=0.95\gamma=0.95
  3. γ=0.975\gamma=0.975
  4. γ=0.99\gamma=0.99
Show the answer

B. γ=0.95\gamma=0.95

Solve (1+γ)/(1−γ)=39(1+\gamma)/(1-\gamma)=39: 1+γ=39−39γ1+\gamma=39-39\gamma, so γ=38/40=0.95\gamma=38/40=0.95. The condition number roughly doubles the effective horizon 1/(1−γ)1/(1-\gamma).

Question 3

For a fixed policy and γ<1\gamma<1, what does the comparison of regular splittings guarantee about in-place sweeps?

  1. Their asymptotic rate ρ\rho is at most γ\gamma, the synchronous rate, whatever the order of the states
  2. They need fewer sweeps than synchronous evaluation from every starting point
  3. They are faster only if the states are swept in reverse order
  4. Jacobi always beats Gauss–Seidel
Show the answer

A. Their asymptotic rate ρ\rho is at most γ\gamma, the synchronous rate, whatever the order of the states

The in-place splitting has N=γ(D+U)≤γP\mathsf N=\gamma(D+U)\le\gamma P, so its spectral radius is at most Richardson's, γ\gamma, 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.

Question 4

A model moves probability 0.05 of one transition to a wrong next state, so ∥ΔP(s,⋅)∥1=0.1\norm{\Delta P(s,\cdot)}_1=0.1 for one ss and 0 elsewhere. All values lie between 9 and 10, rewards are exact, and γ=0.9\gamma=0.9. What does the span bound give for ∥V^−V∥∞\norm{\hat V-V}_\infty?

  1. 0.05
  2. 4.5
  3. 0.45
  4. 9
Show the answer

C. 0.45

∣(ΔP V)(s)∣≤12⋅0.1⋅sp⁡(V)=0.05\abs{(\Delta P\,V)(s)}\le\frac12\cdot0.1\cdot\operatorname{sp}(V)=0.05, and the error is at most γ⋅0.05/(1−γ)=0.45\gamma\cdot0.05/(1-\gamma)=0.45. The crude bound with ∥V∥∞=10\norm{V}_\infty=10 would give 0.9⋅0.1⋅10/0.1=90.9\cdot0.1\cdot10/0.1=9.

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).