Part XVI — Reinforcement Learning: Bandits, MDPs, Policy Gradients & PPO · Chapter 3

Value functions & Bellman equations

Hook

The last chapter's Bellman equation was conditioned on a policy someone else handed you: Vπ(s)V^\pi(s), the value if you follow π\pi. But nobody handed the gridworld's agent "always right" — it has to be discovered. That means asking a sharper question: not "how good is this policy," but "how good can any policy possibly make this state?"

Intuition
S0
S1
S2
S3
V*(0) = 6.20 — best action is "right"

Step through each state and compare its two available one-step lookaheads, Q(s,left)Q^*(s,\text{left}) and Q(s,right)Q^*(s,\text{right}) — the value of taking that action once, then acting optimally forever after. Whichever is larger is V(s)V^*(s), the optimal value of that state. There's no policy input here at all: the "best possible" value falls straight out of comparing the actions.

Formalize

The optimal value function V(s)V^*(s) is the best expected discounted return achievable from ss, over every possible policy. It satisfies the Bellman optimality equation — the same recursive shape as before, but with a max\max over actions replacing a policy's fixed choice:

V(s)=maxa[R(s,a)+γV(P(s,a))]V^*(s) = \max_a \Big[ R(s,a) + \gamma\, V^*\big(P(s,a)\big) \Big]
  • V(s)V^*(s) — the optimal value of state ss: the best expected discounted return any policy can achieve from here.
  • aa — a candidate action, ranged over by the max\max.
  • R(s,a)R(s,a) — the immediate reward for taking action aa from state ss.
  • γ\gamma — the discount factor.
  • P(s,a)P(s,a) — the state landed in after taking action aa from ss.

It's often useful to split the bracketed quantity out into its own object, the optimal action-value function:

Q(s,a)=R(s,a)+γV(P(s,a))Q^*(s,a) = R(s,a) + \gamma\, V^*\big(P(s,a)\big)
  • Q(s,a)Q^*(s,a) — the value of taking action aa from ss once, then behaving optimally forever after.
  1. V* and Q* are two views of the same thing

    V(s)=maxaQ(s,a)V^*(s) = \max_a Q^*(s,a) — the optimal value of a state is just the best action-value available from it. Every VV^* number in this chapter is secretly a max\max over two QQ^* numbers.

  2. The optimal policy falls out for free

    Once QQ^* is known, the optimal policy is simply π(s)=argmaxaQ(s,a)\pi^*(s) = \arg\max_a Q^*(s,a) — no separate search required. This is exactly the relationship Q-learning exploits: learn QQ^*, and a policy comes along for free.

Play
S0V*=6.2
S1V*=8.0
S2V*=10.0
S3V*=0.0
the optimal value function — the best possible expected return from each state

These are the exact same numbers the MDP chapter computed for "always right" — 6.2,8,10,06.2, 8, 10, 0. That's not a coincidence: with only two actions and a reward structure where moving away from the goal is strictly worse, "always right" already achieves the best possible value from every state. Vπ=VV^\pi = V^* here only because π\pi happened to already be optimal.

Worked example

Using the already-known VV^* values V(3)=0V^*(3){=}0, V(2)=10V^*(2){=}10, V(1)=8V^*(1){=}8, V(0)=6.2V^*(0){=}6.2 (from the previous chapter), check that the Bellman optimality equation actually holds at each state:

  1. State 2 — where the two actions disagree the most

    Q(2,right)=10+0.9(0)=10Q^*(2,\text{right}) = 10 + 0.9(0) = 10. Q(2,left)=1+0.9(8)=6.2Q^*(2,\text{left}) = -1 + 0.9(8) = 6.2. The max is 1010, exactly V(2)V^*(2) — and "right" is clearly the better action here, by 3.83.8.

  2. State 0 — furthest from the goal

    Q(0,right)=1+0.9(8)=6.2Q^*(0,\text{right}) = -1 + 0.9(8) = 6.2. Q(0,left)Q^*(0,\text{left}) bounces back to state 00 itself: 1+0.9(6.2)=4.58-1 + 0.9(6.2) = 4.58. The max is 6.26.2, exactly V(0)V^*(0).

  3. The equation is a consistency check, not a solving method

    Every one of these checks passes only because the correct VV^* values were already plugged in on the right-hand side. Nothing here computed VV^* from scratch — that's the job of the next chapter.

Checkpoint

Step forward until you reach the state whose optimal value V*(s) equals exactly 10.

S0
S1
S2
S3
V*(0) = 6.20
Step forward to try it
Summary
V(s)=maxaQ(s,a),Q(s,a)=R(s,a)+γV(P(s,a))V^*(s) = \max_a Q^*(s,a), \qquad Q^*(s,a) = R(s,a) + \gamma\, V^*\big(P(s,a)\big)

The Bellman optimality equation defines what VV^* and QQ^* are — a fixed point that the true optimal values must satisfy — but it doesn't by itself say how to find them when they aren't already known. Here, they were simply recognized by re-using a policy already proven optimal. The next chapter shows the general algorithm: start from a wrong guess for every state's value, and keep applying this exact equation as an update rule until it stops changing anything.