A policy changes the distribution of whole trajectories
The state retains history needed to predict the next outcome.
The policy chooses actions; the environment supplies rewards and next states.
Compare policies by expected discounted return, including delayed consequences.
Today: estimate value from experience, then use reward feedback to improve the policy.
Choose the policy with the highest expected return from the start
The return from time \(t\) is the discounted sum of future rewards: \[G_t=\sum_{k=0}^{T-t-1}\gamma^k R_{t+k+1},\qquad
\pi^*\in\arg\max_\pi\mathbb E_{S_0\sim\rho_0,\,\pi,\,p}[G_0].\]
Discount sets the weight on later rewards. Bounded episodes can use \(\gamma=1\). For continuing tasks with bounded rewards, \(0\le\gamma<1\) guarantees a finite discounted sum.
What does a value tell us about the next move?
A state’s value is the expected return from that square
One step
Move one square north, south, east or west. Earn \(0\).
Hit a wall. Stay in place and earn \(-1\).
From A or B, any action takes the marked jump.
Many steps · Start in \(s\), follow \(\pi\), and discount future rewards by \(\gamma=0.9\).
\[v_\pi(s)=\mathbb E_\pi[G_t\mid S_t=s].\]
Split the return once to get the Bellman equation
1. Separate the first reward.\[G_t=R_{t+1}+\gamma G_{t+1}.\]
2. Average over trajectories starting in\(s\). \[\begin{aligned}
v_\pi(s)&=\mathbb E_\pi[G_t\mid S_t=s]\\
&=\mathbb E_\pi[R_{t+1}+\gamma G_{t+1}\mid S_t=s].
\end{aligned}\]
3. Average over the first action and outcome. From the next state \(s'\), the same policy gives expected return \(\mathbb E_\pi[G_{t+1}\mid S_{t+1}=s']=v_\pi(s')\).
One policy dominates another only if it does at least as well in every state
\[\pi'\succeq\pi\quad\Longleftrightarrow\quad v_{\pi'}(s)\ge v_\pi(s)\quad\text{for every state }s.\]
Strict improvement also requires a higher value in at least one state. Here, always north wins at A (\(24.4>8.8\)) and loses at the upper-left corner (\(-10<3.3\)). Neither policy dominates.
The upper-left corner’s value matches its Bellman average
\(\textcolor{#00776e}{\pi(a\mid C)}\)action probability · \(\textcolor{#a44316}{r_a}\)reward · \(\textcolor{#733c95}{\gamma}\)discount · \(\textcolor{#245395}{v_\pi(s'_a)}\)next-state value
\[\begin{aligned}
v_\pi(C)\approx{}&\textcolor{#00776e}{\tfrac24}(\textcolor{#a44316}{-1}+\textcolor{#733c95}{0.9}\cdot\textcolor{#245395}{3.3}) &&\text{north or west → C}\\
+{}&\textcolor{#00776e}{\tfrac14}(\textcolor{#a44316}{0}+\textcolor{#733c95}{0.9}\cdot\textcolor{#245395}{8.8}) &&\text{east → E}\\
+{}&\textcolor{#00776e}{\tfrac14}(\textcolor{#a44316}{0}+\textcolor{#733c95}{0.9}\cdot\textcolor{#245395}{1.5}) &&\text{south → S}\\
={}&3.3025.
\end{aligned}\]
Rounded to one decimal · \(3.3\), the value shown at C.
A fixed policy gives the value map one consistent answer
Intuition. Every square must agree with the average of its next reward plus its discounted successor value.
Fix the rules and the policy. This fixes the distribution of future rewards from each square.
Uniqueness. In a finite MDP with bounded rewards and \(0\le\gamma<1\), exactly one value map satisfies all the Bellman equations.
Action value lets us compare first moves from the same square
Both quantities measure expected discounted return. What do we fix before averaging?
Quantity
Inputs
First move
How to use it
\(v_\pi(s)\)
State
Draw from \(\pi\)
Evaluate a starting square. To compare moves, look ahead with known or estimated dynamics.
\(q_\pi(s,a)\)
State and action
Choose \(a\), then follow \(\pi\)
Compare moves directly at the same square, even with unknown dynamics.
In Gridworld, \(q_\pi(C,\mathrm{east})\) values east from the corner and the whole path afterward.
State value averages action values under the policy
Fix the first action and average the remaining trajectory: \[q_\pi(s,a)=\mathbb E[G_t\mid S_t=s,\ \text{take }a\text{ now, then follow }\pi].\]
Look one step ahead to compute an action value: \[q_\pi(s,a)=\sum_{s',r}p(s',r\mid s,a)\,[r+\gamma v_\pi(s')].\]
Let the policy choose to recover the state value: \[v_\pi(s)=\sum_a\pi(a\mid s)q_\pi(s,a).\]
Greedy action selection improves an evaluated policy
Choose a deterministic greedy move \(\pi'(s)\in\arg\max_a q_\pi(s,a)\) in every state.
1. Change one move. Take the new move, then follow the old policy: \[q_\pi(s,\pi'(s))=\max_a q_\pi(s,a)\ge v_\pi(s).\]
2. Keep using the improved policy. The same one-step improvement holds at every successor. Applying it there, and then at each later step, gives \[v_{\pi'}(s)=q_{\pi'}(s,\pi'(s))\ \ge\ q_\pi(s,\pi'(s)).\]
The two \(q\) terms fix the same first move. Their subscripts tell us which policy takes over afterward.
Evaluate the policy, improve its moves, then evaluate again
In each square: arrows give the policy (“all” means four equally likely moves). The number is the value of that policy.
Read left to right. Evaluate each map → choose greedy moves everywhere → evaluate again. At the lower-right corner the value rises from \(-1.98\) to \(10.89\) to \(11.67\).
Two ways to choose an optimal move
\[v_*(s)=\max_a q_*(s,a).\]
From optimal action values\(q_*\)
\[\pi_*(s)\in\arg\max_a q_*(s,a).\]
At the upper-left corner, look up each move’s value. East scores 21.98, north and west 18.78, and south 17.80. Choose east.