Reinforcement Learning

Monte Carlo Reinforcement Learning

Monte Carlo RL evaluates a fixed policy by averaging return-to-go values from complete sampled episodes, so no transition model is needed and small visit counts can be noisy.

status: reviewimportance: importantdifficulty 4/5math: graduateread: 18mlive demo

Concept Structure

Monte Carlo Reinforcement Learning

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

2prerequisites
2next concepts
3related links

Learner Contract

What this page should let you do.

You are here becauseMonte Carlo RL evaluates a fixed policy by averaging return-to-go values from complete sampled episodes, so no transition model is needed and small visit counts can be noisy.

This Reinforcement Learning concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.

By the end4/4 sections ready | runnable code expected | live demo

Explain the mechanism, trace the main notation, and test one prediction in the live demo.

Do this firstIntuition

Read the intuition before the notation; the math should name a mechanism you already felt.

Test the linkManipulate one control and predict the visible change.Then continue to Temporal-Difference Learning (review)

Claim/source review status

Substantive review recorded

1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.
Claims1/1 reviewed
Sources3 cited
Codeattached
Demolive
Reviewed2026-07-03
Updatedpage 2026-07-03

Learning item flow

4/4 sections readyAsk about thisResearch room
ConceptMonte Carlo Reinforcement LearningReinforcement Learning
3 sources attachedLocal snapshot ready
concept:reinforcement-learning/monte-carlo-rl
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

Dynamic programming asked for a model. It updated values by looking through transition probabilities.

Monte Carlo reinforcement learning makes a different bargain:

Do not ask for the model. Run episodes, wait until they end, then average what actually happened.

For policy evaluation, the policy π\pi is fixed. Every time an episode visits a state ss, we can look forward along that sampled episode and compute the return from that visit. If the agent visits the same state many times across many episodes, the average of those returns becomes an estimate of Vπ(s)V^\pi(s).

That makes Monte Carlo conceptually simple. It is also why it can feel jumpy. A single unusually good or bad episode can move a value estimate, especially when a state has only a few visits. Monte Carlo learns from complete returns, not from one-step bootstrapped targets.

The useful contrast is:

  • dynamic programming backs up through a known model;
  • Monte Carlo RL averages sampled complete-episode returns;
  • temporal-difference learning will update from one sampled step plus a bootstrapped value estimate.
02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let an episode under policy π\pi be

S0,A0,R1,S1,A1,R2,,ST,S_0,A_0,R_1,S_1,A_1,R_2,\ldots,S_T,

where STS_T is terminal. The return from time tt is the discounted sum of rewards after that time:

Gt=Rt+1+γRt+2+γ2Rt+3++γTt1RT.G_t = R_{t+1}+\gamma R_{t+2}+\gamma^2 R_{t+3}+\cdots+\gamma^{T-t-1}R_T.

The state-value function under policy π\pi is

Vπ(s)=Eπ[GtSt=s].V^\pi(s)=\mathbb{E}_\pi[G_t\mid S_t=s].

Monte Carlo policy evaluation estimates that expectation with sample averages. In first-visit Monte Carlo, each state contributes at most one return per episode: the return after its first visit in that episode.

If G(1)(s),,G(N(s))(s)G^{(1)}(s),\ldots,G^{(N(s))}(s) are the observed first-visit returns for state ss, then

V^π(s)=1N(s)i=1N(s)G(i)(s).\hat V^\pi(s) = \frac{1}{N(s)} \sum_{i=1}^{N(s)} G^{(i)}(s).

Every-visit Monte Carlo uses every occurrence of ss in the episode instead of only the first. Both variants are built from sampled returns. Neither uses P(ss,a)P(s'\mid s,a), reward tables, or a Bellman backup through another value estimate.

The incremental average form is useful for code and memory:

V^n+1(s)=V^n(s)+1n+1(Gn+1(s)V^n(s)).\hat V_{n+1}(s) = \hat V_n(s) + \frac{1}{n+1} \left( G_{n+1}(s)-\hat V_n(s) \right).

This is a sample-average update. The target is the complete return Gn+1(s)G_{n+1}(s), not R+γV^(S)R+\gamma \hat V(S'). That distinction is exactly what temporal-difference learning will change.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
gamma = 0.90
episodes = [
    [("Start", 1.0), ("Practice", 0.5), ("Practice", 1.2)],
    [("Start", -0.5), ("Confused", -0.8), ("Confused", 0.7), ("Practice", 2.0)],
    [("Start", 3.0)],
]

returns = {}
for episode in episodes:
    G = 0.0
    tape = []
    for state, reward in reversed(episode):
        G = reward + gamma * G
        tape.append((state, G))
    seen = set()
    for state, G in reversed(tape):
        if state in seen:
            continue
        returns.setdefault(state, []).append(G)
        seen.add(state)

for state, values in returns.items():
    estimate = sum(values) / len(values)
    print(state, [round(v, 3) for v in values], round(estimate, 3))

The code computes return-to-go backward through each completed episode, then averages first-visit returns by state. There is no transition matrix in the program.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

Use the Monte Carlo RL Return Lab to predict how one more completed episode changes value estimates.

Choose first-visit or every-visit counting, inspect the returns already observed, then predict which state estimate will jump most after the next episode is added. After reveal, compare the return-to-go tape, the before/after sample average, and the variance note.

Before reveal, the next episode and updated estimates stay locked. That keeps the learning move honest: Monte Carlo value estimates are empirical averages over complete returns, so a rare episode can move a small-sample estimate sharply.

Live Concept Demo

Explore Monte Carlo Reinforcement Learning

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 4/5graduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Monte Carlo Reinforcement Learning should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Monte Carlo RL evaluates a fixed policy by averaging return-to-go values from complete sampled episodes, so no transition model is needed and small visit counts can be noisy.

Prediction open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Monte Carlo Reinforcement Learning should make visible.

Visual Inquiry

Make the image answer a mathematical question

Monte Carlo RL evaluates a fixed policy by averaging return-to-go values from complete sampled episodes, so no transition model is needed and small visit counts can be noisy.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Monte Carlo Reinforcement Learning easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

book · 2018Reinforcement Learning: An Introduction, Second EditionRichard S. Sutton and Andrew G. Barto

Canonical source for Monte Carlo prediction, first-visit/every-visit averaging, no-model learning from episodes, and the no-bootstrapping contrast with dynamic programming and TD.

Open source
course-notes · 2026Stanford CS234: Lecture 3, Model-Free Policy EvaluationStanford CS234

Graduate RL source for return-to-go, incremental Monte Carlo policy evaluation, first-visit/every-visit properties, high variance, and episodic limitations.

Open source
reference · 2026Continuous Function: Monte Carlo Estimation and Importance SamplingContinuous Function

Local prerequisite page for sample-average estimation, estimator variance, and the probability background behind Monte Carlo RL.

Open source

Claim Review

Monte Carlo RL evaluates a fixed policy by averaging return-to-go values from complete sampled episodes, so no transition model is needed and small visit counts can be noisy.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources3 references

sutton-barto-2018-rl, stanford-cs234-mc-policy-evaluation, cf-monte-carlo-importance-sampling

Local checks4 local checks

Use equations, runnable code, and demos to check whether the source support is operational.

Substantively reviewedOn-policy Monte Carlo policy evaluation estimates V^pi(s) by averaging complete-episode returns observed after visits to state s; it does not require a transition model and does not bootstrap from other value estimates, but it can have high variance and generally waits for episode completion before updating.Claim metadata: source checked

The sources support finite episodic on-policy Monte Carlo policy evaluation as empirical averaging of discounted returns from sampled episodes under a fixed policy, with first-visit/every-visit variants, model-free/no-bootstrapping contrast, high variance, and the need to observe episode returns before updating.

Sources: Reinforcement Learning: An Introduction, Second Edition, Stanford CS234: Lecture 3, Model-Free Policy Evaluation, Continuous Function: Monte Carlo Estimation and Importance SamplingFinite episodic teaching MDP only; excludes Monte Carlo control, off-policy importance-sampling corrections, continuing tasks, function approximation, eligibility traces, and TD bootstrapping beyond a contrast note.A bounded review summary is present; still check caveats and exact reference scope.

Checked Sutton/Barto Chapter 5 for Monte Carlo prediction as averaging returns after state visits, model-free sample-episode learning, and no bootstrapping; checked Stanford CS234 Lecture 3 for return-to-go definitions, incremental updates, first-visit/every-visit properties, high-variance limitations, and episodic update timing. GPT Pro publication critique remains pending because 127.0.0.1:51672 is unavailable.

Reviewer: codex-local-source-review; reviewed 2026-07-03

Practice Loop

Try the idea before it explains itself

Monte Carlo RL evaluates a fixed policy by averaging return-to-go values from complete sampled episodes, so no transition model is needed and small visit counts can be noisy.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Monte Carlo Reinforcement Learning.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Grounded research drawerClose
ConceptMonte Carlo Reinforcement LearningReinforcement Learning

Research Room

Attach the question to a claim, equation, code, or demo

Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptReinforcement Learning

Monte Carlo Reinforcement Learning

Attached question

What is the smallest example that makes Monte Carlo Reinforcement Learning click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays in this browser, attached to the selected learning item.

No local draft saved.
Evidence to inspect
  • References to inspect: attached references on this page.
  • Definition, prerequisite, and contrast concept links
  • The equation or runnable code that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Monte Carlo Reinforcement Learning Selected item key: recorded for copy. Context: Reinforcement Learning Page anchor: recorded for copy. Open question: What is the smallest example that makes Monte Carlo Reinforcement Learning click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

View it in context
concept/concept-notebook/reinforcement-learning/monte-carlo-rl concept:reinforcement-learning/monte-carlo-rl