Planning in Markov Decision Processes with Gap-Dependent Sample Complexity
Anders Jonsson, Emilie Kaufmann, Pierre Ménard, Omar Darwiche Domingues, Edouard Leurent, Michal Valko
Introduction
In reinforcement learning (RL), an agent repeatedly takes actions and observes rewards in an unknown environment described by a state. Formally, the environment is a Markov Decision Process (MDP) , where is the state space, the action space, a set of transition kernels and a set of reward functions. By taking action in state at step , the agent reaches a state with probability and receives a random reward with mean . A common goal is to learn a policy that maximizes cumulative reward by taking action in state at step . If the agent has access to a generative model, it may plan before acting by generating additional samples in order to improve its estimate of the best action to take next.
In this work, we consider Monte-Carlo planning as the task of recommending a good action to be taken by the agent in a given state , by using samples gathered from a generative model. Let be the maximum cumulative reward, in expectation, that can be obtained from state by first taking action , and let be the recommended action after calls to the generative model. The quality of the action recommendation is measured by its simple regret, defined as .
We propose an algorithm in the fixed confidence setting : after calls to the generative model, the algorithm should return an action such that with probability at least . We prove that its sample complexity is bounded in high probability by a quantity that depends on the sub-optimality gaps of the actions that are applicable in state . We also provide experiments showing its effectiveness. The only assumption that we make on the MDP is that the support of the transition probabilities should have cardinality bounded by , for all , and .
Monte-Carlo Tree Search (MCTS) is a form of Monte-Carlo planning that uses a forward model to sample transitions from the current state, as opposed to a full generative model that can sample anywhere. Most MCTS algorithms sample trajectories from the current state , and are widely used in deterministic games such as Go. The AlphaZero algorithm guides planning using value and policy estimates to generate trajectories that improve these estimates. The MuZero algorithm combines MCTS with a model-based method which has proven useful for stochastic environments. Hence efficient Monte-Carlo planning may be instrumental for learning better policies. Despite their empirical success, little is known about the sample complexity of state-of-the-art MCTS algorithms.
The earliest MCTS algorithm with theoretical guarantees is Sparse Sampling , whose sample complexity is polynomial in in the case (see Lemma 1). However, it is not trajectory-based and does not select actions adaptively, making it very inefficient in practice.
A first category of algorithms rely on optimistic planning , and require additional assumptions: a deterministic MDP , the open loop setting in which policies are sequences of actions instead of state-action mappings (the two are equivalent in MDPs with deterministic transitions), or an MDP with known parameters . For MDPs with stochastic and unknown transitions, polynomial sample complexities have been obtained for StOP , TrailBlazer and SmoothCruiser but the three algorithms suffer from numerical inefficiency, even for . Indeed, StOP explicitly reasons about policies and storing them is very costly, while TrailBlazer and SmoothCruiser require a very large amount of recursive calls even for small MDPs. We remark that popular MCTS algorithms such as UCT are not -correct and do not have provably small sample complexities.
In the setting , BRUE is a trajectory-based algorithm that is anytime and whose sample complexity depends on the smallest sub-optimality gap . For planning in deterministic games, gap-dependent sample complexity bounds were previously provided in a fixed-confidence setting . Our proposal, MDP-GapE, can be viewed as a non-trivial adaptation of the UGapE-MCTS algorithm to planning in MDPs. The defining property of MDP-GapE is that it uses a best arm identification algorithm, UGapE , to select the first action in a trajectory, and performs optimistic planning thereafter, which helps refining confidence intervals on the intermediate Q-values. Best arm identification tools have been previously used for planning in MDPs and UGapE also served as a building block for StOP .
Finally, going beyond worse-case guarantees for RL is an active research direction, and in a different context gap-dependent bounds on the regret have recently been established for tabular MDPs .
Contributions
We present MDP-GapE, a new MCTS algorithm for planning in the setting . MDP-GapE performs efficient Monte-Carlo planning in the following sense: First, it is a simple trajectory-based algorithm which performs well in practice and only relies on a forward model. Second, while most practical MCTS algorithms are not well understood theoretically, we prove upper bounds on the sample complexity of MDP-GapE. Our bounds depend on the sub-optimality gaps associated to the state-action pairs encountered during exploration. This is in contrast to StOP and TrailBlazer, two algorithms for the same setting, whose guarantees depend on a notion of near-optimal nodes which can be harder to interpret, and that can be inefficient in practice. In the anytime setting, BRUE also features a gap-dependent sample complexity, but only through the worst-case gap defined above. As can be seen in Table 1, the upper bound for MDP-GapE given in Corollary 1 improves over that of BRUE as it features the gap of each possible first action , , and scales better with the planning horizon . Furthermore, our proof technique relates the pseudo-counts of any trajectory prefix to the gaps of state-action pairs on this trajectory, which evidences the fact that MDP-GapE does not explore trajectories uniformly.
Learning Framework and Notation
where the supremum is taken over (deterministic) policies , and the expectation is on a trajectory where and for . With this definition, an optimal action in state is .
We assume that there is a maximal number of actions available in each state, and that, for each , the support of is bounded by : that is, is the maximum number of possible next states when applying any action. We further assume that the rewards are bounded in $i,hi\leq h[i,h]=\{i,\ldots,h\}[h]=[1,h]$.
A sequential planning algorithm proceeds as follows. In each episode , the agent uses a deterministic policy on the form to generate a trajectory , where , is a reward with expectation and . After each episode the agent decides whether it should perform a new episode to refine its guess for a near-optimal action, or whether it can stop and make a guess. We denote by the stopping rule of the agent, that is the number of episodes performed, and the guess.
We aim to build an -correct algorithm, that is an algorithm that outputs a guess satisfying
while using as few calls to the generative model (i.e. as few episodes ) as possible.
Our setup permits to propose algorithms for planning in the undiscounted episodic case (in which our bounds will not blow up when ) and in discounted MDPs with infinite horizon. Indeed, choosing such that , an -correct algorithm for the discounted episodic setting recommends an action that is -optimal for the discounted infinite horizon setting.
A (recursive) baseline
Sparse Sampling can be tuned to output a guess that satisfies (1), as specified in the following lemma, which provides a baseline for our undiscounted episodic setting (see Appendix F). Note that Sparse Sampling is not strictly sequential as it does not repeatedly select trajectories.
If , Sparse Sampling using horizon and performing transitions in each node is -correct with sample complexity for .
Structure of the optimal Q-value function
In our algorithm, we will build estimates of the intermediate Q-values, that are useful to compute the optimal Q-value function . Defining
and the optimal action-values can be computed recursively using the Bellman equations, where we use the convention :
Let denote a deterministic optimal policy where, for , , with ties arbitrarily broken. Hence the optimal value in is .
The MDP-GapE Algorithm
In this section we present MDP-GapE, a generalization of UGapE to Monte-Carlo planning. Like BAI-MCTS for games a core component is the construction of confidence intervals on . The construction below generalizes that of OP-MDP for known transition probabilities.
Let be the number of observations of transition , and the sum of rewards obtained when selecting in . We define the empirical transition probabilities and expected rewards as follows, for state-action pairs such that :
As rewards are bounded in $r_{h}(s_{h},a_{h})$ :
In order to define confidence bounds on the values , we introduce a confidence set on the probability vector . We define if and otherwise
where is the set of probability distribution over elements, is an exploration function and is the Kullback-Leibler divergence between two categorical distributions and with supports satisfying .
We now define our confidence bounds on the action values inductively. We use the convention , and for all ,
As explained in Appendix A of , optimizing over these KL confidence sets can be reduced to a linear program with convex constraints, that can be solved efficiently with Newton Iteration, which has complexity where is the desired digit precision.
We provide in Section 4.1 an explicit choice for the exploration functions and that govern the size of the confidence intervals. Note that if the rewards or transitions are deterministic, or if we know , we can adapt our confidence bounds by setting or .
MDP-GapE
As any fixed-confidence algorithm, MDP-GapE depends on the tolerance parameter and the risk parameter . The dependency in is explicit in the stopping rule (4), while the dependency in is in the tuning of the confidence bounds, that depend on .
After trajectories observed, MDP-GapE selects the -st trajectory using the policy where the first action choice is made according to UGapE:
where is the current guess for the best action, which is the action with the smallest upper confidence bound on its gap , and is some challenger:
Then for all remaining steps we follow an optimistic policy, for all ,
and the guess output when stopping is . A generic implementation of MDP-GapE is given in Algorithm 1 in Appendix A, where we also discuss some implementation details. Note that, in sharp contrast with the deterministic stopping rule proposed for Sparse Sampling in Lemma 1, MDP-GapE uses an adaptive stopping rule.
Analysis of MDP-GapE
Recall that MDP-GapE uses policy to select the -st trajectory, , satisfying and .
To define an event that holds with high probability, let (resp. ) be the event that the confidence regions for the mean rewards (resp. transition kernels) are correct:
For a state-action pair , let be the probability of reaching it at step under policy , and let . We define the pseudo-counts of the number of visits of as As is a martingale, the counts should not be too far from the pseudo-counts. Given a rate function , we define the event
Finally, we define to be the intersection of these three events: .
1 Correctness
One can easily prove by induction (see Appendix B) that
In Lemma 2 below, we provide a calibration of the thresholds functions and such that this sufficient condition holds. This result, proved in Appendix C, relies on new time-uniform concentration inequalities that follow from the method of mixtures .
Moreover, the maximum of these three thresholds defined (by continuity when ) as
is such that is non-decreasing and is non-increasing.
2 Sample Complexity
In order to state our results, we define the following sub-optimality gaps. measures the gap in future discounted reward between the optimal action and the action , whereas also takes into account the gap of the second best action and the tolerance level .
Recall that . For all , we let
Our sample complexity bounds follow from the following crucial theorem, which we prove in Appendix D, that relates the pseudo-counts of state-action pairs at time to the corresponding gap.
If holds, every is such that
The number of episodes used by MDP-GapE satisfies
The upper bound on the sample complexity of MDP-GapE that follows from Corollary 1 improves over the sample complexity of Sparse Sampling. It is also smaller than the samples needed for BRUE to have a reasonable upper bound on its simple regret. The improvement is twofold: first, this new bound features the problem dependent gap for each action in state , whereas previous bounds were only expressed with or . Second, it features an improved scaling in .
In particular, using that where is the set of complete trajectories leads to a sample complexity bound featuring all gaps. However, its improvement over the bound of Corollary 1 is not obvious in the general case. For , that is for planning in a deterministic MDP with possibly random rewards, a slightly different proof technique leads to the following improved gap-dependent sample complexity bound (see the proof in Appendix E).
Numerical Experiments
We consider random discounted MDPs with infinite horizon in which the maximal number of successor states and the sparsity of rewards are controlled. The transition kernel is generated as follows: for each transition in , we uniformly pick next states in . The cumulative transition probabilities to these states are computed by sorting numbers uniformly sampled in . The reward kernel is computed by selecting a proportion of the transitions to have non-zero rewards with means sampled uniformly in . The values for these parameters are shown in Table 3(a).
We verify empirically that MDP-GapE is (, )-correct while stopping with a reasonable number of oracle calls. Table 3(b) shows the choice of parameters for the algorithm. For various values of the desired accuracy and of the corresponding planning horizon (see Section 2), we run simulations on 200 random MDPs. We report in Table 4 the distribution of the number of oracle calls and the simple regret of MDP-GapE over these 200 runs. We first observe that MDP-GapE verifies in all simulations, despite the use of smaller exploration functions compared to those prescribed in Lemma 2. We then compare its sample complexity to that of Sparse Sampling, which is deterministic and for which given in Lemma 1 is a tight upper bond. We see that the sample complexity of MDP-GapE is an order of magnitude smaller than that of Sparse Sampling.
Scaling in ε𝜀\varepsilon
Comparison to the state of the art
In the fixed-confidence setting, most existing algorithms are considered theoretical and cannot be applied to practical cases. For instance, for our problem with and , Sparse Sampling and SmoothCruiser both require a fixed budgetIn non-regularized MDPs, SmoothCruiser has the same sample complexity as Sparse Sampling. of at least 8\text{\times}{10}^{9}$n=(\varepsilon,\delta)$-correct algorithm for general MDPs with an easy implementation and a reasonable running time in practice. The only planning algorithms that can be run in practice are in the fixed-budget setting, which we now consider.
Fixed-budget evaluation
We compare MDP-GapE to three existing baselines: first, the KL-OLOP algorithm , which uses the same upper-confidence bounds on the rewards and states values as MDP-GapE, but is restricted to open-loop policies, i.e. sequences of actions only. Second, the BRUE algorithm which explores uniformly and handles closed-loop policies. Third, the popular UCT algorithm , which is also closed-loop and performs optimistic exploration at all depths. UCT and its variants lack theoretical guarantees, but they have been shown successful empirically in many applications. For each algorithm, we tune the planning horizon similarly to KL-OLOP, by dividing the available budget into episodes, where is the largest integer such that , and choose . The exploration functions are those of KL-OLOP and depend on : . Again, we perform 200 simulations and report in Figure 2 the mean simple regret, along with its confidence interval. We observe that MDP-GapE compares favourably with these baselines in the high-budget regime.
Conclusion
We proposed a new, efficient algorithm for Monte-Carlo planning in Markov Decision Processes, that combines tools from best arm identification and optimistic planning and exploits tight confidence regions on mean rewards and transitions probabilities. We proved that MDP-GapE attains the smallest existing gap-dependent sample complexity bound for general MDPs with stochastic rewards and transitions, when the branching factor is finite. In future work, we will investigate the worse-case complexity of MDP-GapE, that is try to derive an upper bound on its sample complexity that only features and some appropriate notion of near-optimality dimension.
Acknowledgments
Anders Jonsson is partially supported by the Spanish grants TIN2015-67959 and PCIN-2017-082.
References
Appendix A Detailed Algorithm
In this section we provide a detailed algorithm for MDP-GapE, namely Algorithm 1.
There are different ways to store and update the confidence bounds on the -value (that is, to specify the UpdateBounds subroutine) according to how we merge information across states.
The most obvious one, suggested by previous work (and also implemented for our experiments) does not merge information at all and builds a search tree in which a node at depth is identified with the sequence of states and actions that leads to it. It leads to a very simple update: after each trajectory, one only needs to update the confidence bounds, and , of the visited action-state pairs. Another option is to merge information for the same states and a fixed depth. But in this case the search tree becomes a graph and after each trajectory we need to re-compute the values for all stored state action pairs at each depth.
Appendix B Correctness of MDP-GapE
In this section we prove the correctness of MDP-GapE under the assumption that the event holds. Concretely, we prove by induction that
The base case is given by , in which case by our previous convention,
For the inductive case, assume that the inclusion holds at depth . Then we have
Appendix C Concentration Events
In this section we prove that the event holds with high probability. But before we need several concentration inequalities.
Let be i.i.d. samples from a distribution supported over , of probabilities given by , where is the probability simplex of dimension . We denote by the empirical vector of probabilities, i.e. for all
For all , for all ,
We apply the method of mixture with a Dirichlet prior on the mean parameter of the exponential family formed by the set of categorical distribution on . Letting
be the log-partition function, the following quantity is a martingale:
where in the second inequality we used Lemma 3. Now we choose the uniform prior . Hence we get
It remains to upper-bound the entropic term
Thus we can lower bound the martingale as follows
Using the fact that, for any supermartingale it holds that
which is a well-known property used in the method of mixtures (see ), we conclude that
where and .
There is a more general way than the ad hoc one below to prove the result. First note that
C.2 Deviation Inequality for Bounded Distribution
Let be i.i.d. samples from a distribution of mean supported on $\widehat{\mu}_{n}$ the empirical mean
It is well known, see , that we can "project" the distribution on a Bernoulli distribution with the same mean and then use deviation inequality for Bernoulli to concentrate the empirical mean. This method dos not lead to the sharpest confidence intervals but it provides a good trade-off between complexity computation and accuracy.
For all distribution of mean supported on the unit interval, for all ,
Then we can follow the proof of Proportion 1 with and where is only a supermartingale but this does not change the result as the property (6) still holds. Thus the proposition follows by specifying Proposition 1 to the case . ∎
C.3 Deviation Inequality for sequence of Bernoulli Random Variables
C.4 Proof of Lemma 2
We just prove that each event forming holds with high probability. For the first one using Proposition 2, since the reward are bounded in the unit interval we have
where we used Doob’s optional skipping in the second inequality in order to apply Proposition 2, see Section 4.1 of . Similarly for the confidence regions for the probabilities transitions, using Proposition 1 we obtain
It remains to control the counts, using Proposition 3,
where we used that by definition of the pseudo-counts
Appendix D Proof of Theorem 1
In this section we present the proof of Theorem 1, which relies on three important ingredients. The first ingredient is Lemma 5 in Appendix D.1, which provides a relationship between the state-action gaps and the diameter of the confidence intervals. The second ingredient is Lemma 8 in Appendix D.2, which provides an upper bound on the diameter . The third ingredient is Lemma 9 in Appendix D.3, which relates the actual counts of state-action pairs to the corresponding pseudo-counts. After providing these ingredients, we present the detailed proof of Theorem 1 in Appendix D.4.
Before stating Lemma 5, we prove an important property of the UGapE algorithm. We recall that and are the candidate best action and its challenger, defined as
The policy at the root is then defined as .
For all , the following inequalities hold:
,
.
We show the first part by contradiction. If the inequality does not hold, we obtain
where the last inequality follows from the definition of . Combining the two inequalities yields , which contradicts the definition of .
For the second part, if then the algorithm has not yet stopped, implying
As a consequence of Lemma 4, we can upper bound any confidence interval involving and .
For each pair of actions , it holds that
If holds and , for all and ,
The proof for is immediate from the correctness of the confidence bounds implied by , and the fact that the selection is optimistic:
For , we prove separately that each term in the max is smaller that the right hand side of desired inequality, that is
Now, by definition of the stopping rule, if , . Using the first property in Lemma 4 yields
Then, exploiting the fact that the action with largest UCB is either or , it holds on that
Using Corollary 3 to further upper bound the right hand side yields
Finally, one can also write, on the event ,
In each of the four possible choices of , Corollary 3 implies that
Lemma 5 follows by combining (7), (8) and (9) with the definition of . ∎
D.2 Upper bounding the diameters
In this section we state and prove Lemma 8. We use the notation to upper bound the discounted reward in steps. As a first step, we prove the following auxiliary lemma.
If holds, for each , each and each ,
where we have used Pinsker’s inequality to bound the -norm using the KL divergence, combined with the fact that both and are close to the empirical transition probabilities under . ∎
As a consequence, we can express the upper bound in terms of the true transition probabilities .
If holds, for each and each ,
We can also express the lower bound in terms of the transition probabilities and policy .
If holds, for each and each ,
We exploit the fact that for each , each and each ,
The proof is analogous to the proof of Lemma 6. We can now write
If holds, for all , and ,
The bound on the diameter follows directly from Corollary 4 and Lemma 7:
where we used and Pinsker’s inequality to bound
To obtain the final expression in Lemma 8, we observe that it also trivially holds that
The conclusion follows by observing that one can get rid of the maximum with 1 in the denominator by using instead the convention . ∎
D.3 Relating counts to pseudo-counts
D.4 Detailed proof of Theorem 1
Using Lemma 5 and the fact that if yields
By induction, one then obtains the following upper bound:
Summing for the inequalities given by (10) yields
The rest of the proof consists in upper bounding in terms of the pseudo counts .
Step 4: from counts to pseudo-counts
Using Lemma 9 to relate the counts to the conditional pseudo-counts, one can write
Since and , we can write
where . The latter is an arithmetico-geometric sum that can be upper bounded as
Appendix E Proof of Theorem 2
The proof of Theorem 2 uses the same ingredients as the proof of Theorem 1: Lemma 5 which relates the gaps to the diameters of the confidence intervals and a counterpart of Lemma 8 for the deterministic case, stated below.
If holds, and is the -st trajectory generated by MDP-GapE, for all ,
It follows from Lemma 11 that for all , along the -st trajectory ,
Using Lemma 5, if , if is the trajectory selected at time , either or
It follows that for any trajectory ,
The conclusion follows from Lemma 12 and from the fact that .
Appendix F Sample complexity of Sparse Sampling in the Fixed-Confidence Setting
For simplicity, and without loss of generality, assume that the reward function is known. Let . Sparse Sampling builds, recursively, the estimates and for , starting from and for all . Then, from a target state-action pair , it samples transitions for and computes:
For an initial state , its output is for all . For any state , consider the events
defined for , where for some .
with probability at least , where . Finally, we let and solve for , obtaining
Thus predicting after sampled transitions we have
Appendix G A Technical Lemma
We state and prove below a technical result that permits to obtain an upper bound on from a condition of the form , like the one which appears in Theorem 1.
Let and . If then
Since and for all , we have