Before we start, three reminders the whole page rests on.
(1) The return Gt — the total discounted reward from time t until the episode ends at time T:
Gt=Rt+1+γRt+2+γ2Rt+3+⋯+γT−t−1RT
Here Rt+1 is the reward you receive just after being at time t, γ (the discount factor, a number between 0 and 1) shrinks rewards that arrive later, and T is the final step. Everything below is either computing this sum, or averaging it.
(2) The recursive form of the return. Factor a single γ out of every term after the first:
Gt=Rt+1+γ(Rt+2+γRt+3+⋯)
The bracket is exactly the return starting one step later, i.e. Gt+1. So
Gt=Rt+1+γGt+1
Why we bother: this lets us build a whole episode's returns from the last step backwards without re-summing the tail each time — one multiply-and-add per step. We use it in L2.2.
(3) The action-value Q(s,a). Where vπ(s) answers "how good is state s?", the action-value Q(s,a) answers "how good is taking action a in state s, then following the policy?" It is the expected return starting from s, committing to a first:
Q(s,a)=E[Gt∣St=s,At=a]
MC estimates it the same way it estimates V: average the observed returns that followed each (s,a) pair, using the incremental-mean update. We use Q in L4.1 and L5.2.
(4) Two model symbols used only in L3.2. A model of the environment is described by two functions. R(s,a) is the expected immediate reward you get for taking action a in state s. P(s′∣s,a) is the transition probability — the chance of landing in next-state s′ after taking a in s. "Model-free" means we do not know either of these; we only see samples. Keep these two definitions in mind for L3.2.
(a) updates before the episode ends and uses its own estimate V(s′) — that is bootstrapping (Temporal-Difference learning), not MC.
(c) uses a known model P — that is Dynamic Programming, not model-free.
(b) waits for the complete episode, then averages actual returns — this is exactly the Monte Carlo definition: episode-based, model-free, uses real outcomes.
Recall Solution
G0=R1+R2+R3=0+0+1=1
With γ=1 nothing is shrunk, so the return is just the plain sum of all rewards. Answer: G0=1.
Plug straight into the definition, one power of γ per step:
G0=R1+γR2+γ2R3+γ3R4G0=2+(0.5)(0)+(0.25)(4)+(0.125)(1)=2+0+1+0.125=3.125Answer: G0=3.125.
Recall Solution
From step 2, only R3 and R4 remain:
G2=R3+γR4=4+(0.5)(1)=4.5
Now rebuild G0backwards with the recursive form Gt=Rt+1+γGt+1, applied twice:
G1=R2+γG2=0+(0.5)(4.5)=2.25G0=R1+γG1=2+(0.5)(2.25)=2+1.125=3.125✓
Matches L2.1 — the recursion and the direct sum must always agree, since one was derived from the other. Answer: G2=4.5, and the recursion reproduces G0=3.125.
Recall Solution
This is the 6th visit, so the step size is α=N(s)1=61:
V(s)←V(s)+61[G−V(s)]=−0.4+61[−1−(−0.4)]=−0.4+61(−0.6)=−0.4−0.1=−0.5Answer: V(s)=−0.5.
Sanity check: the average of the running mean −0.4 (weight 5) and the new −1 (weight 1) is 65(−0.4)+(−1)=6−3=−0.5. Identical, as it must be.
Step 1 — return at each visit (undiscounted, so just sum remaining rewards).
First S1 (time t=0): G0=R1+R2+R3=0+2+3=5.
Second S1 (time t=2): G2=R3=3.
Step 2 — First-visit MC: use only the first occurrence of S1:
Vfirst(S1)=G0=5
Step 3 — Every-visit MC: average all occurrences of S1:
Vevery(S1)=2G0+G2=25+3=4
Answer: first-visit =5, every-visit =4. Unlike the parent note's example, here the two returns differ, so the methods disagree on this episode. Both would still converge to the same vπ(S1) over infinitely many episodes.
Recall Solution
Greedy policy improvement with V requires
π′(s)=argmaxa[R(s,a)+γ∑s′P(s′∣s,a)V(s′)].
Both R(s,a) (expected immediate reward) and P(s′∣s,a) (transition probability) appear explicitly — but model-free MC does not know them, so this maximisation cannot be evaluated.
Fix: estimate the action-valueQ(s,a) instead (defined in reminder (3)). Then improvement collapses to
π′(s)=argmaxaQ(s,a),
which needs no model — Q(s,a) already bundles the expected reward and the expected discounted future into one learned number. That is precisely why MC control learns Q, not V.
Recall Solution
Unbiased. By definition vπ(s)=Eπ[Gt∣St=s]. A single return Gt is one sample of that random variable, and the expectation of a sample equals the quantity it samples — so on average it hits the true value; no systematic error.
High variance: each Gt is one whole path through a stochastic environment — every random action choice, every random transition, every random reward along the entire episode is baked into that one number. Long episodes accumulate many independent random effects, so returns scatter widely. Averaging many episodes shrinks this scatter (law of large numbers), which is why MC needs many samples.
Step 1 — count steps remaining. Each move costs −1, γ=1, so the return from a state is simply −(number of moves left). The figure below draws the path on the grid and labels each arrow with the return credited to that move — so you can see how the return grows more negative (deeper) the earlier in the path a move sits.
Move from
Steps remaining
Return G
(0,0) right
6
−6
(0,1) down
5
−5
(1,1) down
4
−4
(2,1) right
3
−3
(2,2) right
2
−2
(2,3) down
1
−1
Figure: the same episode as a picture. Each coral arrow is a move; its label is the return G credited to that move (equal to the negative of the moves still remaining). Notice the returns get deeper — from −1 at the last move up to −6 at the very first — because earlier moves must "pay for" every step that follows.
Step 2 — update Q((0,0),right) (recall Q(s,a) = expected return after taking a in s, from reminder (3)). With α=1 from initial 0:
Q←0+1⋅(−6−0)=−6Answer: Q((0,0),right)=−6, and each earlier state-action gets credit for the return measured from when it was taken (the table and figure above).
Recall Solution
The random branch (probability ε) picks uniformly among all 4 actions, so every action — greedy included — gets an extra ε/∣A∣ from it.
After each episode the visit count N(s) goes up by one, so the step size is α=1/N(s)=1/(episode number).
Episode 1 (N=1, α=1, return G(1)=4):
V←0+1⋅(4−0)=4.Episode 2 (N=2, α=21, return G(2)=0):
V←4+21(0−4)=4−2=2.Episode 3 (N=3, α=31, return G(3)=2):
V←2+31(2−2)=2+0=2.Answer: V(s)=2.
Plain average check: 3G(1)+G(2)+G(3)=34+0+2=36=2✓. The incremental mean lands exactly on the plain average at every step — that is precisely what the α=1/N choice guarantees.
Recall Solution
(a) Greedy =argmaxaQ(s,a). Since −3>−5, the greedy action is a1.
(b)P(a1)=(1−ε)+2ε=0.9+0.05=0.95; P(a2)=2ε=0.05. (Sum =1.00✓.)
(c) Third visit → α=1/3:
Q(s,a2)←−5+31[−1−(−5)]=−5+31(4)=−5+1.333…=−3.667
Now Q(s,a1)=−3 and Q(s,a2)=−3.667. Since −3>−3.667, the greedy action is still a1 — but the gap shrank from 2 to about 0.67. A couple more good returns for a2 (only reachable becauseε>0 let us explore it) could flip the policy. Answer: Q(s,a2)≈−3.667; greedy unchanged this step.
Recall Solution
Step 1 — MC only updates what it visits. The incremental-mean update touches Q(s,a)only for pairs that actually occur in an episode. A pair never sampled keeps its initial value forever.
Step 2 — pure greedy self-censors. With ε=0 the policy always plays the current argmaxaQ(s,a). So any action that starts with a poor or merely un-tried estimate is never chosen, hence never sampled, hence never updated — even if it were truly the best. The agent locks onto whatever action first looked good, and has no mechanism to discover it was wrong.
Step 3 — the convergence condition. The guarantee that on-policy MC control reaches π∗ requires every (s,a) pair to be visited infinitely often. A fixed ε>0 delivers exactly this: from every state each action keeps probability ≥ε/∣A∣>0, so no action is ever starved of samples. ε=0 breaks the condition on line one, so the proof no longer applies and sub-optimal lock-in is possible.
Answer: pure greedy can freeze exploration and trap the policy; a fixed ε>0 restores the "infinitely often" visitation that the convergence theorem needs.
Recall Self-test checklist (reveal after finishing)
Return exponent starts at γ0 on Rt+1 ::: yes — first reward is undiscounted
Incremental step size for the n-th visit ::: α=1/n
Method that averages full-episode returns ::: Monte Carlo (not TD, not DP)
Why control learns Q not V ::: argmaxaQ needs no model
ε-greedy probability of the greedy action (uniform-over-all convention) ::: (1−ε)+ε/∣A∣
Reason for exploration (ε>0) ::: visit every (s,a) infinitely often → convergence