Quick recap
The key takeaways of every lesson on one page. Read it in ten minutes to refresh the whole track; open a lesson when a point feels unclear.
01 MDPs and Bellman equations
- A finite MDP is . Markov: the next state and the reward depend on the past only through .
- The return is ; with the agent looks about steps ahead.
- and ; the advantage is .
- and .
- The Bellman expectation equation is linear: , and is invertible for because .
- With , the values are finite only if the policy ends every episode with probability 1.
- The optimality equations put a max over actions inside: .
- A policy that is greedy with respect to is optimal in every state and deterministic.
02 Policy and value iteration
- Iterative policy evaluation repeats ; synchronous sweeps use the old vector, in-place sweeps the newest values.
- The Bellman operators are and ; both are monotone.
- Max lemma: .
- and are -contractions in the -norm, so they have unique fixed points and , and .
- Stopping rule: ; value iteration needs about iterations.
- Policy improvement theorem: if in every state, then in every state; the greedy policy satisfies the condition.
- Policy iteration (exact evaluation + greedy improvement) stops after finitely many steps at an optimal policy; one iteration costs . Value iteration costs per iteration but needs many more.
- Generalized policy iteration: any interleaving of evaluation and improvement converges to and ; most RL algorithms have this form.
03 Bandits and exploration
- A -armed bandit has arm means , best mean and gaps . It is an MDP with one state: the pure exploration–exploitation problem.
- The sample mean updates as ; a constant step gives an exponential recency-weighted average for changing means.
- The pseudo-regret is the expected loss against always pulling the best arm: .
- Greedy can lock onto a bad arm; fixed ε-greedy has linear regret .
- UCB1 pulls ; the bonus comes from Hoeffding with failure probability ; it pulls each bad arm at most about times.
- Lai–Robbins: every consistent algorithm has regret of order at least , with constant per bad arm.
- Thompson sampling draws from each Beta posterior and pulls the largest; each arm is pulled with the posterior probability that it is best (probability matching).
04 Monte Carlo and TD prediction
- Prediction estimates from episodes without a model. Both MC and TD move a step toward a target.
- Monte Carlo uses the return : unbiased, high variance, needs complete episodes, does not need the Markov property.
- TD(0) uses and the TD error , with after a terminal state: biased while , low variance, online.
- The expected TD(0) target is , so TD(0) is a sampled form of iterative policy evaluation; and .
- Batch MC converges to the average observed returns; batch TD converges to the values of the maximum-likelihood Markov model (certainty equivalence).
- The λ-return gives weight to the n-step return and the rest, , to ; λ = 0 is TD(0), λ = 1 is MC.
- TD(λ) keeps traces , and updates ; offline it equals the λ-return updates.
- Importance sampling with : ordinary IS is unbiased with high variance; weighted IS is biased, consistent and stays in the range of the returns.
05 SARSA and Q-learning
- Control without a model learns : the greedy step needs no or . GPI then alternates (partial) evaluation of and ε-greedy improvement.
- ε-greedy gives the greedy action and every other action . If is ε-soft, the ε-greedy policy with respect to is at least as good as ; reaching needs GLIE exploration.
- All three methods update . Targets: SARSA ; expected SARSA ; Q-learning ; and at the end of an episode.
- SARSA is on-policy (it learns of the exploring policy); Q-learning is off-policy (it learns from any data that visit every pair); expected SARSA with a greedy target policy is Q-learning.
- Tabular Q-learning converges to with probability 1 if every pair is updated infinitely often and , (Watkins and Dayan, 1992).
- On cliff walking with , Q-learning learns the 13-step edge path but has the worse online return (about per episode); SARSA learns a safer path and loses less while exploring (about ).
- Maximization bias: for unbiased . The double estimator with independent is not biased upward; double Q-learning keeps two tables and updates one at random.
06 Function approximation and DQN
- A linear value function is with ; one-hot features give the table, state aggregation a staircase. The objective is with the on-policy distribution .
- Gradient MC, , is SGD on . Semi-gradient TD uses as a constant target; it is not the gradient of any loss.
- On-policy linear TD converges to the TD fixed point , , ; its error can exceed the best fit (by at most in continuing tasks).
- Deadly triad: function approximation + bootstrapping + off-policy data can diverge; with any two of the three, instability can be avoided. In the example, diverges for .
- DQN minimizes a Huber or squared loss on with , no gradient through ; a replay buffer decorrelates samples, a target network (copy every steps or Polyak averaging) fixes the labels.
- Double DQN: : the online network selects, the target network evaluates.
- Offline RL: the max picks out-of-distribution actions whose values are never corrected (extrapolation error). CQL adds , whose gradient lowers unsupported values and raises data actions.
07 Policy gradients and REINFORCE
- A policy-gradient method does gradient ascent on directly in the policy parameters.
- Log-derivative trick: , so ; the reward need not be differentiable.
- Scores: softmax ; Gaussian .
- Policy gradient theorem: ; the dynamics drop out and there is no term.
- REINFORCE: from one episode, with the reward-to-go (rewards before have a mean-zero term).
- Any baseline keeps the estimate unbiased because ; turns into an advantage estimate and cuts the variance. A baseline adds bias.
- Tabular softmax: .
- When states cannot be told apart, the best policy can be stochastic: in the short corridor and .
08 Actor-critic, GAE and SAC
- Actor-critic: the critic gives the TD error ; the critic moves by and the actor by .
- The -step estimator has bias from the critic error at the bootstrap state; more real rewards mean less bias and more variance.
- GAE: ; gives , gives ; with an exact critic every is unbiased.
- Backward recursion: , value targets ; only for real terminations, and truncations bootstrap from of the next state.
- is part of the objective; only trades the critic's bias against the rewards' variance.
- A2C loss: , on fresh on-policy data from parallel environments.
- TD3 fixes DDPG with clipped double Q, delayed actor updates and target policy smoothing.
- SAC maximizes ; for discrete actions the soft-greedy policy is and .
09 PPO and RL for LLMs
- Performance difference lemma: , proved by telescoping along trajectories of .
- The surrogate uses the old states; it has the same value and gradient as the true improvement at , but can be badly wrong for large steps.
- TRPO maximizes the surrogate subject to an average KL , using with the Fisher matrix , conjugate gradient and a line search.
- PPO maximizes : a pessimistic lower bound on whose gradient is zero only for samples that already moved more than in the helpful direction.
- The clip does not bound the KL; PPO monitors , an unbiased and non-negative estimate of , and stops early.
- LLM generation is a token-level MDP with deterministic transitions; the KL-regularized objective gives the per-token reward plus the score at the last token.
- The KL-regularized optimum is with value ; DPO uses this formula to fit preferences without RL.
- RLOO uses (unbiased); GRPO uses inside a clipped ratio; both replace the critic by a group of responses to the same prompt.
10 Model-based RL and AlphaZero
- A model predicts from ; planning uses it to improve values or policies without new real experience. Dyna-Q = Q-learning on each real step plus Q-learning updates on transitions replayed from the model.
- MPC: plan an action sequence in the model, run only the first action, observe the real state, plan again. Random shooting and the cross-entropy method (CEM) are common planners.
- Open-loop model error compounds: with one-step error and -Lipschitz dynamics, . Planners also exploit model errors (model bias).
- MCTS repeats Select, Expand, Evaluate, Backup. UCT selects : UCB1 at every node. In two-player games the backup flips the sign at every level.
- Behaviour cloning with error on the expert's states has extra cost at most , and this order is reached; DAgger trains on the learner's own states with expert labels and gets .
- AlphaZero: ; PUCT selects ; self-play gives targets ; loss . MCTS is the policy improvement step of an approximate policy iteration.
- MuZero plans with MCTS in a learned latent model trained to predict rewards, values and policies; Dreamer trains an actor-critic on imagined latent rollouts; MBPO uses short model rollouts from real states.