Skip to content

Value Functions & Bellman Equations

The core mathematics of RL — measuring how good states and actions are


State Value Function V(s)

The state value function Vπ(s) measures the expected return starting from state s and following policy π thereafter.

Vπ(s)=Eπ[GtSt=s]=Eπ[k=0γkRt+k+1St=s]

Where Gt is the return, γ[0,1] is the discount factor, and Eπ denotes expectation under policy π.

Think of Vπ(s) as the "score" of a state—how valuable it is to be there. A state near the goal has high value; a state near a trap has low value.

V(s) Heatmap Animation

PropertyDescription
Policy-dependentDifferent policies yield different value functions
BoundedVπ(s)[Rmin1γ,Rmax1γ]
UniqueFor a fixed policy, there exists a unique value function

Action Value Function Q(s, a)

The action value function Qπ(s,a) measures the expected return starting from state s, taking action a, and then following policy π.

Qπ(s,a)=Eπ[GtSt=s,At=a]

Q-values allow action selection without a model. Given Qπ(s,a) for all actions:

a=argmaxaQπ(s,a)

This is why Q-learning and DQN focus on learning Q-values directly.

V and Q Relationship

Vπ(s)=aπ(a|s)Qπ(s,a)Qπ(s,a)=R(s,a)+γsP(s|s,a)Vπ(s)

Bellman Expectation Equations

The Bellman equations express a recursive relationship: the value of a state depends on successor state values.

Derivation for V(s)

Starting from Vπ(s)=Eπ[GtSt=s] and expanding the return Gt=Rt+1+γGt+1:

Vπ(s)=Eπ[Rt+1+γGt+1St=s]

By linearity and the law of total expectation:

Vπ(s)=aπ(a|s)sP(s|s,a)[R(s,a,s)+γVπ(s)]

Bellman Expectation Equation for Q

Qπ(s,a)=sP(s|s,a)[R(s,a,s)+γaπ(a|s)Qπ(s,a)]

Bellman Backup Diagram

Bellman Backup Diagram

The backup diagram shows how value "flows back" from successor states. White nodes = states; black nodes = state-action pairs.


Bellman Optimality Equations

The optimal value functions V(s) and Q(s,a) represent the best possible values achievable by any policy.

V(s)=maxπVπ(s)=maxaQ(s,a)

Bellman Optimality for V:*

V(s)=maxasP(s|s,a)[R(s,a,s)+γV(s)]

Bellman Optimality for Q:*

Q(s,a)=sP(s|s,a)[R(s,a,s)+γmaxaQ(s,a)]

The key difference from expectation equations: instead of averaging over actions, we take the maximum.

Relationship Between V* and Q*

V(s)=maxaQ(s,a)andQ(s,a)=R(s,a)+γsP(s|s,a)V(s)

Once we have Q, the optimal policy is: π(s)=argmaxaQ(s,a)


Policy Evaluation and Policy Improvement

Policy Evaluation

Compute Vπ(s) by iteratively applying the Bellman expectation equation:

Vk+1(s)=aπ(a|s)sP(s|s,a)[R(s,a,s)+γVk(s)]

Policy Improvement

Given Vπ, construct a better policy by acting greedily:

π(s)=argmaxasP(s|s,a)[R(s,a,s)+γVπ(s)]

Policy Improvement Theorem: Qπ(s,π(s))Vπ(s)Vπ(s)Vπ(s)

Policy Iteration

1. Initialize V(s), pi(s) arbitrarily
2. Repeat until policy stable:
   a. Policy Evaluation: Compute V^pi
   b. Policy Improvement: pi' = greedy(V^pi)
   c. If pi' = pi, return (optimal); else pi <- pi'

Value Iteration Algorithm

Value iteration combines evaluation and improvement into a single update:

Vk+1(s)=maxasP(s|s,a)[R(s,a,s)+γVk(s)]

Convergence

The Bellman optimality operator is a contraction mapping:

Vk+1VγVkV

Convergence is geometric with rate γ.

AspectValue IterationPolicy Iteration
UpdateSingle sweepFull evaluation
ConvergenceAsymptoticExact in finite steps
Per-iteration costLowerHigher

Value Iteration Convergence Animation


Summary Comparison

ConceptFormulaKey Insight
Vπ(s)Eπ[GtSt=s]Expected return from state under policy
Qπ(s,a)Eπ[GtSt=s,At=a]Expected return from state-action under policy
V(s)maxaQ(s,a)Best achievable value from state
Q(s,a)R+γmaxaQ(s,a)Best achievable value from state-action
Bellman ExpectationAverage over actionsEvaluates a given policy
Bellman OptimalityMax over actionsFinds optimal policy

Interview Questions

Q1: When would you prefer learning V(s) vs Q(s,a)?

Answer:

Prefer Q when:

  • Model-free learning (unknown transitions)
  • Need direct action selection: a=argmaxaQ(s,a)
  • Off-policy learning (Q-learning works with any data)

Prefer V when:

  • Model is known (derive Q from V cheaply)
  • Large action spaces (V has lower memory)
  • Actor-Critic methods (critic often estimates V)

Key tradeoff: Q enables model-free action selection but requires |S|×|A| storage vs |S| for V.


Q2: Derive the Bellman equation and explain its computational benefit.

Answer:

From Vπ(s)=Eπ[GtSt=s], expand Gt=Rt+1+γGt+1:

Vπ(s)=aπ(a|s)sP(s|s,a)[R+γVπ(s)]

Computational benefit: Instead of simulating infinite trajectories (Monte Carlo), Bellman transforms this into a system of n linear equations solvable in O(n3) or O(n2k) via iteration. This is dynamic programming.


Q3: Why does value iteration converge?

Answer:

The Bellman optimality operator is a contraction: TVTVγVV

By Banach fixed-point theorem, repeated application converges to the unique fixed point V.

Convergence rate: Error decreases as γk. At γ=0.9, ~44 iterations for 100x reduction; at γ=0.99, ~460 iterations.

Stopping criterion: When maxs|Vk+1(s)Vk(s)|<ϵ, we have VkV<ϵ1γ.


Quick Reference Card

+============================================================================+
|                     VALUE FUNCTIONS CHEAT SHEET                            |
+============================================================================+
| VALUE FUNCTIONS                                                            |
|   V^pi(s) = E_pi[G_t | S_t = s]       Q^pi(s,a) = E_pi[G_t | S_t=s, A_t=a] |
|   V*(s) = max_a Q*(s,a)               Q*(s,a) = R + gamma max_a' Q*(s',a') |
+----------------------------------------------------------------------------+
| BELLMAN EQUATIONS                                                          |
|   Expectation: Average over actions   Optimality: Max over actions         |
|   V = sum_a pi(a|s) [R + gamma V']    V* = max_a [R + gamma V*']           |
+----------------------------------------------------------------------------+
| ALGORITHMS                                                                 |
|   Policy Iteration: Evaluate -> Improve -> Repeat (exact convergence)      |
|   Value Iteration: V_k+1 = max_a [R + gamma V_k] (asymptotic convergence) |
+----------------------------------------------------------------------------+
| CONVERGENCE: ||V_k - V*|| <= gamma^k ||V_0 - V*||                         |
|   gamma=0.9: ~44 iters for 100x reduction | gamma=0.99: ~460 iters        |
+============================================================================+

Key Takeaways

  1. Value functions quantify long-term rewardV(s) for states, Q(s,a) for state-action pairs. They convert the complex problem of sequential decision-making into a tractable optimization.

  2. Bellman equations provide recursive structure — The value of a state depends only on immediate rewards and values of successor states. This enables dynamic programming solutions.

  3. Expectation vs. Optimality — Bellman expectation equations average over a policy; Bellman optimality equations maximize. This distinction separates policy evaluation from policy optimization.

  4. Value iteration is a contraction — Convergence is guaranteed with rate γ. Lower discount factors mean faster convergence but more myopic policies.

  5. Q-values enable model-free learning — By learning Q directly, algorithms like Q-learning can find optimal policies without knowing transition probabilities.

These concepts form the mathematical foundation for both tabular RL methods and modern deep RL approaches like DQN, A3C, and PPO.