Interactive figures
Every figure in the track. Each one is a small experiment: drag, slide, and watch the numbers. The link under each figure takes you to the lesson that explains it.
Lesson 1 · MDPs and Bellman equations
Predict, then press Step. Before each step, guess the action (orange), the reward (aqua) and the next state. The table adds up . One episode gives one random return. Press Average 1000 episodes: the mean of many returns from H is close to the exact value (blue), which comes from a linear solve (section 3). Switch the policy to "clean in H, charge in L" and compare the values.
Move . The aqua bars are the weights . The blue curve adds them up and approaches (the violet line). The dashed line marks the effective horizon . Notice that looks 100 steps ahead, ten times more than .
Move the sliders to change the policy. The orange edges are the actions with probabilities ; the aqua labels are the transition probabilities and rewards; the blue numbers are the values. Each is "reward now plus times the average next value", and is the -average of the values. Then switch to max to see the optimality equation: the average over actions becomes a max (the arc).
Click a cell to change its action (random, then ↑, →, ↓, ←, then random again). The values are recomputed by one linear solve; darker blue means a higher value. For the random policy, the cell next to a corner has : on average a random walk needs 14 steps. The side panel shows the backup of the selected cell: is the -average of the values. Now make two neighbouring cells point at each other: those two states never end, so their value is , and so is the value of every state from which the random policy can walk into them.
Lesson 2 · Policy and value iteration
Press "Evaluate: one sweep" a few times, then "Improve (greedy)". The blue values are ; the orange arrows are the policy (several arrows = a tie, the agent picks one of them at random). After three sweeps the greedy arrows are already optimal. Then try "Run policy iteration" and "Run value iteration", and the other worlds: in the slippery world, raise the slip and watch the policy move away from the pit; in the cliff world, the safe path moves up when the slip is above 0.
Drag the two points. The robot vacuum has two states, so a value function is a point . The blue and the violet are two guesses; the arrows show where sends them. The dashed square around has half-width , so lies on its edge. The shaded square around is times smaller, and always lands inside it. Press "Apply T" a few times: both points move to the same fixed point . The small chart is the max lemma in state H: the gap between the two maxima is never larger than the largest vertical gap.
Move and predict the slope. On a log scale, the true error (blue) follows the theorem's line (violet, dashed); the slope is . The grey dashed line is the stopping-rule bound, which you can compute without knowing . The orange line marks the iteration from which the greedy policy is optimal: on the 5×5 grid with this is iteration 29, while the value error is still about 1.15.
Predict, then press "Step both" a few times, and then "Run both to the end". Each step is one iteration of each method. On the 5×5 grid, policy iteration finishes after 5 evaluations; value iteration needs 154 sweeps to reach , but its greedy policy is optimal much earlier. The cost line uses the dense model of the table.
Lesson 3 · Bandits and exploration
Pull the arms by hand first (the buttons 1–4), about 20 times, and guess which arm is best; then press Reveal. Then press Reset and let an algorithm play. The blue dot is the sample mean ; in UCB1 mode the yellow bar above it is the exploration bonus, and its top is the index that UCB1 maximizes. In Thompson mode the yellow diamond is the posterior sample . The last pulled arm is orange. After Reveal, the aqua dashes are the true means and the chart shows the cumulative regret. Notice how the algorithms stop pulling the bad arms, but never completely.
Move and . The yellow curve is the bonus for the chosen ; grey curves are . Doubling divides the bonus by ; multiplying by 10 changes it only a little. The number line shows the interval and the index. Switch to Hoeffding vs exact to compare the bound with the exact tail for fair coin flips: for , the bound is 0.2019 and the true probability is 0.0577. The bound is loose, but it holds for every reward distribution on .
Press "Sample once" a few times, then "Sample 100 times". The curves are the posteriors Beta(6, 2) (arm 1: 5 successes, 1 failure) and Beta(3, 3) (arm 2: 2 and 2). Each draw marks one per arm; the orange line is the largest, and that arm is pulled. The frequency of arm 1 approaches the exact . Try more data (same means, about ten times the pulls): the posteriors narrow, and arm 2 almost never wins.
Before you press Run, predict which curves keep growing like a straight line and which bend. The mean regret over 100 runs is shown for four Bernoulli arms with means 0.2, 0.4, 0.6, 0.8 and . Greedy and fixed ε-greedy grow linearly (greedy leaves the chart); UCB1, decaying ε and Thompson sampling bend. Switch the axis to logarithmic: a curve that grows like becomes a straight line there. Thompson sampling is almost straight already; UCB1 still bends upward at this horizon, because its behaviour starts late (its constant is large). The table divides the final regret by .
Lesson 4 · Monte Carlo and TD prediction
Choose a method and press Step. The blue bars are the current values (all start at 0.5), the dashed lines the true values, and the orange dot the agent. The default episode is C → B → C → D → E → right end. With TD(0), every TD error before the last step is 0, so only E moves. With MC, nothing moves until the end; then every visited state moves toward the return 1. With TD(λ), the orange trace bars show which states share the final TD error. Then switch to learning curves (mean of 100 runs) and look for the best α of each method: the best TD(0) curve ends lower than the best MC curve.
Predict for each method, then press Run batch updates. The diagram is the maximum-likelihood model estimated from the data. The chart shows over sweeps for batch MC and batch TD, and , which both methods share. Change the counts or the reward of the A episode and predict again; the preset Sutton & Barto Ex. 6.4 gives 0 against 3/4.
Move λ and the number of steps until the episode ends. Violet bars are the weights of the n-step returns (they bootstrap); the aqua bar is the weight of the full return . With λ = 0.5 and the end 3 steps after , the weights are 0.5, 0.25 and 0.25. Set λ = 0 and λ = 1 to see the two ends: TD(0) and Monte Carlo.
Step through the episode C → B → C → D → E → +1. The orange bars are the traces; C was visited twice, so its bar has two pieces (the older visit is lighter). All TD errors are 0 until the reward arrives; then each state moves by (blue numbers). Predict first: at the last step, is larger or smaller than ? Then move λ: at λ = 0 only E moves; at λ = 1 every visit counts fully.
Lesson 5 · SARSA and Q-learning
Switch the next action and move the sliders. The blue bars are and , with their ε-greedy probabilities in orange. The three targets are SARSA, expected SARSA and Q-learning. Only the SARSA target changes when you switch . Press "Sample a′ 200 times": the dashed line, the mean of many SARSA targets, lands on the expected SARSA target. Set and expected SARSA becomes Q-learning.
Predict the two paths first, then press "Train 500 episodes". The grid shows run 1 of the selected method: the shading is (blue, darker is higher), the small arrow is the greedy action, and the orange line is the greedy path from S. The chart shows the online return, the total reward per episode while the agent explores (10 runs, smoothed). Compare Q-learning, SARSA and expected SARSA: which one has the shortest greedy path, and which one collects the most reward? Then set and train again.
Predict first, then press "Repeat 1000 times". Ten actions all have true value 0. Each estimate is the mean of samples of . The orange histogram is the single estimator : its mean is about , not 0. The violet histogram is the double estimator: choose with the blue set, read the value from the independent violet set. Its mean is 0. Make (no choice, no bias) and make large (less noise, less bias).
Lesson 6 · Function approximation and DQN
Predict which staircase fits better, then press "Train 1000 episodes" a few times. The dashed black line is the true value . The aqua staircase is gradient Monte Carlo, the violet one semi-gradient TD(0), both trained on the same episodes. The grey curve at the bottom is the on-policy distribution (the walk spends most time in the middle). "Show the limits" draws where each method converges. Notice where TD is worse: at the ends, where is small.
Move across , then switch the updates to "both states". The chart shows on a log scale over 100 episodes, starting from . With only the first state updated (magenta), grows for every , even though is exactly right. With on-policy updates (blue), the second state is also updated, towards its own target 0, with gradient . This pulls back, and it shrinks to 0.
Press "Next step" six times to walk through one iteration of DQN: act, store, sample, compute targets with the target network, take a gradient step on the online network, and copy. Then switch to "moving target". There, a linear Q-network with two weights must learn the values of two states, (aqua), from off-policy data, and the second state's feature doubles the first one's weight. The blue path shows the values over 1000 updates; the violet dots are the regression targets after each copy. Predict first: with (no target network), do the values reach the aqua point? Then try larger , and on-policy data.
Press "Repeat 1000 times". Ten actions all have true value 0; the online and target networks have independent errors of size . The orange histogram is the DQN target (the max of the target network): its mean is about . The violet histogram is the double DQN target (target network at the online network's argmax): its mean is about 0.
Press "50 steps" with , then set and press again. One state, three actions, a one-step decision (the target is the reward). The dashed lines are the true values . The data contain only (grey coverage bars); the magenta actions never appear in the data. The values start at : the network's guess for is an extrapolation error, and the greedy action (orange outline) is . Plain offline Q-learning () never changes it. The CQL penalty pushes down and up until is greedy.
Lesson 7 · Policy gradients and REINFORCE
Drag the logits , then press Sample. The bars are the policy π and the rewards . The plane shows gradient vectors (all of them have entries that add up to 0, so they lie in a plane). Each orange point is one possible REINFORCE sample; its area is its probability . The black arrow is the exact gradient , and the dashed orange arrow is the mean of your samples. Move the baseline : the points move, the black arrow does not, and the variance in the readout changes.
Press "Sample 20 actions". The aqua curve is the reward , and the orange area is the policy . Each orange dot is a sampled action on the reward curve. Under the axis, each violet arrow is that sample's push on , . Then press "Gradient step" a few times and watch climb to the peak. Turn on the baseline : the arrows change a lot, their mean does not.
Click a step . The top row shows the actions of one episode, the second row the rewards. The bracket shows which rewards multiply the score of the selected step. In the "full return" mode all rewards count; in the "reward-to-go" mode the rewards before are dropped (step 4 of the proof: their term has mean 0). In this toy problem every step is an independent coin with and reward . The chart shows the exact variance of the three estimators. Their means are all equal.
Predict the best , then press "Run 100 episodes" a few times. The cells show the corridor; X has switched actions. The first chart is ; the aqua line marks . Each dot is the current policy of one REINFORCE run, and the second chart shows over episodes: orange runs use no baseline, blue runs use a learned constant baseline. All runs start at . Raise the step size to see the runs without a baseline become unstable first.
Lesson 8 · Actor-critic, GAE and SAC
Press "1 step (slow)" a few times, then "100 steps". The robot vacuum of lesson 01: the boxes show the actor's policy (orange bars) and the critic's values (blue bars) in the states H and L. The slow step shows the five phases of one update. The charts show and against the optimal values (dashed), and the probabilities of the optimal actions. Watch in the first 100 steps: the critic starts at , so "clean" (reward 1 now) looks better than "charge" (reward 0 now) until the critic learns that is large.
Move the critic error and the reward noise , then find the best . A chain of 20 steps, each with a reward , . The critic is wrong by in every state. The top chart shows the error of 40 sampled estimates (the orange dots are at the current setting) and their mean, the bias. The bottom chart shows bias², variance and their sum, the mean squared error, for every . Switch to "k-step" to see the same trade-off for . A perfect critic favours small ; a bad critic and quiet rewards favour near 1.
Press "Step back" until all steps are computed. The data is the worked example below: rewards, values, done flags, and the bootstrap value on the right. Each step shows and in violet; the violet arrow carries back, and it is cut at a dashed line where an episode ends. Click a done flag to toggle it. Make the last step terminal: is no longer used.
Move the temperature . The blue bars are the action values , the orange bars the soft-greedy policy . The violet line is the soft value , the dashed line is . The chart shows the entropy of (it rises to ) and how far is above . The readout checks . Edit the values to see that only their differences, divided by , shape .
Lesson 9 · PPO and RL for LLMs
Predict, then slide. Move the step size along the policy gradient. The blue curve is the true improvement , computed exactly. The violet curve is the surrogate , the improvement predicted from old data. Near they agree (same value, same slope). Far away the surrogate keeps rising while the true improvement falls below zero. The lower chart shows the KL from the old policy (solid) and its Fisher approximation (dashed). The shaded band is the trust region .
Drag the orange point along the curve (or use the slider), then switch the sign of . The solid orange curve is PPO's per-sample objective ; the dashed line is the unclipped . In the magenta region the curve is flat, so the gradient is zero. Notice that the flat part is only on one side: a sample that moved the wrong way keeps its full gradient.
Pick a response and move the sliders. The tree shows a toy model that writes two tokens from . Each edge shows the policy probability and the reference probability . For the chosen response, the panel lists the per-token log-ratios, the KL rewards and the reward-model score. Check that the per-token rewards add up to , and that the sequence KL equals the sum of the per-token KLs.
Move and drag the reward dots. Grey bars are ; orange bars are the optimum ; the aqua dots are the rewards . The lower chart shows, for every , the expected reward (aqua) and (magenta). Predict first: what happens to when ? Can put mass on a response with ?
Drag the reward bars, then compare the advantages. The aqua bars are the rewards of responses to one prompt. Below are three advantages per response: (grey), RLOO and GRPO. Try "one correct of four" and "all equal": when every reward is the same, every advantage is 0 and the prompt gives no learning signal.
Lesson 10 · Model-based RL and AlphaZero
Predict, then run two episodes. With , how many cells get an arrow (a value above 0) after episode 2? With ? Run two episodes for each and count. Then press Run 10 episodes and Compare to see the steps per episode (log scale). Blue cells have a positive value (darker = higher); G is the goal. All need a long first episode, because all values are 0 and the agent walks at random.
Predict first. The model's one-step error is about 1%. Is its error after 50 steps about 50%? Move the horizon . The real state (dark line) grows as ; the model predicts . The lower chart shows the relative error and, dashed, times the one-step error. Then switch to open loop vs MPC: the open-loop run executes the whole plan and drifts away; MPC plans again at every step and stays at 0.
Predict, then step. Click the move (A, B or C) that you think the next Select will choose, then press Next phase four times: Select, Expand, Evaluate, Backup. The orange path is the selection; edge width grows with the visit count ; Q is the mean result for the player who made the move. Under each leaf, p is your win probability there. Then press Run 100 a few times. Move A has the best average (0.633), but the opponent can answer it with A3 (). Watch the visits move to B, the best move against a good opponent. Set and press Reset a few times: without exploration the search can lock onto a wrong move.
Predict first: if you double the horizon , how much does the expected cost of BC grow? Move . BC cars leave the road and never come back, because their data has only on-road states (the dots on the left show where the data has expert labels). Switch to the DAgger rounds: each round adds the positions the learner visited, labelled by the expert, and the cars return to the road. The chart compares the costs with and .