🎮 Reinforcement Learning · Lecture 3 of 21

The Bellman Equations: Recursive Structure of Value

Value functions satisfy recursive consistency conditions. We derive the Bellman expectation and optimality equations for V and Q, interpret backup diagrams, and solve a small MDP exactly with linear algebra.

The single most important equation in reinforcement learning expresses a simple idea: the value of where you are equals the reward you get now plus the (discounted) value of where you end up. Richard Bellman's recursive equations underpin dynamic programming, temporal-difference learning, Q-learning and deep RL alike.

From returns to recursion#

The return satisfies $G_t = R_{t+1} + \gamma G_{t+1}$. Taking expectations under a policy $\pi$ gives the Bellman expectation equation for $V^\pi$:

$$ V^\pi(s) = \sum_a\pi(a \mid s)\sum_{s', r}p(s', r \mid s, a)\Big[r + \gamma V^\pi(s')\Big] $$

and for $Q^\pi$:

$$ Q^\pi(s, a) = \sum_{s', r}p(s', r \mid s, a)\Big[r + \gamma\sum_{a'}\pi(a' \mid s')Q^\pi(s', a')\Big] $$

They are linked by $V^\pi(s) = \sum_a\pi(a \mid s)Q^\pi(s, a)$.

Backup diagram intuition: from a state, branch over actions (weighted by the policy), then over next states and rewards (weighted by the dynamics), and "back up" the values from the leaves to the root.

Solving the expectation equation exactly#

For a finite MDP with $n$ states, the Bellman expectation equation is a linear system. Writing $\mathbf{P}^\pi$ for the state-transition matrix under $\pi$ and $\mathbf{r}^\pi$ for expected immediate rewards:

$$ \mathbf{v}^\pi = \mathbf{r}^\pi + \gamma\mathbf{P}^\pi\mathbf{v}^\pi \quad\Longrightarrow\quad \mathbf{v}^\pi = (\mathbf{I} - \gamma\mathbf{P}^\pi)^{-1}\mathbf{r}^\pi $$

The matrix is invertible for $\gamma < 1$. Direct solution costs $O(n^3)$ — fine for small problems.

python
import numpy as np

# A 3-state chain: 0 -> 1 -> 2 (terminal). Policy moves right with prob 0.9, stays with 0.1.
P = np.array([[0.1, 0.9, 0.0],
              [0.0, 0.1, 0.9],
              [0.0, 0.0, 1.0]])
r = np.array([-1.0, -1.0, 0.0])        # expected reward per step from each state
gamma = 0.95
v = np.linalg.solve(np.eye(3) - gamma * P, r)
print("V^pi:", v.round(3))

# Check the Bellman equation holds
print(np.allclose(v, r + gamma * P @ v))

The Bellman optimality equations#

The optimal value functions $V^*(s) = \max_\pi V^\pi(s)$ and $Q^*(s, a) = \max_\pi Q^\pi(s, a)$ satisfy

$$ V^*(s) = \max_a\sum_{s', r}p(s', r \mid s, a)\Big[r + \gamma V^*(s')\Big] $$
$$ Q^*(s, a) = \sum_{s', r}p(s', r \mid s, a)\Big[r + \gamma\max_{a'}Q^*(s', a')\Big] $$

The expectation over actions is replaced by a maximum: an optimal agent picks the best action. These equations are non-linear (because of the max), so we solve them iteratively — value iteration, policy iteration, Q-learning.

Once $Q^*$ is known, the optimal policy is greedy: $\pi^*(s) = \arg\max_aQ^*(s, a)$. This is why so many algorithms focus on estimating $Q^*$.

Why iteration converges: contraction#

Define the Bellman optimality operator $(\mathcal{T}V)(s) = \max_a\sum p(s', r \mid s, a)[r + \gamma V(s')]$. For $\gamma < 1$, $\mathcal{T}$ is a $\gamma$-contraction in the max norm:

$$ \|\mathcal{T}V_1 - \mathcal{T}V_2\|_\infty \le \gamma\,\|V_1 - V_2\|_\infty $$

By the Banach fixed-point theorem, repeatedly applying $\mathcal{T}$ from any starting point converges to the unique fixed point $V^*$, with error shrinking by a factor $\gamma$ each iteration. This is the theoretical foundation of value iteration.

Bootstrapping#

The Bellman equations define values in terms of other values — estimates built on estimates. This is called bootstrapping. Dynamic programming and temporal-difference methods bootstrap; Monte Carlo methods do not (they wait for actual returns). Bootstrapping reduces variance and allows learning before an episode ends, but introduces bias when estimates are wrong — a trade-off at the heart of RL algorithm design.

JA
Written by

Janin A Apurba

B.Sc. in CSE, AUST · Advanced ICT Officer, CNRS-UNHCR. Teaching AI, ML and Deep Learning to the next generation of engineers and researchers.

Keep learning

Related lectures

🎮 Reinforcement Learning

Markov Decision Processes: The Mathematical Framework of RL

MDPs formalise sequential decision making under uncertainty. We define states, actions, transition probabilities, rewards and discounting, discuss the Markov property, episodic vs continuing tasks, and partial observability.

Intermediate⏱ 5 min#222
🎮 Reinforcement Learning

Dynamic Programming: Policy Evaluation, Policy Iteration and Value Iteration

When the MDP model is known, dynamic programming computes optimal policies exactly. We implement iterative policy evaluation, policy improvement, policy iteration and value iteration on a gridworld, and discuss their limits.

Intermediate⏱ 5 min#224
🎮 Reinforcement Learning

Introduction to Reinforcement Learning: Learning by Interaction

Reinforcement learning studies agents that learn to act from rewards. We define the agent–environment loop, rewards, returns, policies and value functions, contrast RL with supervised learning, and map the field.

Beginner⏱ 5 min#221