↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Loading the recording…

Planning when the rules are known

Reinforcement learning is about an agent that acts, sees what happens and gets rewards, and wants as much reward as it can collect. Before any learning, there is a simpler problem: if you already know the rules of the world exactly, what is the best way to act? That is planning, and value iteration is its oldest algorithm.

The world is a Markov decision process: states , actions , and for each pair a probability of landing in each next state with a reward . Here the states are the 64 cells of Gymnasium's FrozenLake 8×8: start at S, reach G for a reward of 1, and a hole H ends the episode with nothing. Gymnasium ships the whole table of probabilities with the environment, so this page reads it directly and never has to guess.

Values and the Bellman equation

The value of a cell is the reward you can expect from there on if you act as well as possible, with each step's reward discounted by a factor (here 0.99) so that sooner is worth more. The best value satisfies the Bellman optimality equation: a cell is worth its best action, and an action is worth its immediate reward plus the discounted value of wherever it leads, averaged over where it might lead:

Value iteration turns the equation into an update. Start from everywhere, and compute from for all states at once (one sweep). The One Bellman backup panel shows this for the cell you click: each action's row lists the cells it can end in, their probability and their value after the previous sweep; the action's value is the weighted sum, and the new is the largest . The arrows on the grids are the actions that are best right now.

Value spreads one step per sweep

On the Deterministic map every move goes where it points. After sweep 1 only the cells next to G have a value; after sweep , exactly the cells within moves of G do, each worth less per extra move. The information travels backwards from the reward at one cell per sweep, and after 15 sweeps nothing changes: the start is worth , because the shortest path is 14 moves and only the last one pays.

On the Slippery map a move goes the way you chose only a third of the time, and to either side otherwise. Every backup now mixes three neighbours, values seep in more slowly, and the start first gets any value at sweep 14. The arrows change too. Near a hole the best action is often to point away from it, because then the two possible slips run along the hole instead of into it. Value iteration finds this on its own, with nothing but the table.

Why it converges

The backup is a contraction: two value tables that differ by at most anywhere differ by at most after one backup each. So the largest change in a sweep, the Bellman residual, shrinks roughly by per sweep, and the values converge to the one fixed point . The Bellman residual chart shows this on a log scale against the dashed line: the slippery map needs 516 sweeps to get below . The policy settles long before the values: the dashed line in the V(start) and the policy chart is the exact chance that each sweep's greedy policy reaches G, and on the slippery map it is at its final 89.4 % from sweep 128 on, while one nearly tied cell keeps switching its arrow until sweep 512. Stopping at a loose tolerance usually costs nothing.

What the policy does in the real environment

The final policies, run for real card plays each map's greedy policy for 1,000 seeded episodes in Gymnasium. On the slippery map it reaches G in 87.7 % of them, consistent with the exact 86.3 % chance of doing it within the environment's 200-step time limit, which the page computes from the same table. Run the deterministic map's shortest path on the slippery map instead and it succeeds once in 1,000 episodes: a plan is only as good as the model of the world it was made for.

The discount is part of the problem, not just a technicality. The How far ahead it looks: γ card solves the slippery map again at other values of . A short horizon ( = 0.9) values a quick risky route over a slow safe one and succeeds 74.9 % of the time; at = 0.999 the policy never falls in, but needs 117 steps on average and so often runs out of time.

From planning to learning

Value iteration comes from Richard Bellman's dynamic programming in the 1950s. It needs the full transition table and touches every state on every sweep, which is impossible for most interesting problems. The rest of this explainer removes those requirements one at a time: TD vs MC learns values from sampled experience without a table, DQN replaces the table of values with a neural network, PPO learns a policy directly, and AlphaZero brings planning back, as a search guided by a learned network.

Papers

  1. A Markovian Decision Process Richard Bellman · Journal of Mathematics and Mechanics 1957 Introduces the Markov decision process and the recursive equation for its optimal value that value iteration solves.
  2. The theory of dynamic programming Richard Bellman · Bulletin of the American Mathematical Society 1954 Bellman's overview of dynamic programming: the principle of optimality and solving for values by successive approximation, which is what each sweep does.
  3. Markov Decision Processes Martin L. Puterman · Wiley 1994 Puterman's Discrete Stochastic Dynamic Programming, the reference text on MDPs, with the contraction argument behind value iteration's convergence.
  4. Gymnasium: A Standard Interface for Reinforcement Learning Environments Mark Towers et al. · arXiv 2024 The library whose FrozenLake environment, and transition table, this page uses.
  5. Value Iteration Networks Aviv Tamar et al. · NeurIPS 2016 Builds value iteration's sweeps into a neural network as convolutions, so planning can be learned end to end.

See also