Markov decision processes and Bellman equations
The language of reinforcement learning: states, actions, rewards, returns, policies and value functions.
Animated explanation
The idea
In reinforcement learning nobody gives the right answers. An agent acts in an environment, receives rewards, and must learn which actions lead to the most reward over time. A chess move that loses a pawn now may win the game later.
A Markov decision process makes this precise: states , actions , transition probabilities , rewards and a discount . A policy says what to do in each state. The value is the expected discounted return from when following .
The key insight, due to Bellman, is that values are recursive: the value of a state is the immediate reward plus the discounted value of the next state. Almost every RL algorithm is a way of solving or approximating that recursion.
The Markov property
The next state and reward depend only on the current state and action, not on the history: . If your observation doesn't have this property (a single video frame doesn't show velocity), extend the state (stack frames) or use a partially observable model.
State values and action values
is the value of being in . is the value of taking action in and then following . Knowing lets you act without a model: pick . The optimal values , satisfy the Bellman optimality equations, and any policy greedy with respect to is optimal.
Policy evaluation
For a fixed policy the Bellman expectation equation is a linear system in the unknowns : , so . For large state spaces we iterate the equation instead; because it is a -contraction, the iteration converges from any start.
The algorithm, step by step
- 1Define states, actions, , rewards and .
- 2Iterative policy evaluation: start with .
- 3Sweep: for each non-terminal , .
- 4Repeat until the largest change in a sweep is below a tolerance.
The maths
Return
Action value
Bellman expectation (matrix form)
Bellman optimality
Strengths and weaknesses
Strengths
- One framework for sequential decisions under uncertainty
- Bellman equations turn long horizons into one-step recursions
- Policy evaluation has exact and iterative solutions
Weaknesses
- Requires a Markov state
- Exact methods need the full model P and small state spaces
- Rewards must be designed carefully (agents exploit loopholes)
Reach for it when…
Check your understanding
Lambdian Lab
Returns and policy evaluation
The gridworld above the dashed line is provided (don't edit it).
- discounted_return(rewards, gamma): .
- evaluate_policy(policy, gamma, tol): iterative policy evaluation; policy is a dict state → action; return a dict state → value (terminals 0).
- evaluate_exact(policy, gamma): solve the linear system over the non-terminal states.