{'fraction_non_alphanumeric': 0.03550084175084175, 'fraction_numerical': 0.01191077441077441, 'mean_word_length': 4.538578088578088, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Better Optimism By Bayes: Adaptive Planning with Rich Models

The computational costs of inference and planning have confined Bayesian model-based reinforcement learning to one of two dismal fates: powerful Bayes-adaptive planning but only for simplistic models, or powerful, Bayesian non-parametric models but using simple, myopic planning strategies such as Thompson sampling. We ask whether it is feasible and truly beneficial to combine rich probabilistic models with a closer approximation to fully Bayesian planning. First, we use a collection of counterexamples to show formal problems with the over-optimism inherent in Thompson sampling. Then we leverage state-of-the-art techniques in efficient Bayes-adaptive planning and non-parametric Bayesian methods to perform qualitatively better than both existing conventional algorithms and Thompson sampling on two contextual bandit-like problems.

The computational costs of inference and planning have confined Bayesian model-based reinforcement learning to one of two dismal fates: powerful Bayes-adaptive planning but only for simplistic models, or powerful, Bayesian non-parametric models but using simple, myopic planning strategies such as Thompson sampling. We ask whether it is feasible and truly beneficial to combine rich probabilistic models with a closer approximation to fully Bayesian planning. First, we use a collection of counterexamples to show formal problems with the over-optimism inherent in Thompson sampling. Then we leverage state-of-theart techniques in efficient Bayes-adaptive planning and non-parametric Bayesian methods to perform qualitatively better than both existing conventional algorithms and Thompson sampling on two contextual bandit-like problems.
As computer power increases and statistical methods improve, there is an increasingly rich range and variety of probabilistic models of the world. Models embody inductive biases, allowing appropriately confident inferences to be drawn from limited observations. One domain that should benefit markedly from such models is planning and control -models arbitrate the exquisite balance between safe exploration and lucrative exploitation.
A general and powerful solution to this balancing act involves forward-looking Bayesian planning in the face of partial observability, which treats the exploration-exploitation trade-off as an optimization problem, squeezing the greatest benefit from each choice. Unfortunately, this is notoriously computationally costly, particularly for complex models, leaving open the possibility that it might not be justified compared to heuristic approaches that may perform very similarly at a much reduced computational cost, for instance treating the tradeoff as a learning problem in a regret setting, focusing on an asymptotic requirement to discover the optimal solution (to avoid accumulating regret).
The motivation for this paper is to demonstrate the practical power of Bayesian planning. We show that, despite the arduous optimization problem, sample-based planning approximations can excel with rich models in realistic settings -here a challenging exploration-exploitation task derived from a real dataset (the UCI 'mushroom' task)even when the data have not been generated from the prior. By contrast, we show that the benefits of Bayesian inference can be squandered by more myopic forms of planning -such as the provably over-optimistic Thompson Sampling -which fails to account for risk in this task and performs poorly. The experimental results highlight the fact that the Bayesoptimal behavior adapts its exploration strategy as a function of the cost, the horizon, and the uncertainty in a non-trivial way. We also consider an extension of the model to a case of more general subtasks, including subtasks that are themselves small MDPs (in the suppl. material, Section S4).
The paper is organized as follows: first, we discuss modelbased Bayesian reinforcement learning (RL), outline some existing planning algorithms for this case and show why Thompson sampling's over-optimism can be deleterious. Next, we introduce an exploration-exploitation domain that motivates a statistical model for a class of MDPs with shared structure across sequences of tasks. We provide empirical results on a version of the domain that uses real data coming from a popular supervised learning problem (mushroom classification) along with a simulated extension. Finally, we discuss related work.

Model-based Bayesian RL
We consider a Bayes-Adaptive planner (Duff 2002), which starts with a prior P (P) over models of the environmental dynamics, progressively receives data D through controlled interaction with the environment, and updates its posterior distribution over models using Bayes-rule P (P | D) ∝ P (D | P)P (P). Actions are intended to maximize an expected discounted return criterion E[ ∞ t=0 γ t r t ], where γ < 1 is the discount factor and r t is the random reward obtained at time t. In an uncertain world, this requires balancing exploration and exploitation. Here, the discount factor γ plays the crucial role of arbitrating the relative importance of future rewards. In general, a low γ does not warrant much exploration because future exploitation will be heavily downweighted. The opposite is true as γ → 1. A clear illustration of these γ-dependent exploration-exploitation Bayesian policies can be found in the Gittins indices (Gittins, Weber, and Glazebrook 1989). 1 The (Bayes-)optimal strategy integrates over how the current belief P (P | D) could be transformed in the light of (imaginary) possible future data. The resulting policy is well known to be the solution to an augmented Markov Decision Process (MDP), whose details we defer to the suppl. material, Section S1. Finding the exact Bayes-optimal policy is computationally intractable even for tiny state spaces, since (a) the augmented state space is either continuous or discrete and potentially unbounded; and (b) the transitions of the augmented MDP require integration over the full posterior. Although this operation can be trivial and closedform for some simple probabilistic models (e.g., independent Dirichlet-Multinomial), it is intractable for most rich models.
A common solution to (b) is to use approximate inference methods, such as Markov chain Monte Carlo (MCMC). This fits snugly with a common heuristic for (a), in which the planning problem is side-stepped by sampling from the posterior but only planning myopically. We describe one such method called Thompson Sampling in the section below, but show that it is no panacea.
A potentially more powerful class of approximate solutions to (a) that should be capable of handling large state spaces and complex models involves sample-based forwardsearch methods. Algorithms such as Sparse Sampling (Wang et al. 2005) or BAMCP (Guez, Silver, and Dayan 2012) do not plan myopically; they approximate Bayes-adaptive planning directly -albeit at a computational cost. It had been unclear how to integrate these methods with approximate, MCMC, approaches to (b). However, recent algorithmic developments (Guez, Silver, and Dayan 2013) provide a practical way to use approximate inference schemes to perform sample-based planning with sophisticated models.

Thompson Sampling
Thompson Sampling (TS) (Thompson 1933) is a myopic planning method that selects actions at each step by 1) drawing a single sample of the dynamics from the posterior distribution P (P | D) ; 2) greedily solving the corresponding sampled MDP; and 3) choosing the optimal action of this MDP at the current state. Though heuristically myopic from the perspective of Bayes-adaptivity, TS is computationally cheap, and has been proven both empirically (Chapelle and Li 2011) and theoretically to perform well in various domains (including reaching theoretical regret lower-bounds for multi-armed bandits (Agrawal and Goyal 2011)). As mentioned, it fits well with complex, e.g., Bayesian nonparametric, models that in any case are handled via MCMC sampling (Doshi-Velez et al. 2010).
Intuitively, TS generates optimistic values in unknown parts of the MDP where the posterior entropy over its samples is large. This forces the agent to visit these regions. However, to show that this way of deriving optimism for exploration is not always beneficial, we consider two simple, and yet particularly pernicious, classes of counter-example; other failure modes are illustrated in the results section below.
Example 1 Consider an MDP that involves a linear chain of 2x + 1 states. Each interior state admits 2 determinis-tic actions: going left or right. The only source of reward (r = 1) is at either one or other end. The agent starts in the middle (state x + 1), and knows everything except the end which delivers the reward; each of the two MDPs P has prior probability P (P) = 1 2 . The episode terminates after the reward is obtained. See Figure 1 for an illustration. Critically, the only transition that changes this belief is at an end. At each step, TS samples one of the chains, and so heads for the end which that sample suggests is rewarding. Since this depends on an unbiased coin flip, TS is effectively performing a random walk with probability 1 2 of moving in either direction, and so takes O(x 2 ) time to reach an end (Moon 1973). This is much worse than the linear time of the Bayes-optimal policy which commits to a given direction by tie-breaking in the first step and then maintains this direction to the end of the chain. One might ascribe this failure to the fact that TS was developed for multi-armed bandits, which lack temporally extended structure. TS has duly been adapted to the MDP setting with the goal of controlling the expected regret. For instance, the PSRL algorithm (Osband, Russo, and Van Roy 2013), which was inspired by Bayesian DP (Strens 2000), samples an MDP from the current posterior and executes its optimal policy for several steps (or an entire episode). This way of exploring an MDP bypasses the TS's lack of commitment in Example 1, but can still be problematic for discounted objectives, as illustrated in Example 2 (Supp. material).
The BOSS (Asmuth et al. 2009) algorithm is a more complicated construction that combines multiple posterior samples, Examples 3-4 (Supp. material) illustrate a similar issue with the kind of optimism it generates for exploration.

Non-myopic planning: Forward-search
Bayesian planning avoids myopia by integrating over the evolution of possible future beliefs. Sample-based forwardsearch planning algorithms such as Sparse Sampling (Wang et al. 2005) perform such integrations, but they are generally not able to deal with approximate inference schemes that are necessary to handle rich probabilistic models.
The Bayes-Adaptive Monte-Carlo Planning (BAMCP) algorithm is a forward-search, sample-based Bayes-adaptive planning algorithm based on POMCP (Silver and Veness 2010) that is guaranteed to converge to the Bayes-optimal solution, even when combined with MCMC-based inference (Guez, Silver, and Dayan 2012;. Despite its lack of finite-time guarantees, it displays good empirical performance on a number of tasks. BAMCP compounds the advantages of sparse-sampling (Wang et al. 2005) and UCT (Kocsis and Szepesvári 2006) to increase search efficiency. It shares with TS the use of samples taken from the posterior; but combines many samples in a search tree to be able to plan less myopically. Critically, like POMCP, BAMCP involves root sampling, in which samples are only generated for the current history from the distribution P (P |h t ) and are then filtered forward. Beliefs need not then be updated at each step in the (imagined) search tree (Wang et al. 2005;Ross and Pineau 2008;Asmuth and Littman 2011). Thus, if T is the search horizon and K is the number of simulations, then BAMCP (with root sampling) requires O(K) samples from the posterior and one belief update, instead of O(T K) samples with many belief updates. For these reasons, we chose BAMCP for our forward-search planning algorithm in this paper. For completeness, the BAMCP algorithm is specified in the supplementary material; refer to (Guez, Silver, and Dayan 2012; for more details.

Statistical models of MDPs
There is a huge range of possible models for complex domains. Understanding when and how they apply is a whole subject in its own right. Here, we adopt a strategy that has been very successful in other areas of statistical modeling, namely using a Bayesian non-parametric model (Orbanz and Teh 2010). This permits complexity to scale as observations accumulate, while carefully parameterizing how structure is likely to repeat.
In section 2.2, we consider a rich, non-parametric, task that is an extension of a contextual bandit problem. However, although solving a wholly artificial task is revealing about the differences between different methods of planning, it says little about performance in real cases in which the data were (likely) not generated from the model. Thus we first motivate this rich model as a generalization of a realistic exploration task.

The mushroom exploration task
The Mushroom Dataset from the UCI repository (Bache and Lichman 2013) contains 8124 instances of gilled mushrooms from 23 different species in the Agaricus and Lepiota family, each of which is described by 22 discrete attributes (e.g., color, odor, ring type) and whether the mushroom is poisonous or edible (51.8% of all instances are edible). We build an MDP based on the data as follows, at each point in time the agent is faced with the attributes of a random mushroom from the dataset, and has to choose whether to eat or ignore it. Ignoring a mushroom has no consequence; eating an edible mushroom is rewarding (r = 5); but eating a poisonous mushroom incurs a large cost (r = −15). This is illustrated in Figure 2a. The agent may be provided with some initial 'free' observations of the attributes and edibility of a set of mushrooms.
This problem is conventionally thought of in terms of supervised learning. However, since the agent is allowed to ignore a mushroom, it is actually more akin to a contextual bandit task (Langford and Zhang 2007). However in our case, unlike most past work on contextual bandits, early rewards are more valuable than later ones, characterized by a discount factor γ. This is a critical difference from explo- shares with TS the use of samples taken from the posterior; but combines many samples in a search tree to be able to plan less myopically. Critically, like POMCP, BAMCP involves root sampling, in which samples are only generated for the current history from the distribution P (P |h t ) and are then filtered forward. Beliefs need not then be updated at each step in the (imagined) search tree (Wang et al. 2005;Ross and Pineau 2008;Asmuth and Littman 2011). Thus, if T is the search horizon and K is the number of simulations, then BAMCP (with root sampling) requires O(K) samples from the posterior and one belief update, instead of O(T K) samples with many belief updates. For these reasons, we chose BAMCP for our forward-search planning algorithm in this paper. For completeness, the BAMCP algorithm is specified in the supplementary material; refer to (Guez, Silver, and Dayan 2012; for more details.

Statistical models of MDPs
There is a huge range of possible models for complex domains. Understanding when and how they apply is a whole subject in its own right. Here, we adopt a strategy that has been very successful in other areas of statistical modeling, namely using a Bayesian non-parametric model (Orbanz and Teh 2010). This permits complexity to scale as observations accumulate, while carefully parameterizing how structure is likely to repeat. In section 2.2, we consider a rich, non-parametric, task that is an extension of a contextual bandit problem. However, although solving a wholly artificial task is revealing about the differences between different methods of planning, it says little about performance in real cases in which the data were (likely) not generated from the model. Thus we first motivate this rich model as a generalization of a realistic exploration task.

The mushroom exploration task
The Mushroom Dataset from the UCI repository (Bache and Lichman 2013) contains 8124 instances of gilled mushrooms from 23 different species in the Agaricus and Lepiota family, each of which is described by 22 discrete attributes (e.g., color, odor, ring type) and whether the mushroom is poisonous or edible (51.8% of all instances are edible). We build an MDP based on the data as follows, at each point in time the agent is faced with the attributes of a random mushroom from the dataset, and has to choose whether to eat or ignore it. Ignoring a mushroom has no consequence; eating an edible mushroom is rewarding (r = 5); but eating a poisonous mushroom incurs a large cost (r = −15). This is illustrated in Figure 2a. The agent may be provided with some initial 'free' observations of the attributes and edibility of a set of mushrooms.
This problem is conventionally thought of in terms of supervised learning. However, since the agent is allowed to ignore a mushroom, it is actually more akin to a contextual bandit task (Langford and Zhang 2007). However in our case, unlike most past work on contextual bandits, early rewards are more valuable than later ones, characterized by a discount factor γ. This is a critical difference from explo- Figure 2: (a) Illustration of the mushroom exploration domain, the rows represent the sequence of mushrooms, with the value of different attributes being displayed on each column. The agent may eat the mushroom to obtain a reward/cost (green/red circle) or choose to ignore it (black circle). (b) Example of a sample sequence of tasks from Section 2.2 with C= 3, A = 3. The left columns indicate the context variables (each color represent a possible value), and the right columns indicate the rewards that have been observed in each task (black when arm has not been pulled). On the left, the true clustering of the tasks (shared mixture component) is displayed. The dictionary of context variables is composed of D = 5 different colors in this case.
ration objectives based on regret that are dominated by the long-term behavior of the agent. More formally, the mushroom MDP consists of a sequence of mushroom tasks parametrized by x τ where τ = 1, 2, . . . . Each parameter vector x τ contains C = 22 scalar parameters x 1 τ , . . . , x C τ to generate context (the mushroom attributes), and a single scalar parameter x C+1 τ to generate the subtask dynamic (the outcome of eating the mushroom). Denoting n = C+1, we have x τ = (x 1 τ , x 2 τ , . . . , x n τ ). The MDP dynamics P can be described as follows. Let S be the set of states, each of the form s = (τ, the rows represent the sequence of mushrooms, with the value of different attributes being displayed on each column. The agent may eat the mushroom to obtain a reward/cost (green/red circle) or choose to ignore it (black circle). (b) Example of a sample sequence of tasks from Section 2.2 with C= 3, A = 3. The left columns indicate the context variables (each color represent a possible value), and the right columns indicate the rewards that have been observed in each task (black when arm has not been pulled). On the left, the true clustering of the tasks (shared mixture component) is displayed. The dictionary of context variables is composed of D = 5 different colors in this case. ration objectives based on regret that are dominated by the long-term behavior of the agent.
More formally, the mushroom MDP consists of a sequence of mushroom tasks parametrized by x τ where τ = 1, 2, . . . . Each parameter vector x τ contains C = 22 scalar parameters x 1 τ , . . . , x C τ to generate context (the mushroom attributes), and a single scalar parameter x C+1 τ to generate the subtask dynamic (the outcome of eating the mushroom). Denoting n = C+1, we have x τ = (x 1 τ , x 2 τ , . . . , x n τ ). The MDP dynamics P can be described as follows. Let S be the set of states, each of the form s = (τ, (meaning unobserved) if the mushroom was not eaten in task τ and o τ = x C+1 τ otherwise. Choosing the exit action a exit increments the first state component and updates the context and observation components. Choosing the eat action a eat updates o τ = x C+1 τ and delivers a reward/cost.

A simple statistical model
The key aspect of the mushroom task is the joint statistics over the characteristics and danger of the mushrooms. The truth of the matter for the UCI data is actually unclear; it is therefore a stringent test of a planning algorithm whether it is possible to perform at all well based on what can only be a vague, and likely in-accurate model. To do its best, the agent assumes a general non-parametric model that allows for substantial underlying complexity in the true model, but adapts its ongoing characterization as a function of the evidence in the data that has so far been observed (Orbanz and Teh 2010). We employ one particularly popular non-parametric model called the Chinese Restaurant Process (Teh 2010) or Dirichlet Process mixture, which postulates that the mushrooms come in a possibly infinite number of mixture components.
The generative model of the mushroom statistics is formally described as follows: . . , n}, ∀τ ∈ Z + , where α is the concentration parameter of the CRP, the z random variables are the cluster assignments. The base measure of this Dirichlet process is assumed to be a symmetric Dirichlet prior with hyperparameter β = 1 (D i is the dimension of θ i , the number of possible observations for x i ), which together with the conjugate observation model, allows for relatively straightforward inference schemes (see Section S3 for details). The collection {θ i k |i ∈ {1, . . . , n}} of vectors contains the parameters corresponding to each mixture component k, the task parameters x τ for a particular τ are drawn by first choosing a mixture component z τ according to the CRP and then using the corresponding θ zτ parameters to sample each component of x τ . The infinitestate, infinite-horizon MDP is derived from this generative process by sampling an infinite sequence of tasks (τ → ∞) and patching them together.
The data at time D t consist of all mushroom attributes and labels observed (the sufficient statistics of the history of transitions), including the current mushroom subtask (and any initial 'free' examples). The posterior distribution over the dynamics P (P | D t ) is then obtained straightforwardly from the posterior over all past and future x τ (denoted x 1:∞ ), P (x 1:∞ | D t ), since P is uniquely characterized by x 1:∞ .
For the mushroom data, we set D i = 12 for each context dimension i -the maximum number of values for any of the 22 attribute dimensions in the data. This implies 2 · 12 22 ≥ 10 24 possible configurations of mushrooms assumed by the model. Since α is not known, we set a generic hyperprior on α ∼ Gamma(.5, .5).
Results in the mushroom task We stress that the mushroom data were not really generated by the process assumed in the previous section -this is what makes the task somewhat more realistic. Indeed, when the agent lacks prior data, maximizing the return is highly challenging. Randomly eating mushrooms to sample the dataset is a particularly bad strategy because of the cost asymmetry between edible and poisonous mushrooms. A natural point of comparison is the policy of ignoring all mushrooms, which leads to a neutral return of 0.
We ran the Bayes-adaptive agent (BAMCP) and TS using this statistical model on the mushroom task. Since the con-centration parameter is unknown, it is inferred from data, both influencing, and being influenced by, the exploration. Results are reported in Figure 3a for three different numbers of 'free' examples. A surprising result is that the Bayesadaptive agent manages to obtain a positive return when starting with no data, despite the mismatch between true data and generative model. This demonstrates that abstract prior information about structure can guide exploration successfully. Given exactly the same statistical model, TS fails to match this performance; we speculate that this is due to overoptimism, and investigate this further in Section 2.2 and the Supp. material (Fig. S3). When initial data (incl. labels) is provided for free to reduce the prior uncertainty, TS can improve its performance by a large margin but its return remains inferior to a Bayes-adaptive agent in the same conditions. 2 For the purposes of comparison, we also considered a simpler discriminative statistical model, namely Bayesian Logistic Regression, which (Li et al. 2012) suggested for use on contextual bandits. Figure 3 shows the results of applying TS and α−UCB (Li et al. 2012) in this context. TS does worse with the logistic regression model than with the CRPbased model; this demonstrates the added benefits of a prior that captures many aspects of the data with only a few datapoints. The α−UCB algorithm, despite good performance in the long-run on large datasets, is too optimistic to perform well with discounted objectives.

Non-Parametric Contextual Bandit Sequence model
The mushroom task can be seen as a sequence of subtasks that share structure, but whose order the agent cannot control. Other such domains are adaptive medical treatments where each patient can be understood as the subtask, handling customer interactions, or making decisions to drill for oil at different geological locations. In this section, we consider a generalized version of domains with this characteristic form of shared structure. Further, by addressing environments that were actually drawn from the model, we study planning in the absence of model mis-match.
The key generalization is to allow multiple arms in each subtask (rather than a single eat/exit decision). Using the same notation as Section 2.1, each parameter vector x τ now contains C scalar parameters x 1 τ , . . . , x C τ to generate context, and Y scalar parameters x C+1 τ , . . . , x C+Y τ to generate the actual task dynamics (i.e., denoting n = C + Y , we have x τ = (x 1 τ , x 2 τ , . . . , x n τ )). The generative model is identical otherwise, but now the choices of the agent in any particular task τ are to either: 1) leave the subtask for the next; or 2) pull any of the Y arms that has not been previously pulled. The MDP states are now of the form including an hypothetical agent trajectory. The exact setting for the experiments is as portrayed in Figure 2b: with C = 3 context cues, A = 3 arms in each task, and D = 5 possible values of x (i.e., the dimension D i = 5 for each θ). The function f (that maps values of x a to rewards) is 1-1 with the domain: {5, 2, 0, −1, −10}. We drew MDPs with different values of the concentration parameter α ∈ {0.1, 0.5, 1, 2, 5, 10}. The agent was assumed to know the generative structure of the MDP; but we considered both cases when it knew the true value of α or just had a generic hyperprior on α ∼ Gamma(.5, .5), and had to learn. This can be seen as a contextual bandit task (Langford and Zhang 2007) with shared structure modeled by a CRP. The difference from the usual definition of contextual bandit is that here, one of the arms has a known reward of 0 (the exit action) and that we give the option of playing multiple arms for the same context (subtask). In addition, unlike our algorithm, existing work on contextual bandit rarely exploits the unsupervised learning that the context affords even when no label is obtained. Many extensions are possible, including more complex intra-task dynamics (we explore this avenue in the supplementary, Section S4) and more general forms of shared structure; however we focus here on planning rather than modeling.
Results on synthetic data We investigate the behaviour and performance of Bayesian agents acting in tasks sampled from the non-parametric model above. The reward mapping implies that E[f (x a )] = −0.8 < 0 for all arms a and for all τ , since all values of x a are equally likely a priori. Thus, again, the strategy π exit of always exiting subtasks (without pulling any arms) is a fair comparison, with value 0 -a myopic planner based on the posterior mean only should never explore an arm, gaining this value of 0. Any useful adaptive strategy should be able to obtain a mean return of at least 0.
We concentrate on two metrics computed during the first 120 steps of the agent in the environment: the discounted sum of rewards (the formal target for optimization; Figure 4a), and the number of times the agent decides to skip a subtask before trying any of its arms (Figure 4b). The second metric relates to the safe exploration aspect of this task; sometimes optimism is unwarranted because it is more likely to lead to negative outcomes, even when taking into account the long-term consequences of the potential information gain.  We ran BAMCP and TS on the task. Figure 4 shows the performance as a function of α, when this concentration parameter is known. When the concentration parameter α is small, there will only be a few different mixture components, making for an easy case with little uncertainty about the identity of the mixture components after a few observations, and therefore little uncertainty about the outcome of an arm pull. In the limit of α → 0, only one cluster will exist and the domain essentially degenerates to a form of multinomial multiarmed bandit problem. As α grows, the identity of a given task's cluster becomes more uncertain and aliasing grows, so safe exploration becomes more challenging. Learning is slower in that regime too, simply because there are more parameter values to acquire. As α → ∞, every cluster will be different; this would prevent any kind of generalization and the Bayes-optimal policy will be to skip every subtask τ (since the a priori expected values of the arms in any given subtask is negative). Figure 4 shows that BAMCP adapts its explorationexploitation strategy according to the structure in the environment; small values of α justify the risk of exploring and incurring costs but this optimism progressively disappears as α gets larger. This translates into positive return when generalization is feasible, despite the marginal negative expected cost for each arm, and a return close to 0 when costs cannot be avoided. On the other hand, TS suffers from overoptimism across the board, leading to poor discounted returns, especially when the number of mixture components is large. Intuition for TS's poor performance comes from considering an extreme case in which all or most subtasks are sampled from a different cluster. Here, past experience provides little information about the value of the arms for the current cluster; thus, discovering these values (which, on average, is expensive) is not likely to help in the future. However, TS samples a single configuration of the arm, mostly informed by the prior in this situation, which likely results in at least one of the arms as having a positive outcome (for the prior, we repeat 3 times a draw having 2 5 probability of success, so p = 0.784). TS then, incorrectly, picks this putatively positive arm rather than exiting. Other myopic sample-based exploration strategies, such as Bayesian DP (Strens 2000) or BOSS (Asmuth et al. 2009), would suffer from similar forms of unwarranted optimism -since they also rely on sampling one or more posterior samples according to which they act greedily (see . A yet more challenging scenario arises when α is not known to the agent. A Bayesian agent starts with a uninformative (hyper-)prior on α in order to infer the value from data, it also takes into account during planning how its belief about this hyperparameter changes over time. In Figure 5, we observe that the Bayes-adaptive agent is more conservative and explores more safely when α is unknown. As expected, this results in lower returns (compared to when α is known). However, robustness to increased uncertainty is shown by the modest difference.
In the suppl. material (Fig. S4), we also show that BAMCP is sensitive to the discount factor, highlighting the dependence of the exploration-exploitation strategy to the horizon.

Related Work
Many researchers have considered powerful statistical models in the context of sequential decision-making (Wingate et al. 2011;Lazaric and Ghavamzadeh 2010), including in exploration-exploitation settings (Doshi-Velez et al. 2010;Asmuth et al. 2009). Non-parametric models have been considered in the context of control before (Doshi-Velez 2009;Asmuth et al. 2009) but with an emphasis on modeling the data rather than planning. In (Ross and Pineau 2008), the authors consider factored MDPs whose transitions are modeled using Bayesian Networks. They demonstrate the advan- tages of having an appropriate prior to capture the existing structure in the true dynamics, at least in a case in which the problems of safe exploration do not arise. For planning, they propose an online Monte-Carlo algorithm with an approximate sampling scheme, however the forward-search is conducted with a depth of 2 and a small branching factor, presumably limiting the benefits of Bayes-adaptivity.
(Moldovan and Abbeel 2012) consider a particular form of safe exploration to deal with non-ergodic MDPs, but they do not address discounted objectives or structured models. (Guez, Silver, and Dayan 2012) consider an infinite MDP, combining Bayes-adaptive planning with approximate inference over possible MDPs. However the class of models is quite specific to the particular domain they consider. In (Doshi-Velez 2009), an hierarchical Dirichlet Process is used to allow for an unbounded number of states in a POMDP and infer the size of the state space from data, this is referred as the iPOMDP model. This model is used in a online forward-search planning scheme, albeit of rather limited depth and tested on modestly-sized problems.
In (Deisenroth and Rasmussen 2011), Gaussian Processes (GPs) are employed to infer models of the dynamics from limited data, with excellent empirical performance. However, the uncertainty that the GP captures was not explicitly used for exploration-exploitation-sensitive planning. This is addressed in (Jung and Stone 2010), but with heuristic planning based on uncertainty reduction. More generally, our task is reminiscent of the case of active classification (Balcan, Beygelzimer, and Langford 2009). But while active learning ultimately aims to find an accurate classifier on a labeling budget, we are concerned with a completely different metric, namely discounted re-turn. In particular, a perfectly fine solution in our setting might be to avoid labeling a large part of the input space.

Discussion
Model-based Bayesian RL has often been viewed as attractive yet hopeless, particularly in high-dimensional and noisy domains. It had previously been shown that BAMCP, an efficient combination of extensions to Monte-Carlo tree search for Bayes-adaptive planning, was computationally viable, and yet very powerful. We showed that alternative, overoptimistic, myopic planning methods such as Thompson Sampling can run into severe problems that BAMCP avoids through explicit lookahead computations.
In an attempt to scale Bayes-adaptive planning to real domains, we proposed a contextual-bandit benchmark domain derived from the UCI mushroom dataset and an associated Bayesian non-parametric model for it. In this challenging exploration-exploitation domain, we demonstrated the feasibility and advantages of using a Bayes-Adaptive, or fully Bayesian, agent.
There are various ways to improve planning. Along with generic ideas such as adaptive adjustments of the roll-out policy which exerts a strong influence over the performance of BAMCP, it would be interesting to think about more radical departures, such as function approximation within the search tree based on histories and possible future histories.
A remaining open problem is to understand which classes of domains will truly benefit from the computations of Bayes-Adaptive planning (such as the ones explored in this paper), and which will be served just right with a simpler exploration-exploitation approach. Indeed, one can come up with examples where additional computation barely matters, in that the gains are vanishingly small (e.g., the Gittins indices for a multi-armed bandit problem with γ ≈ 1 are hard to obtain, but many myopic policies would do well in that scenario).
We have focused on planning; this means that the challenge now opened up by the success of BAMCP is modeling. The non-parametric model of shared structure amongst sub-tasks is readily generalizable to many domains, including ones in which the equivalent of the arms are themselves MDPs (see Section S4). A more radical extension would be to something closer to an Indian buffet process (Griffiths and Ghahramani 2011), in which the whole collection of subtasks also share a measure of structure; this should lead to solutions with collaboration among a set of expert solvers.
We describe the generic Bayesian formulation of optimal decision-making in an unknown Markov Decision Process (MDP), we refer the reader to (Martin 1967) and (Duff 2002) for additional details. An MDP is described as a 5-tuple M = S, A, P, R, γ , where S is the set of states, A is the set of actions, P : S×A×S → R is the state transition probability kernel, R : S × A → R is a bounded reward function, and γ is the discount factor (Szepesvári 2010). When all the components of the MDP tuple are known, standard MDP planning algorithms can be used to estimate the optimal value function and policy off-line. In general, the dynamics are unknown, and we assume that P is a latent variable distributed according to a distribution P (P). After observing a history of actions and states D t = s 1 a 1 s 2 a 2 . . . a t−1 s t from the MDP, the posterior belief on P is updated using Bayes' rule P (P| D t ) ∝ P (D t |P)P (P). The uncertainty about the dynamics of the model can be transformed into uncertainty about the current state inside an augmented state space S + = D, where D is the set of possible histories. The dynamics associated with this augmented state space are described by P + (D, a, D as ) = P P(s, a, s )P (P| D) dP, (1) where s is the suffix state of D. Together, the 5-tuple M + = S + , A, P + , R + , γ forms the Bayes-Adaptive MDP (BAMDP) for the MDP problem M . Since the dynamics of the BAMDP are known, it can in principle be solved to obtain the optimal value function associated with each action: where π is a policy over the augmented state space, from which the optimal action for each belief-state can be readily derived. Optimal actions in the BAMDP are executed greedily in the real MDP M and constitute the best course of action for a Bayesian agent with respect to its prior belief over P.
It is obvious that the expected performance of the BAMDP policy in the MDP M is bounded above by that of the optimal policy obtained with a fully-observable model, with equality occurring, for example, in the degenerate case in which the prior only has support on the true model.

S2 Examples -Cont.
Example 2 Consider a slight modification of Example 1 where the start state is the second state on the chain, so that with probability 1 2 the agent is only 1 step away from the reward source (See Figure S1). Clearly, the Bayes-optimal solution is to go left towards the nearest end first. The value of the policy at the start state is V * = 1 2 (γ + γ 2x+1 ). On the other hand, an algorithm that commits to a particular policy based on a posterior sample will aim for the left or right end of the chain equally often (since they are equally likely). The resulting value of such a strategy is V = 1 4 (γ + γ 2x−2 (1 + γ 3 ) + γ 4x−1 ), which gives V = 1 2 V * as x → ∞.
Example 3 Consider a single-step decision between two actions, a 1 and a 2 , with uncertainty in the payoff as follows.
With probability p (case 1), action a 1 leads to reward c 1 < 0 and a 2 leads to reward 0. With probability 1 − p (case 2), action a 1 leads to reward 1 and a 2 leads to negative reward 0. This is illustrated in Figure S2. Conventional TS in this example involves sampling one of the transitions according to the prior and taking the corresponding optimal action. This results in the following expected reward: p)). If c 1 is arbitrarily large and negative, V T S can be made arbitrarily bad. The Bayes-optimal policy integrates over the possible outcomes, therefore it performs at least as well as always choosing action a 2 with an expected reward of 0. This implies V * ≥ 0. The BOSS algorithm (Asmuth et al. 2009) constructs an optimistic MDP based on K posterior samples, so that the best action across all K samples is taken. In this example, it is enough for a single sample of case 2 to be present in these K samples to decide to take action a 1 (since r 2 > r 1 ), resulting in the following value for BOSS (denoting X to be the number of samples in the set of K samples of case 2): V ex3 BOSS = P (X ≥ 1)(p · c 1 + (1 − p)) = (1 − p K )(p · c 1 + (1 − p)) := z(K), which is a decreasing function of K (since c 1 < 0), showing the cost of this added optimism.
Of course, we usually think of BOSS as being applied to MDPs with sequential decisions, but one can readily transform Example 3 in an MDP by putting these 1-step decisions one after the other. We provide details of the construction in Example 4.

Example 4
Consider linking together different instances of Example 3. The agent starts in s 0 , and chooses between a 1 and a 2 with payoff described in Example 3. After executing either action, the agent makes a transition to state s 1 , where the process repeats until state s n , which itself transits back to s 0 . The outcome of a 1 and a 2 (determined by whether s i is of case 1 or 2) is independent across states.
BOSS has a parameter B that decides the number of steps between posterior resampling operations. However, B has no effect in this example for the first n steps. To compute the value of BOSS's policy from the initial belief state, leveraging the independence assumption, we can employ the value analysis of Example 3 for the first visit of every state. After every state gets visited once, the transition in some states (where action a 1 was chosen) will be uniquely known and BOSS can perfectly exploit the MDP in these states. For simplicity, we bound the value of the policy by assuming perfect knowledge of the MDP after the first n states: where z(K) = (1−p K )(p·c 1 +(1− p)) (from Example 3). We can choose n large to make the second term arbitrarily small, whereas the first term again depends on c 1 < 0, which we can make arbitrarily bad. Again, the value of the Bayes-optimal policy in this example can easily be lower-bounded as V * ≥ 0 since the Bayesoptimal policy can at least choose action a 2 at all times (no exploration).
We stress that PSRL and BOSS do enjoy strong theoretical guarantees for a different objective, namely expected regret; our goal of Bayes adaptivity is a more severe objective because discounting exerts pressure to perform well within a relatively shorter time horizon. Step Eating mushroom / Not eating mushroom ratio BAMCP Thompson Figure S3: Average rate of exploitation of mushrooms over time for BAMCP and TS for the domain described in Section 2.1, when starting with no labelled observations (0 free data condition). For a given step, the reported value is the fraction of time the agent chose to eat the current mushroom (when it had the option to), rather than to skip it.

S3 Inference details for the CRP-based
contextual-bandit sequence model • We use a Rao-Blackwellized Gibbs sampler, as described for example in (Sudderth 2006). We use the auxiliary variable trick from (Escobar and West 1995) for tractable inference of the concentration parameter α.
• A couple of Gibbs sweeps are performed between every BAMCP simulation but this thinning is not necessary for convergence. For Thompson Sampling, we burn in the chain with 500 Gibbs sweep before selecting the sample used for a particular step.  Figure S4: In the domain described in Section 2.2, the average number of ignored subtasks over 120 steps when using BAMCP with either γ = 0.95 or γ = 0.96 (Known α scenario). We see that a larger γ induces more exploration and risk-taking (fewer subtasks are ignored), showing the sensitivity of Bayes-Adaptive planning to the horizon.
• Given a setting of the cluster assignments and cluster parameters for the observed subtasks (obtained from the Gibbs sampler), the future subtasks x t:∞ are sampled by running the generative model forward conditioned on the inferred variables.
• In order to improve the planning speed, posterior samples can be memoized at the root of the search tree; the simulations pick from a pool of previously generated samples. The pool gets slowly regenerated.

S4 CRP mixture of MDPs
To illustrate that our methodology is not restricted to tasks resembling contextual bandits, we consider an extension of the problem in Section 2.2 in which each subtask τ is a random MDP of a particular class, with contextual information being informative about the class. This extension is loosely motivated by the following oil exploration problem. Possible drilling sites are considered in a sequence; each site comes with some particular known contextual information (e.g., geological features). One can ignore a drilling site (action a exit ), or (buy acreage and) run one of two types of terrain preparation strategies (actions a 0 and a 1 in state s 0 ). The outcomes of these two strategies is the potential for either natural gas (state s 1 ) or crude oil (state s 2 ). Finally, one has to make a final choice about how to exploit (e.g., the type of extraction process, either a 2 or a 3 ), which results in a stochastic payoff for this drilling site: either dry hole with many expenses (r = −1.5) or a profitable exploitation (r = 1).
We model this task as in Section 2.2 (each drilling site corresponds to a cluster/subtask τ ), except that additional x τ variables are necessary to establish the transitions between states, in addition to the variables already modeling context and rewards (for states s 1 and s 2 ). The payoff r 1,3 from executing action a 3 in s 1 in subtask τ is determined by the binary variable x 1,3 τ as r 1,3 = f (x 1,3 τ ) (f (0) = −1.5, f (1) = 1). In the generative model, x 1,3 τ (and other x i,j τ ) is determined like the other x τ variables in Section 2.2. The model is illustrated in Figure S5. The performance of BAMCP and TS on simulated data resemble return π * (s) 6: end procedure Figure S5: The extension of the CRP mixture model to MDPs, modelling an intermediate decision within each subtask before getting a payoff. that in the contextual bandits of Section 2.2. BAMCP adaptively ignores, explores, or exploits drilling sites depending on the environmental statistics. As in the other examples, with the same statistical model, TS acts too optimistically to do well in terms of discounted return and is less inclined to ignore subtasks. Figure S6-a shows that BAMCP is also more conservative when acting within each MDP when α is large, compared to TS. The dynamics of the cumulative return as a function of the steps is presented in Figure S6-b.