Skip to content
AI360XpertBeta

Monte Carlo Exploring Starts

A control method that starts every practice run from a random situation with a random first move, so even a stubborn greedy policy ends up testing everything.

Exploring starts forces the episode to open at S1 with Right, the run returns 13.0, and Q(S1, Right) jumps from 1.0 to 7.0 so the policy flips
Exploring starts forces the episode to open at S1 with Right, the run returns 13.0, and Q(S1, Right) jumps from 1.0 to 7.0 so the policy flips

Why Does This Exist?

A greedy policy has a blind spot: it only visits what it already likes. If early estimates are wrong, the truly best action never gets tried, so its value never improves, so it never gets tried. The loop seals shut. This is the classic exploration problem in Monte Carlo control, where values are learned from full episodes with no model to query about untried branches.

Exploring starts breaks the loop at the root. Sutton and Barto (Chapter 5) assume every state action pair (s,a)(s, a) has nonzero probability of opening an episode. After that forced first step, the agent follows its deterministic greedy policy all the way to termination. Randomize the opening, keep everything else greedy, and every choice gets sampled infinitely often in the limit, which is what lets plain averaging converge to optimal values in episodic tasks. When forced openings are impossible, the successor is on-policy first-visit MC control, which explores with soft policies instead.

The one idea you need first

Values here are action values Q(s,a)Q(s, a): the expected return after taking action aa in state ss. Returns GtG_t are discounted sums of rewards to the end of the episode, Gt=Rt+1+γGt+1G_t = R_{t+1} + \gamma G_{t+1}, with γ\gamma discounting later rewards. The full treatment of estimating them from episodes is in Monte Carlo action values.

Think of It Like This

A food critic with a forced first bite

A critic reviews restaurants but has a rut: they always order the pasta, so the kitchen's brilliant fish never gets judged. Their editor imposes one rule: each visit opens with a random dish drawn from the menu, first bite mandatory. After that, the critic eats the rest of the meal by their usual habits and writes the review.

Over many visits every dish gets a fair hearing without changing how the critic normally eats. Random opening dishes are exploring starts, usual habits are the greedy policy, and the published reviews are the averaged returns.

Where it stops: no editor can force a real first bite everywhere, and the math needs every pair to keep a nonzero chance forever plus episodes that actually end. Real kitchens also change menus, while this method assumes fixed dynamics.

How It Actually Works

Initialize Q(s,a)Q(s, a) arbitrarily and π(s)\pi(s) as any deterministic policy. Then repeat:

Open. Draw S0S_0 and A0A_0 so that every pair keeps positive probability, P(S0=s,A0=a)>0P(S_0 = s, A_0 = a) > 0 for all ss and aa.

Roll. From t=1t = 1 onward act greedily, At=π(St)A_t = \pi(S_t), until termination at time TT.

Score. Walk backward accumulating Gt=Rt+1+γGt+1G_t = R_{t+1} + \gamma G_{t+1}.

Update. For the first visit of each pair in the episode, with N(s,a)N(s, a) counting visits so far:

Q(s,a)←Q(s,a)+G−Q(s,a)N(s,a)Q(s, a) \leftarrow Q(s, a) + \frac{G - Q(s, a)}{N(s, a)}

Improve. For each visited state, set π(s)←arg⁡max⁡aQ(s,a)\pi(s) \leftarrow \arg\max_a Q(s, a).

No exploration parameter appears anywhere after step zero. The policy stays fully greedy because the opening carries the whole exploration burden.

Worked example

Two states, actions Left and Right, γ=0.90\gamma = 0.90. Current values at S1S_1: Q(S1,Left)=2.0Q(S_1, \text{Left}) = 2.0, Q(S1,Right)=1.0Q(S_1, \text{Right}) = 1.0, so π(S1)=Left\pi(S_1) = \text{Left}. Exploring starts forces the opening (S1,Right)(S_1, \text{Right}). The episode runs: R1=4.0R_1 = 4.0 into S2S_2, then the greedy policy earns R2=10.0R_2 = 10.0 and terminates.

G1=10.0,G0=4.0+0.90×10.0=13.0G_1 = 10.0, \qquad G_0 = 4.0 + 0.90 \times 10.0 = 13.0

The pair (S1,Right)(S_1, \text{Right}) was seen once before, so NN goes 11 to 22:

Q(S1,Right)=1.0+13.0−1.02=7.0Q(S_1, \text{Right}) = 1.0 + \frac{13.0 - 1.0}{2} = 7.0

Now arg⁡max⁡\arg\max compares 2.02.0 against 7.07.0, so π(S1)\pi(S_1) flips to Right. One forced opening found a 13.013.0 line the greedy policy would never have touched. The diagram draws this exact episode.

Code

This snippet replays the worked example with type hints: accumulate the return backward, then apply the averaging update.

def episode_return(rewards: list[float], gamma: float) -> float:    """Discounted return G0 for one episode's reward sequence."""    g = 0.0    for r in reversed(rewards):        g = r + gamma * g    return g

def mc_update(q: float, n: int, g: float) -> tuple[float, int]:    """Fold one first-visit return into the running average."""    n_new = n + 1    return q + (g - q) / n_new, n_new

g0 = episode_return([4.0, 10.0], 0.90)print(f"G0={g0:.4f}")  # -> G0=13.0000q_new, n_new = mc_update(1.0, 1, g0)print(f"Q={q_new:.4f} N={n_new}")  # -> Q=7.0000 N=2

The printout matches the hand computation: G0=13.0G_0 = 13.0 and QQ moves 1.01.0 to 7.07.0, flipping the greedy choice.

Watch Out For

Assuming you can start anywhere in the real world

In a simulator, opening at any state and action is one line of code. In a plant or on a road, it means teleporting a reactor into an explosive regime or a car sideways into traffic. The method then quietly stops exploring and the policy stagnates, with no error raised. Symptom: training curves flatline outside simulation. Fix: switch to epsilon soft policies that explore from natural starts, as in on-policy first-visit control.

Applying it where episodes never end

Monte Carlo updates need a terminal reward to score the episode. In continuing tasks there is no GtG_t, so the backward pass has nothing to accumulate and the update never fires. Symptom: values stay at initialization while the agent keeps acting. Fix: use temporal difference methods, which bootstrap from the next estimate instead of waiting for termination.

The Quick Version

  • Exploring starts forces every state action pair to keep a nonzero chance of opening an episode.
  • After the forced first step the policy is purely greedy and deterministic, with no exploration parameter.
  • Episodes are scored backward into returns GtG_t, and first visits update QQ with a running average.
  • Each visited state's policy is reset to the current greedy best, which is what drives improvement.
  • It fits simulators and episodic tasks, not physical systems with unsafe starts or tasks that never terminate.