A hands-on study guide

Reinforcement learning basics

Fifteen interactive pages covering the whole of Sutton & Barto's Reinforcement Learning: An Introduction, from the simplest learning problem to function approximation, policy gradients and the links to psychology and neuroscience. Every demo runs live in the browser, showing each update with its actual numbers so you can check the arithmetic yourself.

01The path

The pages are meant to be read in order. Each one reuses ideas from the one before. Numbers are the book's chapters.

  1. 1

    Introduction

    Open →

    What reinforcement learning is: an agent learning from interaction, with rewards, values and a policy. Exploration, and learning a value function from experience.

    Try: play tic-tac-toe against a learning agent and watch its board values update after every move.

Part I · Tabular solution methods

  1. 2

    Multi-armed bandits

    Open →

    One situation, k choices, no instructions. Estimating action values and balancing exploration against exploitation.

    Try: pull a five-armed bandit with ε-greedy, UCB or a gradient bandit; compare them on the 10-armed testbed.
  2. 3

    Finite Markov decision processes

    Open →

    States, actions, dynamics, returns and discounting. Value functions, the Bellman equation and optimal policies.

    Try: change the recycling robot's dynamics and policy, and verify the Bellman equation with real numbers.
  3. 4

    Dynamic programming

    Open →

    With a perfect model, compute values by sweeping the Bellman equations: policy evaluation, policy iteration, value iteration.

    Try: back up a 4×4 gridworld one cell at a time, in place or synchronously, and improve the policy.
  4. 5

    Monte Carlo methods

    Open →

    No model: learn from complete episodes by averaging returns. Exploring starts, ε-soft policies and importance sampling.

    Try: play blackjack hands, watch the value heatmaps fill in, and find the optimal strategy.
  5. 6

    Temporal-difference learning

    Open →

    No model and no waiting: update after every step by bootstrapping. TD(0), Sarsa, Q-learning and Expected Sarsa.

    Try: run Sarsa and Q-learning side by side on the cliff and see why they learn different paths.
  6. ↔

    TD vs Monte Carlo

    Open →

    The two model-free approaches head to head: bias and variance, online vs episodic learning, and n-step TD as the bridge.

    Try: step both methods through the same random-walk episodes and compare their error curves.
  7. 7

    n-step bootstrapping

    Open →

    Look n rewards ahead, then bootstrap. n-step TD and n-step Sarsa, and why an intermediate n usually wins.

    Try: step through the n-step update on a 19-state walk and sweep n and α in a parameter study.
  8. 8

    Planning and learning

    Open →

    Combine a learned model with direct RL. Dyna-Q, prioritized sweeping, expected vs sample updates, and decision-time planning.

    Try: solve a maze with Dyna-Q and see how planning steps cut the episodes needed.

Part II · Approximate solution methods

  1. 9

    On-policy prediction with approximation

    Open →

    Values from a parameterized function: the value-error objective, SGD and semi-gradient methods, and linear features (aggregation, tile coding, Fourier, polynomials).

    Try: fit a 1000-state random walk with different features and compare gradient MC with semi-gradient TD.
  2. 10

    On-policy control with approximation

    Open →

    Semi-gradient Sarsa for action values, n-step variants, and the average-reward setting for continuing tasks.

    Try: teach an underpowered car to escape a valley with tile-coded Sarsa and watch the cost-to-go map form.
  3. 11

    Off-policy methods with approximation

    Open →

    Why off-policy learning with approximation can diverge (the deadly triad), the projected Bellman error, and gradient-TD and emphatic methods.

    Try: run Baird's counterexample: semi-gradient TD blows up while TDC converges.
  4. 12

    Eligibility traces

    Open →

    The λ-return, TD(λ) and its backward-looking trace vector, true online TD(λ), Sarsa(λ) and off-policy traces.

    Try: watch the trace vector build behind a random walker and compare λ values in a parameter study.
  5. 13

    Policy gradient methods

    Open →

    Learn the policy directly: the policy gradient theorem, REINFORCE, baselines, actor–critic and continuous actions.

    Try: learn a stochastic policy in a corridor where every deterministic policy fails, with and without a baseline.

Part III · Looking deeper

  1. 14–17

    Psychology, neuroscience, applications and frontiers

    Open →

    Conditioning and the TD model, dopamine as a reward prediction error, landmark applications from TD-Gammon to AlphaGo Zero, and open problems.

    Try: train the TD model of conditioning and watch the error move from the reward to the cue, then dip when the reward is withheld.

02How the methods relate

Two questions separate the methods for estimating values. Does an update need a model of the environment, or just a sample of experience? And does its target bootstrap, using current estimates of later states, or wait for the real outcome?

Bootstraps
Waits for the real return
Needs a model
(expected updates)
Dynamic programming
Averages over every next state, using their current values.
Exhaustive search
Expands the whole tree to the end. Rarely feasible.
Learns from samples
(sample updates)
Temporal difference
One sampled step, then the current estimate of the next state.
Monte Carlo
A whole sampled episode, then the actual return.

n-step TD and TD(λ) fill the space between the bottom two. See n-step bootstrapping, eligibility traces and the TD vs MC comparison.

03One update rule, different targets

Nearly every method in the series moves an estimate a step toward a target: new estimate ← old estimate + step size × (target − old estimate). The methods differ in the target.

MethodEstimatesTarget
Bandit sample averageQ(a)R
Policy evaluation (DP)V(s)Σa π(a|s) Σs′,r p(s′,r|s,a) [ r + γV(s′) ]
Value iteration (DP)V(s)maxa Σs′,r p(s′,r|s,a) [ r + γV(s′) ]
Monte CarloV(s) or Q(s,a)Gt
TD(0)V(s)Rt+1 + γV(St+1)
SarsaQ(s,a)Rt+1 + γQ(St+1, At+1)
Q-learningQ(s,a)Rt+1 + γ maxa Q(St+1, a)
n-step TDV(s)Rt+1 + … + γn−1Rt+n + γnV(St+n)
λ-returnV(s)(1−λ) Σn λn−1 Gt:t+n
Semi-gradient TDw in v̂(s, w)Rt+1 + γ v̂(St+1, w)
REINFORCEθ in π(a|s, θ)Gt, weighting ∇ln π(At|St, θ)
Actor–criticθ and wRt+1 + γ v̂(St+1, w), weighting ∇ln π

DP replaces V(s) outright with its target (in effect a step size of 1). The others take a step of size α or 1/n toward a sampled target. With approximation the step adjusts weights instead, in the direction of the gradient, and policy-gradient methods adjust policy parameters in proportion to how good the outcome was.