Marginal

Reinforcement Learning

Learning to act from reward: Markov decision processes, policies and value functions, the Bellman equations and their contraction property, policy and value iteration, temporal-difference learning, Q-learning and stochastic approximation, exploration, policy gradients and actor–critic methods, PPO, deriving rewards from preferences and reward shaping.

26 lessons in 4 units

Start your free trial14 days free. No card needed.
What you'll learn

26 lessons, one small step at a time

Each lesson states its goal, then works up to it in short steps with practice after each. A placement test at the start skips what you already know.

MDPs & Bellman Equations

9 lessons
  1. Discounted returnsCompute the discounted return of a reward stream, directly and recursively, its value for a constant reward forever, and the horizon a discount implies.
  2. Markov decision processesCompute the probabilities of the next state and the expected rewards under a policy, and model a problem as a Markov decision process.
  3. Values from action valuesCompute a state's value from its action values under a policy, and improve the policy by acting greedily.
  4. Policies & value functionsCompute action values from the values of the next states, for deterministic and for random transitions, and tell deterministic from stochastic policies.
  5. Iterative policy evaluationApply Bellman backups to evaluate a fixed policy, sweep by sweep from a starting guess, and explain why the method converges.
  6. Policy evaluationSolve the Bellman expectation equation exactly for a policy's values, for one state and for several.
  7. Bellman optimalityBound the error of repeated Bellman optimality backups with the contraction property, and count the iterations a target accuracy needs.
  8. Policy improvementCompute a policy's action values and improve the policy greedily, the two steps of policy iteration.
  9. Value iterationApply value-iteration updates, and read each iterate as the optimal value of a finite-horizon problem.

Learning from Experience

9 lessons
  1. TD errorsCompute temporal-difference errors and their average, and Monte Carlo targets.
  2. Temporal-difference learningApply the TD(0) update, and compare TD learning with Monte Carlo.
  3. n-step returnsCompute n-step targets and the weights TD(λ) gives them, and choose n or λ to trade bias against variance.
  4. Q-learningCompute the Q-learning target and update, and state when tabular Q-learning converges.
  5. Deep Q-networksCompute a deep Q-network's regression target and the overestimation from maximizing noisy estimates, and explain what keeps DQN stable.
  6. Stochastic approximationUpdate a running average with a step size, and tell which step-size schedules satisfy the Robbins–Monro conditions.
  7. SARSA vs. Q-learningApply the SARSA update, and contrast on-policy SARSA with off-policy Q-learning.
  8. ε-greedy banditsUpdate an arm's estimated payoff, and compute the choice probabilities of ε-greedy exploration.
  9. UCB & optimismCompute UCB scores, explain why optimism explores well, and compute the regret of a sequence of pulls.

Policy Optimization

4 lessons
  1. The score functionCompute softmax policy probabilities and their score function, and use the score to estimate the gradient of an expectation.
  2. Policy gradients (REINFORCE)Apply the REINFORCE update, explain where the policy gradient theorem comes from, and weigh REINFORCE's strengths and weaknesses.
  3. Baselines & actor–criticCompute advantages from a critic's values, and describe the roles of the actor and the critic.
  4. Proximal policy optimizationCompute PPO's importance ratios and clipped objective, and explain why clipping keeps updates safe.

Rewards & Their Pitfalls

4 lessons
  1. From preferences to rewardsCompute how affine changes of rewards change values, state the reward hypothesis, and tell when rewards fail to represent preferences.
  2. The Markov reward theoremTell preferences, utilities and rewards apart, compute a utility from rewards and transition discounts, and judge in which state a goal is Markov.
  3. Beyond expected utilityMatch preference patterns to the expected-utility axioms they violate, and explain why the alternatives matter for AI safety.
  4. Reward shapingCompute potential-based shaped rewards, and show why such shaping preserves optimal policies.
Sample lesson

Discounted returns

Goal: Compute the discounted return of a reward stream, directly and recursively, its value for a constant reward forever, and the horizon a discount implies.

Reinforcement learning studies agents that learn by trial and error to collect rewards: game-playing programs, robots, and language models fine-tuned on feedback. The first question is what the agent is trying to maximize: not one reward, but the whole stream of future rewards.

We will add up the return, work backward, value rewards forever, and finish with the horizon.

Step 1: The return

An agent collects rewards r₀, r₁, r₂, … over time. Its return adds them up, discounting each later step by a factor γ between 0 and 1:

G = r₀ + γr₁ + γ²r₂ + … = Σₜ γᵗ rₜ

A reward t steps from now is weighted by γᵗ. With γ = 0.5, rewards 0, 2, 4 give 0 + 1 + 1 = 2. With γ = 0 the return is just the immediate reward; raising γ toward 1 makes the agent care more about distant rewards.

Step 2: Working backward

The return is also recursive: the return from step t is the reward now plus γ times the return from the next step on, Gₜ = rₜ + γGt+1. Working backward through rewards 0, 2, 4 with γ = 0.5 gives G₂ = 4, G₁ = 2 + 0.5 × 4 = 4 and G₀ = 0 + 0.5 × 4 = 2, the same as the direct sum.

Step 3: Rewards forever

Many tasks have no end, and an undiscounted sum of rewards forever would be infinite. With γ < 1 a constant reward r forever is a geometric series with a finite total:

G = r + γr + γ²r + … = r ÷ (1 − γ)

A reward of 1 per step with γ = 0.5 is worth 2. The return is linear in the rewards, so doubling a constant reward doubles its return. Keeping infinite sums finite is one reason many formulations use γ < 1.

Step 4: The horizon

Discounting also expresses a preference for sooner rewards, and it sets how far ahead the agent effectively looks: rewards much more than about 1/(1 − γ) steps away count little. γ = 0.5 looks about 2 steps ahead, γ = 0.9 about 10, γ = 0.99 about 100 and γ = 0.999 about 1,000. Choosing γ is choosing how patient the agent is.

In the app, each step ends with practice questions, new ones every time, and the lesson comes back later in spaced reviews.

Start Reinforcement Learning

Lessons that need something you haven't learned yet bring it in first, from any course.

Start your free trial14 days free. No card needed.