{'fraction_non_alphanumeric': 0.03414047225146639, 'fraction_numerical': 0.006767935027823733, 'mean_word_length': 4.550500834724541, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Stacked Thompson Bandits

We introduce Stacked Thompson Bandits (STB) for efficiently generating plans that are likely to satisfy a given bounded temporal logic requirement. STB uses a simulation for evaluation of plans, and takes a Bayesian approach to using the resulting information to guide its search. In particular, we show that stacking multiarmed bandits and using Thompson sampling to guide the action selection process for each bandit enables STB to generate plans that satisfy requirements with a high probability while only searching a fraction of the search space.


I. INTRODUCTION
In many cases, system requirements can be formalized in a bounded temporal logic [1], [2]. For example, consider a mobile robot with planning capabilities in a area with obstacles. Here, a requirement could be that when executing a given sequential plan of ten actions, there should occur less than e.g. three collisions with obstacles. One could write this requirement as a temporal logic formula similar to the following: In this paper, we propose Stacked Thompson Bandits (STB) as an algorithm for constructing plans that are likely to satisfy a given requirement. STB works by simulation: It repeatedly samples a plan from its current policy, simulates the result of this plan w.r.t. a given requirement, and updates its policy according to the result in order to increase the quality of further sampled plans. As we will see, STB leverages Bayesian statistics to guide the exploration-exploitation tradeoff when searching the space of possible plans for feasible solutions.
STB is an open loop planner [3], [4]: It does only search the space of plans. That is, action selection is not conditioned w.r.t. intermediate states, but only w.r.t. previously selected actions. STB does only account for intermediate states when evaluating requirement satisfaction of a given plan.
The key idea of STB is to model the plan selection policy by an open loop sequence of multiarmed bandits. Each of the bandits represents an action choice for plan construction at a certain point in time. Exploration of the search space and exploitation of already gathered results are balanced with Thompson sampling [5], [6]. Information gathered from simulating sampled plans is used to increase the likelihood that plans constructed by STB satisfy a given requirement.
The remainder of the paper is structured as follows: Section II recaps open loop planning, multiarmed bandits and Thompson sampling. Section III introduces Stacked Thompson Bandits. In Section IV we discuss our empirical findings. Section V discusses related work. We conclude in Section VI and give pointers to potential future work.

II. PRELIMINARIES
In this Section, we recap open loop planning, multiarmed bandits and Thompson sampling.

A. Open Loop Planning
In our setting, open loop planning ( [3], [4]) is an approach to find plans that result in satisfaction of a given goal without storing information about the intermediate states that are encountered while executing the plan. I.e. given a set of actions A, we are only interested in finding a plan p ∈ A * , and we are only keeping information about the action sequences in order to guide the planning process. This is in contrast to closed loop planning, such as e.g. Monte Carlo Tree Search [7], where action selection is typically conditioned by the history of previously encountered states and executed actions.

B. Multiarmed Bandits
Multiarmed bandits (MAB) are a core framework for decision making. A bandit consists of a number of arms, each representing an agent's choice. In our setting, each arm represents an action a ∈ A. Each arms provides a particular payoff, and the agent's goal is to identify the most preferable arm. It can explore the bandit by pulling one arm at a time, and observe the corresponding payoff.
An MAB can be interpreted as a simple Markov decision process with a single state. In their basic formulation, MABs already provide a clear framework for studying the exploration-exploitation tradeoff inherent to decision making under uncertainty: Should the agent select the arm that previously showed to be most promising? Or should it go on exploring other options? For a recent survey of MAB and its variants, see [8].

C. Thompson Sampling
Thompson sampling (TS) is a Bayesian algorithm for solving an MAB. It was proposed decades ago [5], but only recently its astonishing effectiveness and generality have been identified [9], [10], [11].
In the case of Bernoulli rewards (as in the case of STB), the parameter of each arm to be estimated is a probability p ∈ [0; 1]. TS infers a posterior distribution over p based on the observed arm payoffs and a prior assumption about the distribution of p. In general, the posterior is proportional to the likelihood of observed data D (i.e. an arm's observed payoffs), multiplied by the prior distribution P (θ) over the parameters of interest, θ = p in our case (Equation 1).
We can model the uncertainty about p by a Beta distribution, the conjugate prior of the Bernoulli distribution. This approach ensures that the posterior is of the same form as the prior distribution, and thus enables efficient sequential updating of the distribution. The Beta distribution is parametrized by two parameters a, b ∈ R + . In our case, a and b are given by the successes and failures of the arm pulls. Given s successes, f failures, and assuming an uninformative prior over p, the posterior (for θ = p) is determined by Equation 2.
TS maintains such a distribution P (θ) for each arm. The algorithm then samples a potential value for each arm from these distributions. It then plays the arm from whose distribution the maximum value has been sampled, observes the payoff, and uses this observation to update the corresponding distribution. Repeating this process results in almost sure identification of the arm with the highest payoff. TS is schematically shown in Algorithm 1. ∀a ∈ A :p a ∼ P a (p) 3: play arg max apa and observe result 4: update P a (p) w.r.t. result

III. STACKED THOMPSON BANDITS
We now present Stacked Thompson Bandits (STB). STB works by stacking a number of MAB, treating them as a sequential decision problem. In order to construct a plan, STB sequentially selects an action from each MAB using Thompson sampling. The resulting plan checked for requirement satisfaction using a simulation M . Given a set of states S, a set of actions A and the set of bounded temporal formulae Φ, M is a conditional probability distribution as follows.
I.e. running a simulation for a given initial state s ∈ S, a given plan p ∈ A * and a given requirement φ ∈ Φ can be interpreted as a Bernoulli experiment. STB is shown in Algorithm 2. It takes the following input: First, STB initializes the parameters of each stacked bandit. In particular, for each step i up to the horizon of the requirement φ and each action a ∈ A, it maintains a count of successes s a,i (i.e. satisfactions) and failures f a,i (i.e. violations) (lines 2 -4).
Then, STB repeats the following steps until interruption (e.g. due to some budget, or because an event occurred).
• An estimated satisfaction probability is sampled from the stacked bandit, i.e. from each beta distribution for each step i and for each action a (line 8). sat ∼ M (s, p, φ)

12:
for a i ∈ p do 13: if sat then 14: s a,i ← s a,i + 1 15: else 16: f a,i ← f a,i + 1 The algorithm terminates on some external interruption signal that is to be specified by the user. A possible decision rule on which plan to execute would be to select the action with maximum distribution mode (the value with most probability mass) for each MAB in the stack. The mode of a beta distribution with parameters a, b is given by: Mode plan selection for STB is therefore performed as shown in Algorithm 3.

IV. EXPERIMENTAL RESULTS
We implemented STB and observed whether it is able to generate plans with increasing probability of satisfaction requirement when performing more search iterations.

A. Setup
The state s is constituted by a 10 x 10 grid world, with the agent at position (0, 0). Obstacles are randomly positioned, at an obstacle to free position ratio of 0.2. Actions are movements in four directions up, down, left, right with obvious semantics.
The agent has a Bernoulli action failure probability p fail uniformly sampled from [0; 1]. Action failure results in the inverse movement (e.g. failing up yields down). This constitutes domain noise in the simulation M available to the agent.
The task of STB is to generate a plan of length 10 that yields less than three collisions with obstacles when executed: This setup yields a search space cardinality 4 10 = 1048576. However, note that due to probabilistic domain dynamics (i.e. the branching due to potential action failures) a plan has to be evaluated many times to obtain an adequate estimate of its satisfaction probability, yielding a very hard search problem. We approximated the ground truth satisfaction probability of a plan by taking the maximum likelihood estimate of satisfaction probability based on 1000 simulation runs.
Our implementation of the setup and STB is available at https://github.com/jazzbob/stb.

B. Results
In our experimental runs, we observed that STB is able to generate plans with increasing probability of satisfying the given requirement. In particular, STB was able to find potentially close to optimal solutions searching only a fraction of the search space. Figure 1 shows an exemplary run of STB.
As a sanity check, we also observed the average mode value as well as the coefficient of variation (CV) of sampled plan arm distributions and mode (i.e. best) plan arm distributions respectively. While the mode value gives a rough estimate about value of an arm (i.e. an action), the CV is defined as the ratio of standard deviation to mean σ µ of a distribution. CV is suitable to measure the accuracy of a distribution when its mean value changes [12], as is the case in STB. We expect the average mode value to increase in the long run for both sampled and best plans. We also expect the CV of sampled and best plans to decrease in the long run. We could empirically establish both expected results (cf. Figure 2).
However, we also observed STB to get stuck in local optima (cf. Figure 3). This is a property of many stochastic search algorithms. One could potentially reduce the risk of getting stuck by using an ensemble of STB planners in order to reduce the probability of such premature convergence.  The vertical axis shows the average value of sampled (orange) and current best (blue) arm distributions' modes and CVs. As expected, average modes increase in the long run, while average CVs decrease. The strong disturbances in the beginning, in particular w.r.t. to the average modes, is due to the lack of valid information for STB to build its action value (i.e. satisfaction probability) estimates.

V. RELATED WORK
Our work on STB is strongly influenced by existing open loop planners. In particular, Cross Entropy Open Loop Planning is an approach for planning in large-scale continuous MDPs [4]. It is however not applicable to discrete domains as STB. Recently, cross entropy planning has been used for searching sequences that satisfy a given temporal logic formula [13] in a continuous motion planning setting.
STB is subtly related to statistical model checking (SMC) [14], [15], and Bayesian statistical model checking in particular [16], [17], [18]. Here, the setting is to guarantee a minimal required satisfaction probability for a given, fixed sequence of actions. SMC approaches are able to provide such a result, potentially with a quantifiable confidence. STB is not able to provide a quantification of satisfaction probability, as is samples every plan only once. Also, the distributions maintained in the stacked bandits to not provide an accurate absolute quantification due to the sampling nature of search and the corresponding concept drift. On the other hand, STB is able to generate plans with high satisfaction probability, whereas SMC only can determine this probability. In practice, a combination of both approaches is possible and seems useful.

VI. CONCLUSION
We have presented Stacked Thompson Bandits (STB), an open loop planning algorithm for generating action sequences that satisfy a given bounded temporal logic requirement with high probability. STB works by maintaining a stack of multiarmed bandits via Thompson sampling. We have preliminarily and empirically evaluated the effectiveness of STB on a toy example.
There are various directions for future work. As mentioned, it would be interesting to see if an ensemble approach with STB could reduce the probability of getting stuck in local minima. Another interesting venue would be to combine temporal action abstraction with STB. See [19], [12] for previous work of one of the authors on temporal abstraction in open loop planning. Also, guiding the sampling process in a QoS-aware manner based on required confidences could prove worthwhile. See e.g. [20] for previous work of the authors on QoS-aware sampling in multiarmed bandits. It would also be interesting to explore STB under model uncertainty, e.g. when the simulation model is learned from incomplete information.