Hyoungseo Son
Reinforcement Learning Theory
Contents · Reinforcement Learning Theory

Part 0 · MDPs

  • MDPs, Returns, and Value Functions

Part 1 · Bellman & Value Iteration

Part 2 · Policy Gradients

Part 3 · Trust Regions

Part 0 · MDPs

MDPs, Returns, and Value Functions

A physics simulator already gives you the hard part of a decision problem: a step function that maps a state and an action to a next state. Add a scalar reward on each step and you have a Markov decision process. The first question is not how to act well but how to grade a fixed way of acting: given a policy, how good is each state? That grade is the value function, and computing it is policy evaluation. Choosing a better policy comes later; here we only measure.

The Markov decision process

An MDP is a tuple (S,A,P,r,γ)(\mathcal{S}, \mathcal{A}, P, r, \gamma). The states S\mathcal{S} and actions A\mathcal{A} are the configurations and controls. The transition kernel

P(ss,a)=Pr{st+1=sst=s, at=a}P(s' \mid s, a) = \Pr\{\, s_{t+1} = s' \mid s_t = s,\ a_t = a \,\}

is the simulator's step, promoted to a distribution to allow stochastic dynamics. The reward r(s,a)r(s, a) is the scalar earned on that step, and γ[0,1)\gamma \in [0, 1) discounts the future. The defining assumption is Markov: st+1s_{t+1} depends on the past only through the current (st,at)(s_t, a_t), which is exactly what a state-based simulator guarantees.

A policy π(as)\pi(a \mid s) is a distribution over actions in each state. Fix one and the MDP collapses to a Markov reward process: the dynamics aπ(as)P(ss,a)\sum_a \pi(a\mid s) P(s'\mid s,a) and the expected reward aπ(as)r(s,a)\sum_a \pi(a\mid s)\, r(s,a) are both determined.

Return and value functions

The agent cares about the return, the discounted sum of future reward from time tt,

Gt=k=0γkrt+k=rt+γrt+1+γ2rt+2+.G_t = \sum_{k=0}^{\infty} \gamma^{k}\, r_{t+k} = r_t + \gamma r_{t+1} + \gamma^2 r_{t+2} + \cdots .

The factor γk\gamma^k makes reward kk steps away worth γk\gamma^k times as much, and keeps the sum finite whenever rewards are bounded. The state-value function is the expected return from a state under π\pi,

Vπ(s)=Eπ ⁣[Gtst=s],V^{\pi}(s) = \mathbb{E}_{\pi}\!\left[\, G_t \mid s_t = s \,\right],

and the action-value function conditions on the first action as well,

Qπ(s,a)=Eπ ⁣[Gtst=s, at=a].Q^{\pi}(s, a) = \mathbb{E}_{\pi}\!\left[\, G_t \mid s_t = s,\ a_t = a \,\right].

The two are tied by the policy: averaging QπQ^\pi over the action the policy would take recovers VπV^\pi,

Vπ(s)=aπ(as)Qπ(s,a).V^{\pi}(s) = \sum_{a} \pi(a \mid s)\, Q^{\pi}(s, a) .

VπV^\pi answers "how good is this state if I keep acting like π\pi?", not "how good could this state be?". Those are different questions, and only the first is on the table until we start improving π\pi.

The Bellman expectation equation

Split the return into the immediate reward and the discounted return from the next state, Gt=rt+γGt+1G_t = r_t + \gamma G_{t+1}. Taking expectations under π\pi turns this recursion into a linear equation in VπV^\pi:

Vπ(s)=aπ(as)sP(ss,a)[r(s,a)+γVπ(s)].V^{\pi}(s) = \sum_{a} \pi(a \mid s) \sum_{s'} P(s' \mid s, a) \Big[\, r(s, a) + \gamma\, V^{\pi}(s') \,\Big].

This is the Bellman expectation equation.1 It is not a maximization: there is no max\max over actions, only an average over the actions the fixed policy actually takes and over the successors the dynamics actually produce. The action-value form is the same statement one step in,

Qπ(s,a)=sP(ss,a)[r(s,a)+γaπ(as)Qπ(s,a)].Q^{\pi}(s, a) = \sum_{s'} P(s' \mid s, a) \Big[\, r(s, a) + \gamma \sum_{a'} \pi(a' \mid s')\, Q^{\pi}(s', a') \Big].

Policy evaluation

Write the right-hand side as an operator TπT^{\pi} acting on a value estimate VV,

(TπV)(s)=aπ(as)sP(ss,a)[r(s,a)+γV(s)].(T^{\pi} V)(s) = \sum_{a} \pi(a\mid s) \sum_{s'} P(s'\mid s,a) \big[\, r(s,a) + \gamma\, V(s') \,\big].

VπV^\pi is its fixed point, TπVπ=VπT^{\pi} V^\pi = V^\pi. Because γ<1\gamma < 1, the operator is a contraction in the max norm,

TπVTπUγVU,\lVert T^{\pi} V - T^{\pi} U \rVert_\infty \le \gamma\, \lVert V - U \rVert_\infty ,

so the iteration Vk+1=TπVkV_{k+1} = T^{\pi} V_k from any starting V0V_0 converges to the unique VπV^\pi at rate γ\gamma. That iteration is iterative policy evaluation: repeatedly apply the Bellman expectation update until VV stops moving.

Worked example: a three-state chain

Take three states A,B,CA, B, C with CC terminal, so V(C)=0V(C) = 0 always, and γ=0.9\gamma = 0.9. Fold a fixed policy into the dynamics so each state has a known transition and reward:

AB w.p. 1,  r=1,BC w.p. 0.5, r=+10orBA w.p. 0.5, r=1,C:terminal.\begin{aligned} A &\to B \ \text{w.p. } 1,\ \ r = -1, \\ B &\to C \ \text{w.p. } 0.5,\ r = +10 \quad\text{or}\quad B \to A \ \text{w.p. } 0.5,\ r = -1, \\ C &: \text{terminal}. \end{aligned}

Start from V0=(0,0,0)V_0 = (0, 0, 0) and apply TπT^\pi. The first sweep uses only immediate rewards, since every V0(s)=0V_0(s') = 0:

V1(A)=1+0.9V0(B)=1,V1(B)=0.5(10+0.9V0(C))+0.5(1+0.9V0(A))=50.5=4.5.\begin{aligned} V_1(A) &= -1 + 0.9\,V_0(B) = -1, \\ V_1(B) &= 0.5\,(10 + 0.9\,V_0(C)) + 0.5\,(-1 + 0.9\,V_0(A)) = 5 - 0.5 = 4.5 . \end{aligned}

The second sweep feeds V1V_1 back in, so value now flows one hop:

V2(A)=1+0.9(4.5)=3.05,V2(B)=0.5(10)+0.5(1+0.9(1))=50.95=4.05.\begin{aligned} V_2(A) &= -1 + 0.9\,(4.5) = 3.05, \\ V_2(B) &= 0.5\,(10) + 0.5\,(-1 + 0.9\,(-1)) = 5 - 0.95 = 4.05 . \end{aligned}

V(A)V(A) has moved 013.050 \to -1 \to 3.05 and V(B)V(B) has settled 04.54.050 \to 4.5 \to 4.05, both heading for the exact fixed point. Solving TπV=VT^\pi V = V directly gives

V(A)=1+0.9V(B),V(B)=4.5+0.45V(A),V(A) = -1 + 0.9\,V(B), \qquad V(B) = 4.5 + 0.45\,V(A),

so V(A)=3.05+0.405V(A)V(A) = 3.05 + 0.405\,V(A), hence V(A)5.13V(A) \approx 5.13 and V(B)6.81V(B) \approx 6.81. Two sweeps already land in the right neighborhood, and the γ=0.9\gamma = 0.9 contraction closes the rest of the gap geometrically.

Evaluation on a grid

The same update runs on a 2D gridworld MDP: every step costs 1-1, entering the goal pays +10+10, and the goal is terminal. Two fixed policies are on offer, a greedy walk toward the goal and the uniform-random walk. Neither is being improved. Iterative policy evaluation just applies Vr+γEπ[V]V \leftarrow r + \gamma\,\mathbb{E}_\pi[V'] until convergence and reports how good each cell is under that one policy.

Policy evaluation on a gridworldinteractive
3.14.66.28.010.0goal1.83.14.66.28.010.00.61.83.14.66.28.0-0.40.61.83.14.66.2-1.4-0.40.61.83.14.6-2.3-1.4-0.40.61.83.1
max change |ΔV|
0.000
far corner V
-2.25

The greedy policy walks straight to the goal, so value stays high and drops off slowly. Drag k back to 0 to watch V spread out from the goal one sweep at a time.

Cells are colored by V under the FIXED policy: green above zero, red below, saturation by magnitude. Arrows are the policy (one action when greedy, four faint stubs when random). Scrub k to watch value spread from the goal, and lower gamma to see far-future reward shrink so only cells near the goal stay bright. Switching the policy changes V, not the MDP.

Read the greedy field against the random one and the point is immediate: the value of a state is a property of the policy, not of the state alone. The random walk reaches the same goal but pays the step cost far longer, so its VπV^\pi is uniformly lower. Deciding which policy is better, and how to construct the best one, is the optimization problem the Bellman optimality equation takes up next.

Footnotes

  1. Sutton & Barto, Reinforcement Learning: An Introduction (2018).