Values and Policy Learning (continued)

ECE 57000 — November 30, 2026

David I. Inouye

Values carry future rewards into the next decision

  • Last meeting: given a model, look ahead to evaluate a move.
  • Today: given experience, estimate values and improve a policy.
  • Next question: how far should one batch of rewards move the policy?

What does a value tell us about the next move?

A state’s value is the expected return from that square

\[v_\pi(s)=\mathbb E_\pi[G_t\mid S_t=s].\]

Gridworld with arrows from A to A prime and B to B prime.

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

Split the return once to get the Bellman equation

Split each trajectory’s return into its first reward and the return that follows: \[G_t=R_{t+1}+\gamma G_{t+1}.\]

Average over the first action and the outcome it produces: \[v_\pi(s)=\sum_a \underbrace{\pi(a\mid s)}_{\text{choose a move}} \sum_{s',r}\underbrace{p(s',r\mid s,a)}_{\text{observe an outcome}} \big[r+\gamma v_\pi(s')\big].\]

Once the next state is known, its value summarizes the rest of the trajectory.

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.\]

Gridworld jump rules followed by two labeled maps of state values under uniform random and always north policies.

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

\[\textcolor{#245395}{v_\pi(C)}=\sum_a \textcolor{#00776e}{\pi(a\mid C)}\big[\textcolor{#a44316}{r_a}+\textcolor{#733c95}{\gamma}\,\textcolor{#245395}{v_\pi(s'_a)}\big].\]

Uniform-policy value map with the upper-left corner C and its east and south neighbors labeled E and S.

\[\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.

Three full Gridworld maps showing uniform actions and values, followed by two greedily improved policies and their reevaluated values.

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.

From optimal state values \(v_*\) and the model

\[\begin{aligned} h(s,a)&=\sum_{s',r}p(s',r\mid s,a)\,[r+\gamma v_*(s')],\\ \pi_*(s)&\in\arg\max_a h(s,a). \end{aligned}\]

East reaches A. Its score is \(0+0.9(24.42)\approx21.98\), the largest of the four.

Which information lets us choose an optimal move?

You know every optimal state value. Two moves can reach different squares.

What else lets you rank those moves?

A. Each move’s reward and next-state distribution

B. The frequency with which each move was tried

C. The highest value of any reachable square

A. Average each move’s immediate reward plus discounted successor value over its possible outcomes.

How can experience supply the values?

Monte Carlo averages observed returns from a square

\[v_\pi(s)=\mathbb E_\pi[G_t\mid S_t=s]\ \approx\ \frac{1}{N(s)}\sum_{i=1}^{N(s)}g^{(i)}(s).\]

First-visit Monte Carlo

  • \(N(s)\) counts episodes that visit \(s\).
  • \(g^{(i)}(s)\) is the observed discounted return after the first visit to \(s\) in the \(i\)th such episode.
  • Independent episodes under \(\pi\) sample possible futures from \(s\). Their mean estimates the conditional expectation.

Toy grid · two episodes · \(\gamma=0.9\)

  1. \(C\xrightarrow{0}B\xrightarrow{10}\text{end}\)
    \(g^{(1)}(C)=0+0.9(10)=9\)
  2. \(C\xrightarrow{0}B\xrightarrow{2}\text{end}\)
    \(g^{(2)}(C)=0+0.9(2)=1.8\)

\(N(C)=2,\quad\hat v(C)=(9+1.8)/2=5.4\).

Tradeoff. Full returns use observed rewards. Updates wait for the episode to finish.

TD updates after one move using a predicted continuation

Evaluate the policy generating the data

\[\underbrace{y=r+\gamma\hat v(s')}_{\text{one-step target}}\] \[\hat v(s)\leftarrow\hat v(s)+\alpha[y-\hat v(s)].\]

  • Read the estimate at the next state \(s'\).
  • Move the current state estimate a fraction \(\alpha\) of the gap toward \(y\).

Same first move · \(C\xrightarrow{0}B\)

Suppose \(\hat v(C)=2\), \(\hat v(B)=8\).

\[y=0+0.9(8)=7.2.\] \[\hat v(C)\leftarrow 2+0.25(7.2-2)=3.3.\]

Only the entry for \(C\) changes.

Experience only. Sample under \(\pi\); its probabilities and the transition model are unnecessary.

Tradeoff. Update immediately, but error in \(\hat v(s')\) enters the target.

Q-learning learns action values for greedy control

Learn to choose a move

\[y=r+\gamma\max_{a'}\hat q(s',a')\] \[\hat q(s,a)\leftarrow\hat q(s,a)+\alpha[y-\hat q(s,a)].\]

  • Compare all estimated moves at \(s'\).
  • Update the entry for the move actually taken at \(s\).

Same first move · east from \(C\) to \(B\)

At \(B\), suppose the two moves score \(6\) and \(10\). At \(C\), east scores \(2\).

\[y=0+0.9\max(6,10)=9.\] \[\hat q(C,\mathrm{east})\leftarrow 2+0.25(9-2)=3.75.\]

The target uses \(10\) even if exploration next tries the move valued at \(6\).

From experience to control. Explore to collect transitions. Each update uses the sample and the Q table alone. Choose greedily from the learned values.

Optimizing the policy directly

Give the policy parameters of its own

  1. Value-based control. Estimate values, then choose a policy \(\pi\). With state values \(v(s)\), look one move ahead using the model. With action values \(q(s,a)\), choose a highest-valued move directly.

  2. Direct policy optimization. Learn the policy \(\pi_\theta(a\mid s)\) directly. Sampled returns guide changes to \(\theta\) without requiring a separate value estimate.

  3. Actor–critic. Learn both \(\pi_\theta\) (the actor) and \(v_\phi\) (the critic). The critic estimates the return expected from each state, giving the actor a baseline that can reduce noise in its updates.

Changing the policy changes which trajectories we average

For a finite episode \(\tau=(s_0,a_0,r_1,\ldots,s_T)\), let \(G_0(\tau)\) be its discounted return. Policy objective. Maximize expected return from starting states drawn from \(\rho_0\): \[J(\theta)=\mathbb E_{\tau\sim p_\theta}[G_0(\tau)]=\sum_\tau p_\theta(\tau)G_0(\tau).\]

\[p_\theta(\tau)=\underbrace{\rho_0(s_0)}_{\text{start}}\prod_{t=0}^{T-1}\underbrace{\pi_\theta(a_t\mid s_t)}_{\text{policy}}\,\underbrace{p(s_{t+1},r_{t+1}\mid s_t,a_t)}_{\text{environment}}.\]

A recorded trajectory has a fixed return. Its probability of occurring changes with \(\theta\).

The distribution inside the expectation changes with the policy

For a fixed trajectory, \(G_0(\tau)\) is fixed. Differentiating only its return would miss the change in trajectory probability.

The log-derivative trick · On trajectories with positive probability, \[\nabla_\theta\log p_\theta(\tau)=\frac{\nabla_\theta p_\theta(\tau)}{p_\theta(\tau)} \quad\Longrightarrow\quad \nabla_\theta p_\theta(\tau)=p_\theta(\tau)\nabla_\theta\log p_\theta(\tau).\]

\[\begin{aligned} \nabla_\theta J(\theta) &=\nabla_\theta\sum_\tau p_\theta(\tau)G_0(\tau)\\ &=\sum_\tau [\nabla_\theta p_\theta(\tau)]G_0(\tau)\\ &=\sum_\tau p_\theta(\tau)[\nabla_\theta\log p_\theta(\tau)]G_0(\tau). \end{aligned}\]

The leading \(p_\theta(\tau)\) gives the sampling distribution for the gradient.

Only the policy factors contribute to the trajectory gradient

Taking the log turns the trajectory product into a sum: \[\log p_\theta(\tau)=\underbrace{\log\rho_0(s_0)}_{\text{fixed}} +\sum_t\Big[\log\pi_\theta(a_t\mid s_t)+\underbrace{\log p(s_{t+1},r_{t+1}\mid s_t,a_t)}_{\text{fixed environment}}\Big].\]

For this recorded path, only the action probabilities depend on \(\theta\): \[\nabla_\theta\log p_\theta(\tau)=\sum_t\nabla_\theta\log\pi_\theta(a_t\mid s_t).\]

\[\nabla_\theta J(\theta)=\mathbb E_{\tau\sim p_\theta}\!\left[G_0(\tau)\sum_t\nabla_\theta\log\pi_\theta(A_t\mid S_t)\right].\]

For ascent: sample a return and differentiate the policy. The update needs a gradient estimate and can proceed without evaluating \(J(\theta)\) exactly.

Sample trajectories to estimate the ascent direction

  1. Run the current policy for \(N\) episodes. Record states, actions and rewards.
  2. For each episode, weight its action log-probability gradients by its return.
  3. Average and take an ascent step: \[\widehat g=\frac1N\sum_{i=1}^N G_0^{(i)}\sum_t\nabla_\theta\log\pi_\theta(a_t^{(i)}\mid s_t^{(i)}), \qquad \theta\leftarrow\theta+\alpha\widehat g.\]

The batch mean of the returns estimates \(J\). The weighted gradients estimate how \(J\) changes.