RL Bible

RL Bible · Chapter 3

Markov Decision Processes

The formal model of sequential decision making: returns, policies, value functions, and the Bellman equations.

The bandit agent of Chapter 2 lives in an eternal present: every pull faces the same situation, and nothing it does changes what it will face next. Almost nothing you actually care about is like that. Move a chess piece and you face a different board; grasp a mug badly and it is now tipping. The moment actions have consequences — the moment they change the situation — you need a mathematical object that tracks situations, transitions, and long-run outcomes. That object is the Markov decision process, and it is the stage on which every remaining chapter of this book is set.

This chapter is the most purely mathematical of Part 0, and deliberately so: the definitions made here — return, policy, value function, Bellman equation — are used on every page that follows. We build each one slowly, prove the identities that matter, and end by exactly solving a small gridworld, no learning required, so you can see what all the machinery is for. If you internalize one thing, make it the Bellman expectation equation: a one-line statement of temporal consistency from which, it is hardly an exaggeration to say, the entire field unfolds.

1. The Markov Property

Start with the word "state." Chapter 1 used it informally as "the situation the agent observes." The formal requirement that makes the theory go is the Markov property: a state summarizes the past so completely that the past adds nothing. Formally, a state process has the Markov property if for all histories,

Pr(St+1=s,Rt+1=r|St,At)  =  Pr(St+1=s,Rt+1=r|S0,A0,R1,,St,At).\Pr\left( S_{t+1} = s', R_{t+1} = r \,\middle|\, S_t, A_t \right) \;=\; \Pr\left( S_{t+1} = s', R_{t+1} = r \,\middle|\, S_0, A_0, R_1, \dots, S_t, A_t \right).

The future is conditionally independent of the past, given the present. "The state is a sufficient statistic of the history."

Whether the Markov property holds is a property of how you define the state, not of the world. A chess board position is Markov for the rules of chess (the legal moves and outcomes depend only on the position — castling rights and repetition counts included, which is why the official "position" includes them). A single camera frame of a flying ball is not Markov: it hides the velocity, and the next frame is not predictable from position alone. Stack two consecutive frames and velocity becomes inferable; the stacked pair is (nearly) Markov. This is precisely why DQN feeds Atari agents four stacked frames (Chapter 10), and the gap between what the agent sees and a true Markov state is the defining problem of robotics (Section 8, and Part IV passim).

Check your understanding

A poker player's 'state' is defined as the cards they hold plus all bets made so far. Is this state Markov?

2. The Markov Decision Process

A finite Markov decision process is a tuple (S,A,p,γ)(\mathcal{S}, \mathcal{A}, p, \gamma):

  • S\mathcal{S}: a finite set of states;
  • A(s)\mathcal{A}(s): a finite set of actions available in each state;
  • pp: the dynamics function, the complete physics of the world,
p(s,rs,a)  =  Pr(St+1=s,Rt+1=r|St=s,At=a),p(s', r \mid s, a) \;=\; \Pr\left( S_{t+1} = s', R_{t+1} = r \,\middle|\, S_t = s, A_t = a \right),

a proper probability distribution: srp(s,rs,a)=1\sum_{s'} \sum_r p(s', r \mid s, a) = 1 for every (s,a)(s, a);

  • γ[0,1]\gamma \in [0, 1]: the discount factor, whose job Section 4 explains.

Everything else you will ever need is a marginal or expectation of pp. The state-transition function:

P(ss,a)  =  rp(s,rs,a),P(s' \mid s, a) \;=\; \sum_{r} p(s', r \mid s, a),

the expected reward function:

r(s,a)  =  E[Rt+1St=s,At=a]  =  rrsp(s,rs,a),r(s, a) \;=\; \E\left[ R_{t+1} \mid S_t = s, A_t = a \right] \;=\; \sum_{r} r \sum_{s'} p(s', r \mid s, a),

and occasionally the three-argument r(s,a,s)=E[Rt+1St=s,At=a,St+1=s]r(s, a, s') = \E[R_{t+1} \mid S_t = s, A_t = a, S_{t+1} = s']. Many texts define an MDP as (S,A,P,r,γ)(\mathcal{S}, \mathcal{A}, P, r, \gamma) directly; the two presentations are interchangeable, and we will use whichever is cleaner in context.

The word finite buys us clean theory (sums instead of integrals, maxima attained, matrices invertible); Part II onward trades it away for continuous states and neural networks, keeping the same equations with integrals understood. The word Markov is what makes pp well-defined at all: only because the state screens off history can a memoryless function give the full distribution over what happens next.

Our running example: the 4×4 Gridworld. Sixteen cells. The agent starts anywhere, moves North, South, East, or West; moves that would leave the grid leave the agent in place. Two opposite corner cells are terminal. Every transition costs 1-1 reward until termination — so maximizing return means escaping fast. Deterministic dynamics: p(s,rs,a)p(s', r \mid s, a) puts probability 1 on the single outcome. This little world (it is Example 4.1 of Sutton & Barto) will follow us through Chapter 8; small enough to solve by hand, rich enough to watch every algorithm work.

0−1−2−3−1−2−3−2−2−3−2−1−3−2−10
Fig 3.1, The 4×4 Gridworld. Shaded corners are terminal; every step costs −1; bumping a wall wastes the step. The numbers are the optimal values V*(s) — the negative of the fewest steps out.

3. Episodes, Returns, and the Absorbing-State Trick

The agent's objective is cumulative reward, formalized as the return. In an episodic task ending at terminal time TT:

Gt  =  Rt+1+Rt+2++RT.G_t \;=\; R_{t+1} + R_{t+2} + \cdots + R_T.

In a continuing task there is no TT, and the plain sum may diverge — an agent earning +1 per step forever has infinite return under any policy, and "maximize infinity" ranks nothing. The fix is discounting: with γ[0,1)\gamma \in [0, 1),

Gt  =  Rt+1+γRt+2+γ2Rt+3+  =  k=0γkRt+k+1.G_t \;=\; R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + \cdots \;=\; \sum_{k=0}^{\infty} \gamma^k R_{t+k+1}.

If rewards are bounded, RRmax\lvert R \rvert \le R_{\max}, the series converges absolutely: GtRmaxkγk=Rmax1γ\lvert G_t \rvert \le R_{\max} \sum_k \gamma^k = \frac{R_{\max}}{1 - \gamma}. That bound, Rmax1γ\frac{R_{\max}}{1-\gamma}, recurs constantly — it is the scale of every value function, and the 11γ\frac{1}{1-\gamma} factor is the "effective horizon": with γ=0.99\gamma = 0.99, rewards about 100 steps out still carry meaningful weight; with γ=0.9\gamma = 0.9, about 10 steps. Choosing γ is choosing how far ahead your agent cares.

Three readings of γ, all useful: an economic one (reward tomorrow is worth γ of reward today — interest rates); a probabilistic one (the process terminates with probability 1γ1 - \gamma each step, and GtG_t is the undiscounted return of that randomly truncated process — Exercise 3.3); and a pragmatic one (γ shrinks the variance of returns and, in Chapter 4, drives the contraction that makes everything converge; practitioners often tune γ below 1 even in episodic tasks purely for this).

The recursion that powers the whole book falls straight out of the definition:

Gt  =  Rt+1+γ(Rt+2+γRt+3+)  =  Rt+1+γGt+1.G_t \;=\; R_{t+1} + \gamma \left( R_{t+2} + \gamma R_{t+3} + \cdots \right) \;=\; R_{t+1} + \gamma\, G_{t+1}.

Return now equals immediate reward plus discounted return from the next step. Memorize this line; the Bellman equations are its expectations.

Finally, the two task types unify. Convert any episodic task to a continuing one by making termination mean entering an absorbing state that transitions only to itself with reward 0 forever. Then the discounted sum equals the finite episodic sum (with γ=1\gamma = 1 allowed if episodes end with probability 1), and one set of equations serves both. We use this convention silently from now on: terminal states have value zero by construction.

4. Policies and Value Functions

A policy π(as)\pi(a \mid s) maps each state to a probability distribution over actions — the agent's complete behavioral specification. Given a policy, the MDP's randomness and the policy's randomness together make the trajectory a well-defined stochastic process, and we can ask the question at the center of the field: how good is it to be somewhere, behaving like this?

The state-value function of policy π:

Vπ(s)  =  Eπ[Gt|St=s]  =  Eπ[k=0γkRt+k+1|St=s],V^\pi(s) \;=\; \E_\pi\left[ G_t \,\middle|\, S_t = s \right] \;=\; \E_\pi\left[ \sum_{k=0}^{\infty} \gamma^k R_{t+k+1} \,\middle|\, S_t = s \right],

and the action-value function, which additionally pins the first action:

Qπ(s,a)  =  Eπ[Gt|St=s,At=a].Q^\pi(s, a) \;=\; \E_\pi\left[ G_t \,\middle|\, S_t = s, A_t = a \right].

(Eπ\E_\pi means: actions sampled from π, transitions from pp, forever.) The two interconvert by one step of averaging or lookahead:

Vπ(s)=aπ(as)Qπ(s,a),Qπ(s,a)=s,rp(s,rs,a)[r+γVπ(s)].V^\pi(s) = \sum_a \pi(a \mid s)\, Q^\pi(s, a), \qquad Q^\pi(s, a) = \sum_{s', r} p(s', r \mid s, a) \left[ r + \gamma V^\pi(s') \right].

The first says: the value of a state is the policy-weighted average of its action values. The second says: the value of an action is the expected immediate reward plus the discounted value of where you land. Substituting either into the other gives the Bellman equations of the next section.

Why two functions? VπV^\pi is enough to evaluate, but acting greedily with respect to VπV^\pi requires a model (you must imagine where each action leads — the second equation above). QπQ^\pi bakes the one-step lookahead into the function itself: greedy action selection is just arg maxaQ(s,a)\argmax_a Q(s, a), no model needed. That single convenience is why model-free control (Chapters 5–13) runs on QQ, and why the letter Q may be the most famous letter in RL.

The advantage function, Aπ(s,a)=Qπ(s,a)Vπ(s)A^\pi(s, a) = Q^\pi(s, a) - V^\pi(s), measures how much better action aa is than the policy's average behavior in ss. It is zero in expectation under π (Exercise 3.5), positive exactly for actions worth deviating to, and it will be the central quantity of the policy-gradient chapters (11–12).

5. The Bellman Expectation Equations

We now derive the identity that everything else in this book either solves, approximates, or samples. Start from the value definition, use the return recursion Gt=Rt+1+γGt+1G_t = R_{t+1} + \gamma G_{t+1}, and unpack the expectation one step:

Vπ(s)=Eπ[Rt+1+γGt+1|St=s]=aπ(as)s,rp(s,rs,a)[r+γEπ[Gt+1St+1=s]]=aπ(as)s,rp(s,rs,a)[r+γVπ(s)].\begin{aligned} V^\pi(s) &= \E_\pi\left[ R_{t+1} + \gamma G_{t+1} \,\middle|\, S_t = s \right] \\[2pt] &= \sum_a \pi(a \mid s) \sum_{s', r} p(s', r \mid s, a) \left[ r + \gamma\, \E_\pi\left[ G_{t+1} \mid S_{t+1} = s' \right] \right] \\[2pt] &= \sum_a \pi(a \mid s) \sum_{s', r} p(s', r \mid s, a) \left[ r + \gamma\, V^\pi(s') \right]. \end{aligned}

The step that deserves scrutiny is the last one: replacing Eπ[Gt+1St+1=s,St=s,At=a,Rt+1=r]\E_\pi[G_{t+1} \mid S_{t+1} = s', S_t = s, A_t = a, R_{t+1} = r] with Vπ(s)V^\pi(s'). That is legal only because of the Markov property — given St+1=sS_{t+1} = s', the future return's distribution is independent of how we arrived, so conditioning on (s,a,r)(s, a, r) changes nothing. No Markov, no Bellman equation; this is where the assumption earns its keep.

The result is the Bellman expectation equation for VπV^\pi:

Vπ(s)  =  aπ(as)s,rp(s,rs,a)[r+γVπ(s)]for all sS,V^\pi(s) \;=\; \sum_a \pi(a \mid s) \sum_{s', r} p(s', r \mid s, a) \left[ r + \gamma V^\pi(s') \right] \qquad \text{for all } s \in \mathcal{S},

and its twin for action values:

Qπ(s,a)  =  s,rp(s,rs,a)[r+γaπ(as)Qπ(s,a)].Q^\pi(s, a) \;=\; \sum_{s', r} p(s', r \mid s, a) \left[ r + \gamma \sum_{a'} \pi(a' \mid s')\, Q^\pi(s', a') \right].
sπps′V backups, apπa′Q backup
Fig 3.2, Backup diagrams for V^π (left) and Q^π (right). Open circles are states, dots are actions. Value flows backward: each parent's value is the weighted average of one-step lookaheads through its children — π weights the action fan-out, p weights the state fan-out.

Three ways to read the Bellman equation, in ascending abstraction:

  1. Consistency check. It is a self-consistency condition: the value at ss must agree with the values one step downstream. Any function violating it at some state is not the value function of π. TD learning (Chapter 6) is nothing but nudging estimates toward satisfying it, one sampled transition at a time.
  2. A linear system. For fixed π, the equation is linear in the S\lvert \mathcal{S} \rvert unknowns Vπ(s)V^\pi(s). In matrix form, stacking values into a vector VRSV \in \R^{\lvert \mathcal{S} \rvert}, with Pssπ=aπ(as)P(ss,a)P^\pi_{ss'} = \sum_a \pi(a \mid s) P(s' \mid s, a) and rsπ=aπ(as)r(s,a)r^\pi_s = \sum_a \pi(a \mid s) r(s, a):
V=rπ+γPπVV=(IγPπ)1rπ.V = r^\pi + \gamma P^\pi V \quad \Longleftrightarrow \quad V = \left( I - \gamma P^\pi \right)^{-1} r^\pi.

The inverse exists whenever γ\gamma is below 1: PπP^\pi is a stochastic matrix, its spectral radius is 1, so γPπ\gamma P^\pi has spectral radius γ\gamma below 1 and IγPπI - \gamma P^\pi is invertible (Neumann series: (IγPπ)1=k0(γPπ)k(I - \gamma P^\pi)^{-1} = \sum_{k \ge 0} (\gamma P^\pi)^k — which is also exactly the "sum of discounted rewards over all paths" reading). Policy evaluation is, in principle, one matrix inversion at cost O(S3)\mathcal{O}(\lvert\mathcal{S}\rvert^3) — Section 7 does it numerically for the gridworld. 3. A fixed point. Define the Bellman expectation operator Tπ\mathcal{T}^\pi acting on any value-function candidate VV: (TπV)(s)=aπ(as)s,rp(s,rs,a)[r+γV(s)](\mathcal{T}^\pi V)(s) = \sum_a \pi(a \mid s) \sum_{s',r} p(s', r \mid s, a) [r + \gamma V(s')]. The Bellman equation says precisely Vπ=TπVπV^\pi = \mathcal{T}^\pi V^\pi: the true value function is the fixed point of Tπ\mathcal{T}^\pi. Chapter 4 proves Tπ\mathcal{T}^\pi is a γ-contraction, so the fixed point is unique and iterating Tπ\mathcal{T}^\pi from anywhere converges to it. That theorem is the bedrock under dynamic programming, TD, and (in spirit) DQN.

6. Optimal Policies and the Bellman Optimality Equations

Evaluation done; now the point of it all — finding the best behavior. Order policies by their value functions: ππ\pi \ge \pi' iff Vπ(s)Vπ(s)V^\pi(s) \ge V^{\pi'}(s) for every state ss. This is a partial order (two policies can each win somewhere), so the following fact, the fundamental theorem of MDPs, is not obvious:

For any finite MDP, there exists a policy π\pi^* that is at least as good as every other policy in every state simultaneously. All optimal policies share one value function V(s)=maxπVπ(s)V^*(s) = \max_\pi V^\pi(s) and one action-value function Q(s,a)=maxπQπ(s,a)Q^*(s, a) = \max_\pi Q^\pi(s, a), and at least one optimal policy is deterministic.

(The proof route: Chapter 4 shows the Bellman optimality operator has a unique fixed point VV^* and that acting greedily with respect to VV^* attains it — existence by construction. Take the theorem on credit until then.) Pause on how strong this is: no trade-offs. In a finite MDP you never have to choose which states to be good in; one policy dominates everywhere. And the existence of a deterministic optimum tells you stochasticity is never necessary for optimality in a fully observed MDP — randomness in policies earns its keep only for exploration (during learning), under partial observability, or against adaptive opponents.

The optimal value functions obey their own Bellman equations. An optimal policy, at state ss, must select an action achieving the max over QQ^* — intuitively, "behave optimally now, given that you will behave optimally later." Formally, the Bellman optimality equations:

V(s)  =  maxas,rp(s,rs,a)[r+γV(s)],V^*(s) \;=\; \max_a \sum_{s', r} p(s', r \mid s, a)\left[ r + \gamma V^*(s') \right], Q(s,a)  =  s,rp(s,rs,a)[r+γmaxaQ(s,a)].Q^*(s, a) \;=\; \sum_{s', r} p(s', r \mid s, a)\left[ r + \gamma \max_{a'} Q^*(s', a') \right].

Structurally identical to the expectation equations with one lethal change: the policy-weighted average over actions became a max. That max makes the system nonlinear — no matrix inversion, no closed form. Everything from Chapter 4 to Chapter 25 is, at bottom, a strategy for solving or approximating this nonlinear system: dynamic programming iterates it, Q-learning samples it, DQN fits it with a neural network, and MuZero learns the pp inside it.

Given QQ^*, optimal behavior is trivial: π(s)=arg maxaQ(s,a)\pi^*(s) = \argmax_a Q^*(s, a) — the greedy policy is optimal, no lookahead, no model, no farsightedness required, because QQ^* already contains the future. This is the sense in which value functions solve credit assignment: all the long-term consequences have been compressed into a number per action.

Check your understanding

The Bellman expectation equation for a fixed policy is a linear system; the optimality equation is not. What exactly broke the linearity, and why does it matter algorithmically?

7. Worked Example: Solving the Gridworld Exactly

Let's make every abstraction above concrete. Take the 4×4 gridworld and the uniform random policy: π(as)=1/4\pi(a \mid s) = 1/4 for all four moves, everywhere; γ=1\gamma = 1 (episodic, so allowed). Because dynamics and policy are known, VπV^\pi is just the linear system from Section 5, and we can solve it exactly:

import numpy as np
 
N = 4                       # grid side; states 0..15, 0 and 15 terminal
TERMINAL = {0, 15}
ACTIONS = [(-1, 0), (1, 0), (0, -1), (0, 1)]   # N, S, W, E
 
def step(s, a):
    """Deterministic gridworld dynamics: returns (s', r)."""
    if s in TERMINAL:
        return s, 0.0                          # absorbing, reward 0
    r, c = divmod(s, N)
    dr, dc = ACTIONS[a]
    nr, nc = r + dr, c + dc
    if not (0 <= nr < N and 0 <= nc < N):      # bump: stay in place
        nr, nc = r, c
    return nr * N + nc, -1.0
 
# Build P^pi (16x16) and r^pi (16,) for the uniform random policy
P = np.zeros((N * N, N * N))
r = np.zeros(N * N)
for s in range(N * N):
    for a in range(4):
        s2, rew = step(s, a)
        P[s, s2] += 0.25
        r[s] += 0.25 * rew
 
# Terminal rows: absorbing with zero reward already handled by step().
# Solve (I - gamma * P) V = r with gamma = 1. The system is singular on
# absorbing states (V_terminal appears as V = 0 + V), so pin them to 0
# by solving only over non-terminal states.
free = [s for s in range(N * N) if s not in TERMINAL]
A = np.eye(len(free)) - P[np.ix_(free, free)]   # gamma = 1
V = np.zeros(N * N)
V[free] = np.linalg.solve(A, r[free])
 
print(V.reshape(N, N).round(1))

The output:

[[  0.  -14. -20. -22.]
 [-14. -18. -20. -20.]
 [-20. -20. -18. -14.]
 [-22. -20. -14.   0.]]

Under aimless wandering, the center cells expect to blunder around for ~20 steps before stumbling out. Two lessons in these numbers. First, this is what VπV^\pi means operationally — run the random policy from the cell next to a terminal corner a million times, average the returns, and you will measure 14.0-14.0. Second, compare with Fig 3.1's optimal values (00 to 3-3): the gap between VπV^\pi and VV^* is the improvement that control algorithms exist to capture. Chapter 4 will close that gap for this exact grid, iteratively, and you should run its code against this solution as a check.

Note also what the code needed that a learning agent will not have: the loop for s in range(16), for a in range(4) — a full sweep over the state space using the known step function. When the model pp is unknown (Chapter 5 onward) or the state space has 1017010^{170} states (Go) rather than 16, exact solution dies, and sampling and approximation take over. The equations survive; only the method of solving them changes.

8. Partial Observability: the POMDP

One honest complication before we go. Real agents rarely see the state. A robot gets pixels, joint encoders, maybe a wrist force sensor — a window, not the world. The formal model is the partially observable MDP: an MDP (S,A,p,γ)(\mathcal{S}, \mathcal{A}, p, \gamma) plus an observation set Ω\Omega and observation model O(os,a)O(o \mid s', a), with the agent receiving OtO_t, never StS_t.

The classical theory says: a POMDP is an MDP over belief states — the posterior bt(s)=Pr(St=sO1:t,A1:t1)b_t(s) = \Pr(S_t = s \mid O_{1:t}, A_{1:t-1}) is itself Markov, updated by Bayes' rule after each observation, and all our machinery applies to belief space. The catch is that belief space is a continuous simplex over S\mathcal{S}, so "just solve the belief MDP" is computationally hopeless except for tiny problems (exact POMDP planning is PSPACE-hard even for finite horizons).

Practice therefore approximates the belief with learned memory: recurrent networks whose hidden state hth_t summarizes o1:to_{1:t} (R2D2, Chapter 10's recurrent cousin), stacked frames (a fixed-window belief proxy), or the latent states of world models — Chapter 23's RSSM is best understood as a learned, compressed belief state. We flag partial observability now, treat everything as fully observed through Part II for clarity, and pay the debt properly in Part IV, where it is unavoidable.

Common pitfalls — modeling sins that no algorithm survives

The MDP you write down, not the world, is what your agent optimizes. The recurring sins: hidden state — omitting a variable the dynamics depend on (ball velocity, motor temperature) makes transitions look random, caps performance, and silently breaks every convergence result resting on the Markov property; wrong discount — γ = 0.99 at 50 Hz control is a 2-second effective horizon, far too short to value a grasp that pays off in 10 seconds (scale γ with the control frequency); reward-per-step sign errors — a positive per-step reward in a task with escape-able episodes teaches the agent to not terminate (the classic "agent runs in circles forever" bug); time-limit confusion — if episodes are cut at 1,000 steps for convenience, bootstrapping as if the cut were a true terminal state corrupts values (treat timeouts as non-terminal by bootstrapping V(s1000)V(s_{1000}); Chapter 6 returns to this).

9. Summary

  • A state is Markov when it screens off history: Pr(St+1,Rt+1St,At)\Pr(S_{t+1}, R_{t+1} \mid S_t, A_t) needs nothing older. Markov-ness is a property of your state design.
  • A finite MDP is (S,A,p,γ)(\mathcal{S}, \mathcal{A}, p, \gamma) with dynamics p(s,rs,a)p(s', r \mid s, a); P(ss,a)P(s' \mid s,a) and r(s,a)r(s,a) are its marginals.
  • The return Gt=kγkRt+k+1G_t = \sum_k \gamma^k R_{t+k+1} is bounded by Rmax/(1γ)R_{\max}/(1-\gamma); 1/(1γ)1/(1-\gamma) is the effective horizon; Gt=Rt+1+γGt+1G_t = R_{t+1} + \gamma G_{t+1} is the master recursion. Absorbing states unify episodic and continuing tasks.
  • Vπ(s)=Eπ[GtSt=s]V^\pi(s) = \E_\pi[G_t \mid S_t = s] and Qπ(s,a)Q^\pi(s,a) add a pinned first action; they interconvert by one step of averaging/lookahead; Aπ=QπVπA^\pi = Q^\pi - V^\pi.
  • Bellman expectation equation: Vπ(s)=aπ(as)s,rp(s,rs,a)[r+γVπ(s)]V^\pi(s) = \sum_a \pi(a \mid s) \sum_{s',r} p(s',r \mid s,a)[r + \gamma V^\pi(s')] — a consistency condition, a linear system solvable as V=(IγPπ)1rπV = (I - \gamma P^\pi)^{-1} r^\pi, and the fixed point of the operator Tπ\mathcal{T}^\pi.
  • Bellman optimality equations swap the average for a max, becoming nonlinear; π(s)=arg maxaQ(s,a)\pi^*(s) = \argmax_a Q^*(s,a) — greedy on QQ^* is optimal, which is why QQ matters so much.
  • In finite MDPs an optimal policy exists that dominates in every state, and a deterministic one suffices.
  • POMDPs model partial observability; beliefs restore Markov-ness at exponential cost; practice substitutes learned memory.

10. Papers & Further Reading

  • Bellman, "A Markovian Decision Process" (Journal of Mathematics and Mechanics, 1957)jstor.org/stable/24900506 — and his book Dynamic Programming (Princeton, 1957). The birth of the framework and of the phrase "curse of dimensionality." Historical reading, but Section 5's equations are on his pages.
  • Howard, Dynamic Programming and Markov Processes (MIT Press, 1960)mit.edu press archive. Introduced policy iteration; the earliest recognizably modern MDP text.
  • Puterman, Markov Decision Processes: Discrete Stochastic Dynamic Programming (Wiley, 1994)doi.org/10.1002/9780470316887. The mathematical reference: every existence theorem this chapter waved at, proved in full generality (countable states, undiscounted criteria, semi-MDPs). Consult, don't read cover to cover.
  • Sutton & Barto, Ch. 3incompleteideas.net/book/the-book-2nd.html. The presentation this chapter's conventions follow, with more examples and the pole-balancing formulation.
  • Kaelbling, Littman & Cassandra, "Planning and Acting in Partially Observable Stochastic Domains" (Artificial Intelligence, 1998)doi.org/10.1016/S0004-3702(98)00023-X. The canonical POMDP paper: belief-state MDPs, exact algorithms, and why they are hopeless beyond tiny problems.
  • Szepesvári, Algorithms for Reinforcement Learning (Morgan & Claypool, 2010)sztaki.hu/~szcsaba/papers/RLAlgsInMDPs.pdf. Sixty dense, rigorous pages from MDP definitions to function approximation; the best short bridge between this book's Parts 0–I and the theory literature (revisited in Chapter 21).

11. Exercises

3.1 (understand) For each proposed state, say whether it is (approximately) Markov for the task, and if not, name the hidden variable: (a) blackjack — your card total, dealer's visible card, and whether you hold a usable ace; (b) pole balancing — cart position and pole angle only; (c) a thermostat — current room temperature, for a room whose radiator takes 10 minutes to heat up; (d) Go — the current board position plus whose turn it is (careful: think about repetition rules).

3.2 (understand) An MDP has rewards bounded in [1,1][-1, 1] and γ=0.95\gamma = 0.95. Give the tightest possible bounds on Vπ(s)V^\pi(s) for any policy. How do the bounds change if rewards lie in [0,1][0, 1]? What does this tell you about comparing "reward scales" across environments?

3.3 (derive) Prove the termination interpretation of discounting: let the environment terminate at each step with probability 1γ1 - \gamma (independently), delivering reward 0 forever after, and let G~t\tilde{G}_t be the undiscounted return of this modified process. Show E[G~t]=E[kγkRt+k+1]\E[\tilde{G}_t] = \E[\sum_k \gamma^k R_{t+k+1}] for any fixed reward sequence, hence for any policy.

3.4 (derive) Derive the Bellman expectation equation for QπQ^\pi from scratch, mirroring Section 5's derivation for VπV^\pi, and state exactly where the Markov property is used. Then verify the two interconversion identities of Section 4 are consistent with both Bellman equations (substitute each into the other).

3.5 (derive) Show that Eaπ(s)[Aπ(s,a)]=0\E_{a \sim \pi(\cdot \mid s)}\left[ A^\pi(s, a) \right] = 0 for every state, and that a policy is optimal if and only if maxaAπ(s,a)=0\max_a A^{\pi}(s, a) = 0 in every state. (The second half is a compact restatement of the Bellman optimality condition — worth doing slowly.)

3.6 (derive) In the 4×4 gridworld with the uniform random policy, verify the Bellman expectation equation numerically at one state: take the cell adjacent to the top-left terminal (value 14.0-14.0), enumerate its four action outcomes, and confirm 14=14a[r+V(s)]-14 = \frac{1}{4}\sum_a [r + V(s')] using the solved values printed in Section 7.

3.7 (implement) Modify the Section 7 code to compute VπV^\pi for γ = 0.9 (now the full 16-state system (IγP)V=r(I - \gamma P)V = r is nonsingular — solve it without pinning terminals and check the terminal values come out 0 anyway). Compare the value surface to γ = 1: which states change most, and why?

3.8 (implement) Add a "wind" to the gridworld: with probability 0.2 the agent is pushed one extra cell East (walls still block). Rebuild PπP^\pi and re-solve. Explain the asymmetry that appears in the value function of the symmetric random policy.

3.9 (derive) Prove that if two policies satisfy Qπ(s,π(s))Vπ(s)Q^{\pi}(s, \pi'(s)) \ge V^\pi(s) for all ss, then Vπ(s)Vπ(s)V^{\pi'}(s) \ge V^\pi(s) for all ss. Hint: expand Vπ(s)Qπ(s,π(s))=E[Rt+1+γVπ(St+1)At=π(s)]V^\pi(s) \le Q^\pi(s, \pi'(s)) = \E[R_{t+1} + \gamma V^\pi(S_{t+1}) \mid A_t = \pi'(s)] and keep substituting the inequality into itself, telescoping. (You have just proven the policy improvement theorem — the engine of Chapter 4. We will cite this exercise there.)

3.10 (research) The optimal-policy existence theorem fails in subtle ways beyond finite MDPs: construct (or find in Puterman §mixed criteria) an example with countably infinite states where no optimal policy exists (only ε-optimal ones), and explain which step of the finite-case argument breaks. What does this suggest about "optimal" as a goal for continuous-state deep RL?