Monte Carlo Action Values
When the rules of the world are unknown, the way to price an action is to try it, finish the episode, and average the totals it earned.
Why Does This Exist?
With a known model, state values are enough: look one step ahead through and pick the action leading to the best successor. Without a model that lookahead is impossible. Knowing the next state is worth a lot helps nothing if you cannot say which action reaches it.
Action values remove the need for the lookahead entirely. The greedy choice becomes a plain maximum over numbers already learned:
Monte Carlo estimation learns those numbers from raw episodes: run an action, finish the episode, record the total, average. No transition probabilities, no bootstrapped guesses. The structural cost is coverage: states are visited naturally along trajectories, but every action from each state must be tried on purpose, or its value stays unknown. This page teaches that estimation step. The prediction background is Monte Carlo methods, the counting variants are first visit versus every visit, and the control loop built on top is Monte Carlo control.
The one idea you need first
The action value is the expected discounted total from taking in and following after. Value functions define both and precisely. Monte Carlo turns that expectation into an average of finished episode totals.
Think of It Like This
Pricing two wine pairings across repeated dinners
A restaurant offers two pairings with the sea bass course but hides the recipes, so no amount of menu study predicts which evening you will enjoy more. You try the white across two full dinners and the red across one, score each whole evening, and average: white averages 4.75 evenings of enjoyment against red at 6.20, so you order red next time.
The scores price the pairing decision directly, with no chemistry model of wine and sauce. Where it stops: dinners are scored by memory and mood, while the agent banks exact discounted sums, and it must keep ordering both pairings on a schedule instead of settling after one pleasant night.
How It Actually Works
For a trajectory ending at , the return from step is accumulated backward:
with discount in . First visit estimation records only at each pair's first appearance per episode, then averages all recorded totals:
or incrementally with visit count :
A deterministic policy replays the same action forever, starving the rest, so convergence needs exploring starts or ongoing random exploration: every pair visited again and again.
Worked example
State offers and with . All tables start empty.
Episode 1 starts with : rewards then . The return is , so and .
Episode 2 starts with : rewards then . The return is , so and .
Episode 3 retries : rewards then . The return is . The running average moves to
which equals . Greedy choice at compares against and picks , with no model queried.
Code
This snippet averages the three episode returns exactly as the worked example does and prints the greedy pick.
def episode_return(rewards: list[float], gamma: float = 0.9) -> float: g = 0.0 for r in reversed(rewards): g = r + gamma * g return round(g, 2)
g1 = episode_return([2.0, 4.0]) # -> 5.6g2 = episode_return([-1.0, 8.0]) # -> 6.2g3 = episode_return([3.0, 1.0]) # -> 3.9q_a1 = round((g1 + g3) / 2, 3)print(g1, g2, g3) # -> 5.6 6.2 3.9print(q_a1, g2) # -> 4.75 6.2print("a2" if g2 > q_a1 else "a1") # -> a2The three returns print as 5.6, 6.2, and 3.9. The averaged is 4.75 against 6.2 for , so the greedy pick prints as the second action.
Watch Out For
Starving actions under a greedy policy
Once one action leads, a greedy policy replays it forever while the rest sit at . An optimal action that drew one unlucky negative reward on its first trial then never gets a second chance.
Symptom: value tables where some pairs have hundreds of visits and neighbors have none, plus a policy that plateaued early. Fix: force coverage with exploring starts in resettable simulators or epsilon greedy exploration online, so every pair is visited infinitely often as episodes accumulate.
The Quick Version
- prices an action directly, so greedy choice needs no transition model.
- Monte Carlo estimates it by averaging finished episode returns from each pair's first visit per episode.
- The worked example prices at and at , so wins.
- Deterministic policies starve untried actions, so exploring starts or epsilon greedy coverage is required.
- Every symbol is concrete: is the sampled total, counts visits, discounts the future.