5.1.10 · D3Reinforcement Learning Foundations

Worked examples — Monte Carlo methods

3,494 words16 min readBack to topic

This page is a drill floor. The parent note taught you the machinery: returns , first-visit vs every-visit averaging, and the incremental update. Here we push that machinery through every kind of input it can meet — every sign of reward, the degenerate one-step episode, the loop that revisits a state, the extreme discount factors and , and a real word problem.

Before we compute anything, four symbols we lean on, so nothing appears unearned.


The scenario matrix

Every Monte Carlo estimate is a return folded into an average. The things that can change between problems are: the sign of rewards, the discount , whether a state is revisited (first- vs every-visit), and whether the episode is degenerate (length 1) or long. The table below enumerates the case classes. Each worked example is tagged with the cell it covers, and after the examples we tick every cell off in a coverage checklist.

Cell Case class What is unusual Example
A Single-step / terminal-adjacent , only one reward in Ex 1
B Multi-step, all rewards equal sign (negative) step-cost accumulation Ex 2
C Discounting bites () geometric weighting matters Ex 3
D (myopic) vs (undiscounted) — the two extremes limiting behaviour Ex 4
E State revisited in one episode first-visit ≠ every-visit Ex 5
F Mixed-sign rewards (positive and negative) cancellation inside Ex 6
G Incremental average across episodes the nudge over time Ex 7
H Real-world word problem translate story → returns Ex 8
I Exam twist: control update & why not argmax with no model Ex 9










Matrix check — every cell covered

We claimed the matrix enumerated every case class. Here is the tick-list tying each cell back to the example that filled it:

  • Cell A (single-step) → Ex 1: one reward, , .
  • Cell B (all-negative multi-step) → Ex 2: step costs give .
  • Cell C ( bites) → Ex 3: distant squashed to , .
  • Cell D (extremes ) → Ex 4: vs .
  • Cell E (revisited state) → Ex 5: first-visit vs every-visit .
  • Cell F (mixed signs) → Ex 6: survives three 's, .
  • Cell G (incremental average) → Ex 7: equals batch mean .
  • Cell H (word problem) → Ex 8: elevator, , .
  • Cell I (control, not ) → Ex 9: greedy prob , model-free argmax.

Every row of the table above now has a worked, verified example — nothing left unshown.


Recall Quick self-test

How is defined and when do we increment it? ::: It counts returns collected for state ; we increment it by one before computing , which keeps the division safe. In the return formula, what exponent multiplies the first reward ? ::: — the immediate reward is never discounted; the sum index starts at . Return from a 3-step undiscounted episode with rewards ? ::: . With rewards and , what is ? ::: . One episode has twice with returns and ; first-visit ? ::: (only the first). Every-visit? ::: . Under -greedy with , 2 actions, probability of the greedy action? ::: . Why does control estimate rather than ? ::: Because argmax over improves the policy with no model, whereas improving from needs and .

Prerequisite backbone for all of the above: the state/return/policy vocabulary of 5.1-Markov-Decision-Processes, and the parent Monte Carlo methods note.