Planning in Huge MDPs: Sparse Sampling
Near-optimal planning in time independent of the number of states.
Value iteration touches every state in every sweep, so its cost grows with the size of the state space: hopeless for a robot in a continuous world or a game with more positions than atoms. Kearns, Mansour and Ng showed that choosing near-optimal actions needs no dependence on the number of states at all, if you can query a simulator. The price moves into the horizon, exponentially, and a matching lower bound shows that this price cannot be avoided without further structure. This lesson proves both results, then follows the idea to rollouts, tree search and the sample complexity of planning from a generative model.
What you’ll learn
- Define planning with a generative model, and implement the sparse sampling algorithm.
- State Kearns, Mansour and Ng's theorem with its constants, and sketch why a sampled tree of width and depth gives -optimal actions.
- Prove the matching lower bound: a planner that only samples can need a number of queries exponential in the effective horizon.
- Compare sparse sampling with rollouts, Monte Carlo tree search, and model-based planning from samples, whose sample complexity is .
Planning from a simulator
A generative model is a simulator you can reset: given any state and action , it returns the reward and a next state . It is weaker than a full model, since you never see the probabilities, and stronger than experience, since you may query any state as often as you like. Game engines and physics simulators are generative models. A policy for a huge state space cannot even be written down, so Kearns, Mansour and Ng (2002) took the online view: a planner is handed the current state, computes, and returns one action, and its cost is counted per decision.
def estimate_q(sim, s, depth, width, gamma, actions):
"""Sparse-sampling estimates of Q_depth(s, a) for every action.
sim(s, a) returns (reward, next_state), next_state ~ P(. | s, a)."""
if depth == 0:
return {a: 0.0 for a in actions}
q = {}
for a in actions:
total = 0.0
for _ in range(width): # C sampled successors per action
r, s2 = sim(s, a)
v2 = max(estimate_q(sim, s2, depth - 1, width, gamma, actions).values())
total += r + gamma * v2
q[a] = total / width
return q
def sparse_sampling_action(sim, s, depth, width, gamma, actions):
q = estimate_q(sim, s, depth, width, gamma, actions)
return max(q, key=q.get)Each call at depth makes simulator calls and recursive calls, so a decision costs calls. The recursion is the backward induction of Value Iteration, with every expectation replaced by an average of samples.
Think first What does sparse sampling become in a deterministic environment, and how large is its tree?
All samples of a pair return the same successor, so one is enough: the tree is exhaustive depth- lookahead with leaves, classical search. More generally, merging repeated states at the same depth helps whenever few states are reachable: with only states reachable from the root, the merged tree has nodes (Kearns, Mansour & Ng, 2002).
The guarantee
Truncation. Rewards beyond depth are worth at most , so depth- values are within of infinite-horizon ones.
One level of sampling. At a node, averages independent terms , each in . By Hoeffding's inequality the average is within of its expectation except with probability at most . The first term of pays for a union bound over all the nodes of the tree, the second makes the overall failure probability small.
Errors compound geometrically. If every average is within , the error at depth obeys , so the root's estimates are within of the depth- values, and with truncation within of :
From actions to a policy. An action chosen from estimates within of loses at most in that state, and a policy whose every action loses at most is within of optimal, by the performance difference lemma. With the main term is exactly ; the paper's accounting with these constants covers the rare failures as well.
| Setting | Depth | Width | Tree size | |
|---|---|---|---|---|
| , , , | 0.00625 | 9 | about | about |
| , , , | 0.0025 | 79 | about | about |
Sparse sampling's cost per decision does not depend on the number of states. What does it depend on exponentially?
- The number of actions alone
- The number of states reachable in one step
- The depth , which grows like
- The number of decisions the agent will make
Show the answer
C. The depth , which grows like
The cost is : polynomial in and for each level, but raised to the power , which grows with the effective horizon. Each decision is planned afresh, so the number of decisions only multiplies the total.
The horizon is the price: a lower bound
Build a complete binary tree of depth . Its nodes are the states, the two actions move deterministically to the left or right child, and the leaves lead to an absorbing state. Choose one leaf uniformly at random and let it pay ; every other reward is 0.
From the root, the only reward is reached by walking to , worth about ; a planner that has not found earns nothing from the root. With the depth tuned slightly, -optimality at the root forces the planner to locate .
The simulator reveals a leaf's reward only when that leaf is queried, and every leaf is equally likely to be . Any search strategy needs queries on average:
For and the tree has depth about 44 and leaves. The two theorems bracket the problem: for a fixed the lower bound grows polynomially in , the upper bound like , and Kearns, Mansour and Ng left the gap open. Without further assumptions, exponential dependence on the horizon is the price of independence from the number of states.
Structure is what practical planners exploit. Most problems are not needles in binary trees: a few lines of play matter, many actions are clearly bad after a few samples, and a heuristic can value the leaves. The planners of the next step put their samples where those properties pay.
Adaptive lookahead: rollouts and tree search
Sparse sampling spends its samples uniformly on every branch. Two ideas spend them better.
Rollouts. Fix a cheap base policy . At the current state, estimate each action's value by simulating and then following , averaged over several rollouts, and pick the best. With exact estimates this is one step of policy improvement, so the rollout policy is at least as good as in every state (Policy Iteration), and its cost per decision grows linearly with the horizon instead of exponentially. Tesauro and Galperin (1996) used it to strengthen backgammon programs, and Bertsekas, Tsitsiklis and Wu (1997) developed it for combinatorial optimization. The limit is built in: one improvement step over , no more.
Adaptive tree search. Chang, Fu, Hu and Marcus (2005) chose actions at each node of a sampled tree with a bandit rule, and Kocsis and Szepesvári (2006) turned this into UCT: grow the tree one simulation at a time, choose actions inside it by an upper confidence bound, and estimate new leaves by rollouts (Monte Carlo tree search). Samples flow to the branches that look best, so far smaller trees find good actions when few lines matter. UCT is consistent, its probability of choosing a suboptimal root action tending to zero as simulations grow, but on adversarially built trees it can need far more simulations than uniform sampling (MCTS in Depth: UCT, PUCT & What Search Optimizes).
| Planner | Cost per decision | Guarantee |
|---|---|---|
| Value iteration on the full model | per sweep, about sweeps, once for all states | -optimal everywhere; needs the probabilities |
| Sparse sampling | simulator calls, independent of | -optimal everywhere, in the worst case |
| Rollouts of a base policy | calls | At least as good as , up to sampling error |
| UCT and Monte Carlo tree search | Anytime: as many simulations as time allows | Consistent as simulations grow; no useful worst-case rate |
How many samples does planning need?
If the state space is finite, a generative model also supports the opposite strategy: estimate the whole model, then plan. Draw next states from every pair , form the empirical model , and solve it by value or policy iteration. This certainty-equivalent planner uses samples, and the question is how large must be for its greedy policy to be -optimal in the true MDP, with rewards in .
An MDP has 100 states and 4 actions, with and target . Ignoring logarithmic factors, samples is 10 to what power?
Show the answer
7.6
, that is samples from every state–action pair. Halving multiplies it by 4; moving to multiplies it by 1,000.
The two routes are complementary. Sparse sampling never looks at most states and pays exponentially in the horizon; the plug-in planner pays polynomially in the horizon but needs samples from every state–action pair. A crude Hoeffding analysis of the plug-in planner gives ; the sharp comes from Bernstein's inequality and the law of total variance, which shows that the variances of the returns accumulated along a trajectory are smaller than the worst case suggests (Azar et al., 2013). Between the two routes lie problems with structure, such as few reachable states, features in which the values are linear, or good heuristics at the leaves, and that is where much of the current theory lives.
Key takeaways
- With a generative model, sparse sampling picks -optimal actions at a per-decision cost of simulator calls, independent of the number of states, with and set by , and (Kearns, Mansour & Ng, 2002).
- The exponential dependence on the horizon is unavoidable in general: a reward hidden in one of leaves, , forces queries.
- Rollouts give one step of policy improvement at linear cost, and UCT-style tree search spends samples adaptively; both are consistent but trade worst-case guarantees for practical speed.
- For finite MDPs, planning in an empirical model needs samples, and the plug-in approach attains it (Azar et al.; Agarwal et al.; Li et al.).
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
What can a planner with a generative model do that an agent learning from its own experience cannot?
- Read the transition probabilities directly
- Sample a transition from any state and action it chooses, as often as it likes
- Evaluate every state in one call
- Avoid the exploration problem without any samples at all
Show the answer
B. Sample a transition from any state and action it chooses, as often as it likes
A generative model is a resettable simulator: it returns samples, not probabilities, for any queried pair. An agent acting in the world sees only the states its own trajectory reaches, which is why exploration is hard there and easy here.
Why must any -optimal planner with only a generative model make exponentially many queries in the worst case?
- Because the number of states is exponential
- Because Hoeffding's inequality needs exponentially many samples
- Because the reward can hide in one of leaves of a deterministic tree, with , and only querying that leaf reveals it
- Because the optimal policy is stochastic
Show the answer
C. Because the reward can hide in one of leaves of a deterministic tree, with , and only querying that leaf reveals it
The construction is a needle in a haystack: with all transitions deterministic, sampling noise plays no role; the planner simply has to find one leaf among , and the depth that still matters at accuracy is .
A rollout planner estimates by simulation and acts greedily. What does it guarantee, with exact estimates?
- An optimal policy
- A policy at least as good as in every state: one step of policy improvement
- A policy within of optimal for any base policy
- Nothing, because the rollouts use a suboptimal policy
Show the answer
B. A policy at least as good as in every state: one step of policy improvement
Acting greedily on is policy improvement, so the policy improvement theorem applies. Repeating the step would be policy iteration, which rollouts do not do; that is why rollouts pay off most with a good base policy.
Planning in an empirical model built from samples per state–action pair is minimax optimal. How does its total sample need, , compare with sparse sampling's cost?
- It is worse in every respect
- It is identical up to constants
- It does not depend on the number of states
- It grows only polynomially with the horizon, but linearly with , while sparse sampling is independent of and exponential in the horizon
Show the answer
D. It grows only polynomially with the horizon, but linearly with , while sparse sampling is independent of and exponential in the horizon
The two strategies sit at opposite corners: sample every pair and pay , or sample only around the current state and pay exponentially in the effective horizon. Which is cheaper depends on the size of the state space and on .
Further reading
- M. Kearns, Y. Mansour & A. Y. Ng, "A sparse sampling algorithm for near-optimal planning in large Markov decision processes," Machine Learning 49, 193–208 (2002).
- L. Kocsis & C. Szepesvári, "Bandit based Monte-Carlo planning," Proceedings of ECML (2006).
- M. G. Azar, R. Munos & H. J. Kappen, "Minimax PAC bounds on the sample complexity of reinforcement learning with a generative model," Machine Learning 91(3), 325–349 (2013).
- A. Agarwal, S. Kakade & L. F. Yang, "Model-based reinforcement learning with a generative model is minimax optimal," Proceedings of COLT (2020).
- G. Li, Y. Wei, Y. Chi, Y. Gu & Y. Chen, "Breaking the sample size barrier in model-based reinforcement learning with a generative model," Advances in Neural Information Processing Systems 33 (2020).