Q-Learning: Convergence & Sample Complexity
From Watkins and Dayan’s proof to sharp sample-complexity bounds.
Watkins argued in 1989 that Q-learning finds the optimal action values, and Watkins and Dayan made the proof rigorous in 1992 with a striking construction: an artificial MDP, built from the agent's own memories, whose optimal values are exactly the Q-table. How fast Q-learning gets there took three more decades to settle. With a generative model it needs on the order of samples, and with the step sizes used in practice it cannot do better: one factor of the effective horizon more than the best possible algorithm. That extra factor is the price of the maximum.
What you’ll learn
- State Watkins and Dayan's convergence theorem with its conditions, and prove that the Q-table equals the optimal action values of the action-replay process.
- Explain how the step-size schedule sets the rate: why steps can need time exponential in the effective horizon while polynomial steps need polynomial time.
- State the sharp sample complexity of synchronous and asynchronous Q-learning, the matching lower bound for Q-learning and the minimax limit, and explain heuristically where the extra horizon factor comes from.
- Describe how variance reduction attains the minimax rate, and how optimistic Q-learning explores episodic MDPs with near-optimal regret.
The action-replay process
At level 0 no card lies above the bottom one, so every action ends at once with its initial value:
Suppose , and update is of the pair . For every other pair the deck at level is the deck at level , so nothing changes. For , card is on top: with probability it is replayed (reward , then the state , worth by the induction hypothesis); otherwise the process continues exactly as from level :
The middle expression is Q-learning's update. By induction, on every sample path and at every , the Q-table is the optimal action-value function of the ARP at level . Nothing is approximate here: Q-learning solves, exactly and incrementally, an MDP made of its own experience.
A pair has been updated four times, with step size at its -th update, so its Q-value is the plain average of its four targets. At the top level, with what probability does the ARP replay each of the four cards?
- from newest to oldest, and for the bottom card
- Only the newest card, with probability 1
- each, and the bottom card is never reached
- each, the fifth fifth going to the bottom card
Show the answer
C. each, and the bottom card is never reached
Newest: . Next: . Then , and the oldest , which exhausts the probability because . With steps the ARP replays a uniformly random past experience: its top level is the empirical model of the data. A constant step instead favors recent cards geometrically, and with some probability always reaches the bottom: the initial guess never fully disappears.
From the ARP to the real MDP. Two facts finish the proof. First, the card replayed for from a high level is drawn from the pair's past experiences, card with probability (indices running over that pair's updates), the very weights with which Q-learning averages its targets. Under the two Robbins–Monro conditions these weighted rewards and next-state frequencies converge to and . Second, makes deep descents rare: the probability of skipping every card down to some fixed level is . Because , only the first steps matter, up to , and for steps from a high enough level the ARP behaves almost like the real MDP. Its optimal values, which are , therefore approach .
The proofs used today are shorter. Jaakkola, Jordan and Singh (1994) and Tsitsiklis (1994) treat Q-learning as asynchronous stochastic approximation of , a -contraction in the max norm since , driven by martingale-difference noise with per-pair Robbins–Monro steps. Convergence of TD: Stochastic Approximation carries out that template for TD(0); for Q-learning only the operator changes. Neither kind of proof says how fast.
How fast? Step sizes and the effective horizon
Any Robbins–Monro schedule gives convergence; the rate depends heavily on which one. Even-Dar and Mansour (2003) gave the first explicit bounds and found a sharp dichotomy. Their main setting is synchronous Q-learning: in each iteration every pair is updated once, from a fresh sample of its next state.
The lower-bound example is the one-state loop of Convergence of TD: each step shrinks the error only by the factor , because bootstrapping feeds most of the old error back into the target, so after updates the error is of order .
Uneven sampling makes this worse. Szepesvári (1997) showed that with steps, , and pairs sampled independently from a fixed distribution in which the rarest pair has probability and the most common , the error decays asymptotically like when , where , and like otherwise. The rarest pair sets the pace for everyone, and its rarity enters the exponent.
In Even-Dar and Mansour's bound for , the second term, , explodes as . What does it account for?
- Averaging out the noise in the sampled targets
- Forgetting the initial values: the total step size grows only like
- The time needed to visit every pair at least once
- The upward bias of the maximum
Show the answer
B. Forgetting the initial values: the total step size grows only like
The contraction removes the initial error at rate per unit of accumulated step size, roughly . With the sum is about , so must reach order . At the sum grows only like , which is exactly the exponential slowness of linear steps. The first term is the price of noise, and it worsens as falls toward ; balances the two.
Sample complexity: tight at (1 − γ)⁻⁴
To count samples cleanly, assume a generative model: in each iteration, synchronous Q-learning draws one next state for every pair, samples per iteration, and applies the sampled backup to every entry. Rewards lie in , so values lie in , and the goal is entrywise accuracy . Bounds of order stood for years; the gap was closed from both sides in 2021.
No algorithm can beat order samples, up to logarithms (Azar, Munos & Kappen, 2013), and the model-based plug-in method, which estimates from the samples and solves the estimated MDP exactly, attains that rate (Azar et al., 2013, for small ; Agarwal, Kakade & Yang, 2020, over a wider range). Plain Q-learning is suboptimal by exactly one factor of the horizon. The lower-bound instance shows why. The calculation below is a heuristic that reproduces both exponents; it is not the proof.
The instance. State 1 has two identical actions: each pays 1, then stays in state 1 with probability and otherwise moves to an absorbing state worth 0. State 2 has the same dynamics with a single action. Both are worth
The noise. One sampled next state per iteration makes the backup's variance of order , not , because the self-loop almost never breaks:
State 2 (TD). With a constant step , the error obeys , so its stationary variance is about . Keeping it below needs , and the contraction then needs about iterations:
State 1 (Q-learning). Both actions bootstrap from the same , so their difference does not accumulate through the loop; its variance is only about . The maximum picks the luckier action, adding a bias of to every target, and the self-loop compounds it over the effective horizon :
Keeping the bias below forces , one factor of smaller than TD's step, and the iteration count grows by the same factor. This is the "over-estimation" that Li et al. make rigorous: their proof analyzes state 2 for steps that are too small or too large, and state 1, with its two identical actions, for everything in between.
Asynchronous Q-learning. With one trajectory from a behavior policy whose stationary state–action distribution has smallest entry and mixing time , Li et al. also show that constant steps reach accuracy after samples, with a matching lower bound for the first term. Since , the first term generalizes the synchronous rate, and the second is a burn-in for the Markov chain to mix. Earlier analyses scaled at least as (Li, Wei, Chi, Gu & Chen, 2020; Qu & Wierman, 2020).
The effective horizon grows from 10 to 100 ( from 0.9 to 0.99). By what factor does Q-learning's sample bound grow, and by what factor does the minimax limit grow, ignoring logarithms?
- Both by 100
- Q-learning by 10,000; the minimax limit by 1,000
- Q-learning by 1,000; the minimax limit by 100
- Q-learning by 100,000; the minimax limit by 10,000
Show the answer
B. Q-learning by 10,000; the minimax limit by 1,000
goes from to and from to . At long horizons the gap between Q-learning and the best possible method is itself a factor of 100.
Closing the gap, and exploring with optimism
Variance reduction. Wainwright (2019) attacked the noise, not the maximum. Work in epochs. At the start of an epoch, freeze a reference and estimate its backup accurately from many fresh samples. Within the epoch, run Q-learning on a recentered update, in which the same fresh samples enter both sampled backups:
Qbar ← Q0
for epoch m = 1, 2, …, M:
Tref ← average of N_m sampled backups T̂_i(Qbar) # N_m fresh next states per pair
Q ← Qbar
for k = 1, …, K:
draw one fresh next state per pair → sampled backup operator T̂_k
Q ← (1 − α_k)·Q + α_k·[ T̂_k(Q) − T̂_k(Qbar) + Tref ] # same samples in both T̂_k terms
Qbar ← QVariance-reduced Q-learning, in the style of SVRG. with the sampled . The expected update is still , but the noise of is proportional to , which is small once the epoch has started near its target.
With suitably chosen epoch lengths and recentering sample sizes, and rescaled linear steps inside each epoch, variance-reduced Q-learning needs samples for every : minimax optimal, and model-free. The maximum is still there; what shrinks is the noise it acts on, and with it the bias of the previous step.
Exploration with optimism. Without a generative model the agent must also find the informative pairs. In episodic MDPs with steps per episode, episodes and steps, ε-greedy Q-learning can need a number of episodes exponential in . Jin, Allen-Zhu, Bubeck and Jordan (2018) made Q-learning optimistic instead: values start at , every update adds an exploration bonus that shrinks with the visit count , and the agent acts greedily on these upper confidence bounds:
The step rather than is essential: gives the first visits, whose targets used wildly wrong next-step values, a permanent equal share, and the error compounds over the steps, whereas keeps weight on roughly the last fraction of visits. With Bernstein-type bonuses the regret is plus lower-order terms (with simpler Hoeffding bonuses, ), against a lower bound of . Zhang, Zhou and Ji (2020) closed the remaining with a reference–advantage decomposition, variance reduction again, reaching for large . Optimism in MDPs: UCRL2 & UCBVI covers the model-based side.
Key takeaways
- Watkins and Dayan's proof: Q-learning's table equals, exactly, the optimal action values of an action-replay process built from experience, and that process approaches the real MDP when and for every pair.
- The step-size schedule sets the rate: steps can need time exponential in ; polynomial steps need time polynomial in it, best around in Even-Dar and Mansour's bound; uneven sampling slows steps further.
- With a generative model, Q-learning with rescaled linear or constant steps needs order samples, and this is tight; the minimax limit, attained by model-based plug-in estimates, is one horizon factor lower, and with a single action (TD) the gap vanishes.
- The extra factor is maximization bias compounded by bootstrapping. Recentering the noise (variance-reduced Q-learning) removes it; optimistic Q-learning with step explores episodic MDPs with regret , and reference–advantage decomposition reaches the lower bound.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In Watkins and Dayan's proof, how is the Q-table after updates related to the action-replay process?
- It is an unbiased estimate of the ARP's optimal values
- It equals the ARP's optimal action values at level , exactly, on every sample path
- The ARP is the true MDP, and the Q-table approximates its values
- It is an upper bound on the ARP's optimal values
Show the answer
B. It equals the ARP's optimal action values at level , exactly, on every sample path
By induction on , the ARP's Bellman optimality equation at level is Q-learning's update, so exactly. All the probability in the proof goes into showing that the ARP, seen from high levels, approaches the real MDP.
In the hard instance behind the lower bound, why must Q-learning's step size be of order , while TD learning gets away with ?
- Because Q-learning has twice as many values to estimate
- Because its sampled targets have a larger variance than TD's
- Because the generative model gives it fewer samples per pair
- Because the maximum over two identical, noisy action values adds an upward bias at every update, the self-loop compounds it over the effective horizon, and only a smaller step keeps it below
Show the answer
D. Because the maximum over two identical, noisy action values adds an upward bias at every update, the self-loop compounds it over the effective horizon, and only a smaller step keeps it below
The two actions in state 1 have identical true values, so the maximum of their estimates is biased upward by an amount of order . Bootstrapping through the self-loop multiplies that by about . Holding the bias below costs one extra factor of in the step size, hence in the number of iterations. A one-action state has no maximum and no such bias.
What lets variance-reduced Q-learning reach the minimax rate ?
- Recentering: each update uses plus an accurate estimate of , so its noise scales with
- Two Q-tables, one choosing the maximizing action and one valuing it
- Linear step sizes , which average the noise exactly
- Exploration bonuses that make every estimate optimistic
Show the answer
A. Recentering: each update uses plus an accurate estimate of , so its noise scales with
The expected update is unchanged, but the noisy part is now the difference of two sampled backups computed with the same samples, which is small when is close to the reference. The costly accurate backup at the reference is computed once per epoch. Less noise means less maximization bias and permits larger steps.
Optimistic Q-learning for episodic MDPs uses the step size at the -th visit of a pair. Why not the sample-average step ?
- Because violates the Robbins–Monro conditions
- Because gives every early target an equal, permanent share, and those targets bootstrapped from badly wrong values of later steps; the error compounds across the steps of an episode
- Because larger steps reduce the variance of the targets
- Because the exploration bonus would otherwise become negative
Show the answer
B. Because gives every early target an equal, permanent share, and those targets bootstrapped from badly wrong values of later steps; the error compounds across the steps of an episode
Early targets used next-step values that were themselves far off. Averaging them in forever, as does, leaves errors that compound layer by layer, exponentially in . The step concentrates the weight on roughly the most recent fraction of visits, so information can propagate smoothly through the layers.
Further reading
- C. J. C. H. Watkins & P. Dayan, "Q-learning," Machine Learning 8, 279–292 (1992).
- E. Even-Dar & Y. Mansour, "Learning rates for Q-learning," Journal of Machine Learning Research 5, 1–25 (2003).
- G. Li, C. Cai, Y. Chen, Y. Wei & Y. Chi, "Is Q-learning minimax optimal? A tight sample complexity analysis," Operations Research 72(1), 222–236 (2024).
- M. J. Wainwright, "Variance-reduced Q-learning is minimax optimal," arXiv:1906.04697 (2019).
- C. Jin, Z. Allen-Zhu, S. Bubeck & M. I. Jordan, "Is Q-learning provably efficient?," Advances in Neural Information Processing Systems 31 (2018).