Monte Carlo Action Programming
Lenz Belzner


An EM Based Probabilistic Two-Dimensional CCA with Application to Face Recognition

    Mehran Safayani Seyed Hashem Ahmadi Homayun Afrabandpey Abdolreza Mirzaei 
    Received: date / Accepted: date
===================================================================================




This paper proposes Monte Carlo Action Programming, a programming language framework for autonomous systems that act in large probabilistic state spaces with high branching factors.
It comprises formal syntax and semantics of a nondeterministic action programming language. The language is interpreted stochastically via Monte Carlo Tree Search.
Effectiveness of the approach is shown empirically.






§ INTRODUCTION


We consider the problem of sequential decision making in highly complex and changing domains. These domains are characterized by large probabilistic state spaces and high branching factors. Additional challenges for system design are occurrence of unexpected events and/or changing goals at runtime.

A state of the art candidate for responding to this challenge is behavior synthesis with online planning <cit.>. Here, a planning agent evaluates possible behavioral choices w.r.t. current situation and background knowledge at runtime. At some point, it acts according to this evaluation and observes the actual outcome of the action. Planning continues, incorporating the observed result. Planning performance directly correlates with search space cardinality. 

This paper introduces Monte Carlo Action Programming (MCAP) to reduce search space cardinality through specification of heuristic knowledge in the form of procedural nondeterministic programs. MCAP is based on stochastic interpretation of nondeterministic action programs by Monte Carlo Tree Search (MCTS) <cit.>. Combining search space constraints and stochastic interpretation enables program evaluation in large probabilistic domains with high branching factors.









From the perspective of online planning, MCAP provides a formal non-deterministic action programming language that allows to specify plan sketches for autonomous systems. From the perspective of action programming, MCAP introduces stochastic interpretation with MCTS. This enables effective program interpretation in very large, complex domains.

We will discuss MCTS and action programming in Section <ref>. Section <ref> introduces MCAP. In Section <ref> we empirically compare MCTS and MCAP specifications for online planning. We conclude and sketch venues for further research in Section <ref>.



§ RELATED WORK



We briefly review Monte Carlo Tree Search in Section <ref> and action programming in Section <ref>.



 §.§ Monte Carlo Tree Search



Monte Carlo Tree Search (MCTS) is a framework for statistical search in very large state spaces with high branching factors based on a generative model of the domain (i.e. a simulation). It yields good performance even without heuristic assessment of intermediate states in the search space. The MCTS framework originated from research in computer Go <cit.>. The game Go exposes the mentioned characteristics. Also, not many good heuristics are known for Go. Nevertheless, specialized Go programs based on the MCTS algorithm are able to play on the niveau of a human professional player <cit.>. MCTS is also commonly used in autonomous planning <cit.> and has been applied successfully to a huge number of other search tasks <cit.>.




MCTS adds nodes to the tree iteratively. Nodes represent states and store metadata about search paths that lead through them. Gathered metadata comprises mean reward (i.e. node value) and the number of searches that passed through the node. It enables assessment of exploration vs. exploitation: Should search be directed to already explored, promising parts of the search space? Or should it gather information about previously unexplored areas?

Figure <ref> shows the basic principle of MCTS. Based on node information, MCTS selects an action w.r.t. a given tree policy. The successor state is determined by simulating action execution. Selection is repeated as long as simulation leads to a state that is represented by a node in the tree. Otherwise, a new node representing the simulated outcome state is added to the tree (expansion). Then, a default policy is executed (e.g. uniform random action execution). Gathered reward is stored in the new node (simulation or rollout). This gives a first estimation of the new node's value. Finally, the rollout's value is backpropagated through the tree and the corresponding node values are updated. MCTS repeats this procedure iteratively.
Algorithm <ref> shows the general MCTS approach in pseudocode. Here, v_0 is the root node of the search tree. v_l denotes the last node visited by the tree policy. Δ is the value of the rollout from v_l according to the default policy.


MCTS can be interrupted at any time and yields an estimation of quality for all actions in the root state. The best action (w.r.t. node information) is executed and its real outcome is observed. MCTS continues reusing the tree built so far. Eventually, nodes representing past states are pruned from the tree.



 §.§ Action Programming



Nondeterministic action programs define sketches for system behavior that are interpreted at runtime, leaving well-defined choices to be made by the system at runtime. Interpreting an action program typically provides a measure of quality for particular instantiations of theses sketches. Concrete traces are then executed w.r.t. to this quality metric.

Well-established action programming languages are Golog <cit.> and Flux <cit.>. Each is interpreted w.r.t. a particular formal specification of domain dynamics: The situation calculus and the fluent calculus are concerned with specification of action effects and domain dynamics in first order logic <cit.>. For both Golog and Flux, Prolog interpreters have been implemented.




The MCAP framework differs from these formalisms and their respective languages: (a) MCAP does not provide nor require a specific formal representation of domain dynamics. Rather, any form of domain simulation suffices. (b) MCAP does not explore the search space exhaustively. Rather, programs are interpreted stochastically by MCTS. The search space is explored iteratively. Program interpretation is directed to promising areas of the search space based on previous interpretations. Search can be interrupted any time yielding an action recommendation accounting for current situation and a given program. Recommendation quality depends on the number of simulations used for search <cit.>.



§ MONTE CARLO ACTION PROGRAMMING



This Section introduces Monte Carlo Action Programming (MCAP), a nondeterministic procedural programming framework for autonomous systems. 
The main idea of the MCAP framework is to allow to specify behavioral blueprints that leave choices to an agent. A MCAP is a nondeterministic program. MCAP programs are interpreted probabilistically by MCTS. MCAPs constrain the MCTS search space w.r.t. a procedural nondeterministic program. 





 §.§ Framework Parameters



The MCAP framework requires the following specification.


	
  * A generative domain model that captures the probability distribution of successor states w.r.t. current state and executed action (Equation <ref>). The model does not have to be explicit: The framework only requires a simulation that allows to query one particular successor state.
	
    simulate : P(  |  ×)

	
  * A reward function R that encodes the quality of a state w.r.t. system goals (Equation <ref>).
	
    ℛ   : →ℝ

	
  * A discount factor γ∈ [0;1] weights the impact of potential future decision on the current situation. A discount factor of zero means that only immediate consequences of action are considered. A discount factor of one means that all future consequences influence the current decision equally, regardless of their temporal distance.
	
  * A maximum search depth h_max∈ℕ.




 §.§ Syntax



Equation <ref> defines syntax of the MCAP language. ϵ is the empty program,  denotes specified action space,  is a sequential operator, + is nondeterministic choice, ∥ denotes interleaving concurrency. Q denotes the query space for conditional evaluation (see Equation <ref>). ? denotes querying the current execution context. ∘ denotes a conditional loop.









    := ϵ           ∥
          ?() {}   ?() {}
      ∘{}{}



Normal Form 
We define a normal form _norm for MCAPs. Each program in normal form is a choice of programs with an action prefix and any tail program.

    _norm := ∑( )


Equations <ref> to <ref> define a term reduction system that ensures transformation of programs to their normal form.


    ϵ p    = p
    
    p + p    = p 
    
    (p_1 + p_2)  p    = (p_1  p) + (p_2  p)
    
    p  (p_1 + p_2)    = (p  p_1) + (p  p_2)
    
    p_1 ∥ (p_2 + p_3)     = (p_1 ∥ p_2) + (p_1 ∥ p_3) 
    ( a_1  p_1 ) ∥( a_2  p_2 )     = 
    ( a_1  (p_1 ∥( a_2  p_2 ) ) )
    
        + 
    ( a_2  (( a_1  p_1 ) ∥ p_2) ) 
    
    a_1 ∥ (a_2  p)     = (a_1  a_2  p) + (a_2  (a_1 ∥ p)) 
    
    a_1 ∥ a_2     = (a_1  a_2) + (a_2  a_1)




 §.§ Semantics



This Section formalizes MCAP semantics in the context of MCTS interpretation.


Search Tree 
We introduce a formal representation of the search tree. Its purpose is to accumulate information about computation traces w.r.t. simulation and system action choices. Tree nodes represent states ∈ and actions ∈. State nodes _ and action nodes _ alternate (Equations <ref> and <ref>). Nodes contain aggregation of metadata 𝒟 that guides further search. Aggregated data are visitation count and node value (Equation <ref>).

    _   ⊆×𝒟× 2^_
    _   ⊆×𝒟× 2^_×
    𝒟   ⊆ℕ×ℝ



While it is possible to use a DAG instead of a tree <cit.>, we will concentrate on the tree setting in this paper for the sake of simplicity.


Framework Operations 
Equations <ref> to <ref> show the functional signatures of MCAP framework operations. We will define each one in the rest of this Section. 

    select   : _→_
    expand   : ×→_
    rollout   : ××ℕ→ℝ
    update   : _→_
    update   : _→_



Selection 
Equation <ref> shows UCB1 action selection. It is a popular instantiation of the MCTS tree policy based on regret minimization <cit.>. q(v_a) denotes the current value aggregated in the metadata of action node v_a. (v_s) and (v_a) denote the number of searches that visited the corresponding node stored in its metadata (see also Algorithm <ref>, lines 2 and 10). UCB1 favors actions that expose high value (first term of the sum), and adds a bias towards actions that have not been well explored (second term of the sum). The parameter c is a constant to control the tendency towards exploration.


    select(v_s)    = argmax_v_a ∈v⃗_⃗a⃗(v_s)( q(v_a) + c ·√(2 ln(v_s)(v_a)))



Queries 
Our framework requires specification of a query representation and a satisfaction function of queries and states to enable conditional computation. Queries Q are evaluated w.r.t. a given state ∈ and yield a set of substitutions for query variables (Equation <ref>). It returns the set of substitutions for variables in the query for which the query holds in the state. In case the query is ground and holds, the set containing the empty substitution {∅} is returned. If the query does not hold, it returns the empty set ∅. We write ⊢ in infix notation and s ⊬q ⇔ s ⊢ q = ∅.

    ⊢ : ×→ 2^Θ



Interpretation of MCAPs 
Expansion of the tree is constrained by a given MCAP through interpreting it w.r.t a given state. The potential program function constrains the search space w.r.t. given action program and current system state. It maps an MCAP and a given state to the set of normalized MCAPs that result from (a) nondeterministic choices and (b) interpretations of queries.

    pot : ×→ 2^_norm


Equations <ref> to <ref> define MCAP interpretation by the potential program function inductively on the structure of .


    pot(s, ϵ)    = ∅
    pot(s, a )    = { a ϵ}
    pot( s, p  p' )    = ⋃_p”∈pot(s, p)( p” p' )
    pot(s, ∑_i p_i )    = ⋃_i pot(s, p_i)
    pot(s, ?{ q }{ p })    = ⋃_θ∈ s ⊢ qpot(s, θ(p) )
    pot(s, ?{ q }{ p })    =
    pot(s, p)     s ⊬q
    ∅   
    pot(s, ∘{ q }{ p })    = pot(s, ?{ q }{ p }∘{ q }{ p })



Expansion 
Equation <ref> shows the MCAP expansion mechanism. s ∈ denotes the state for which a new node is added. p is the MCAP to be executed in state s. Potential programs pot(s,p) in normal form define the set of action node children for actions a that contain the corresponding tail programs p'. Thus, a MCAP effectively constrains the search space. d_0 ∈𝒟, d_0 = (0,0) defines initial node metadata.

    expand(s,p) = (s,d_0,v⃗_⃗a⃗)    
    where v⃗_⃗a⃗   = ⋃_(a,p') ∈pot(s,p) (a,d_0,∅,p')



Rollout 
After expansion a rollout is performed. A number of simulation steps is performed (i.e. until maximum search depth h_max is reached) and the reward for resulting states is aggregated. An MCAP p defines the rollout's default policy. Actions and corresponding tail programs are selected uniformly random from the set of potential programs in each state s encountered in the rollout.

    rollout(s, p, h) = 
       
    	R(s)     h = h_max
    
    	R(s) + γ·rollout(s', p', h + 1)    
       where  (a,p') ∼pot(s,p) ∧ s' ∼simulate(s' | s, a)



Value Update 
After a node is expanded its value is determined by a rollout. The newly created value is then incorporated to the search tree by value backpropagation along the search path. In general any kind of value update mechanism is feasible, e.g. a mean update as used by many MCTS variants. MCAP uses dynamic programming (i.e. a Bellman update) for updating node values <cit.>. An action's value is the weighted sum of its successor states' values (Equation <ref>). A state's value is the currently obtained reward and the value of the currently optimal action (Equation <ref>).

    update(v_a)    = ∑_v_s ∈v⃗_⃗s⃗(v_a)(v_s)(v_a) v(v_s)
    update(v_s)    = R(s(v_s)) + max_v_a ∈v⃗_⃗a⃗(v_s) q(v_a)



















Algorithm <ref> shows the interplay of selection, aggregation of metadata, simulation, expansion, rollout and value update for Monte Carlo Action Programming.



Algorithm <ref> shows the integration of MCAP with online planning. While the system is running, a given MCAP is repeatedly evaluated and executed until termination (lines 2 – 4).
Evaluation is performed by MCTS until a certain budget is reached (lines 6 – 8). The currently best action w.r.t. MCAP interpretation is determined (line 9). If there is no such action, the program terminated (line 10). Otherwise, the best action is executed and the outcome observed (lines 13 and 14). In case the new state is already represented in the search tree, the corresponding state node is used as new root for further search (lines 15 and 16). Otherwise, a new root node is created (line 18).





§ STATISTICAL MODEL CHECKING OF MCAPS


TODO: Remove this Section? Paper with Andrea.



Metasimulation allows to assess system performance if there is a difference of the simulation used for generating trajectories in MCTS and the simulation that runs online MCTS.






§ EXPERIMENTAL EVALUATION





 §.§ Example Domain



We introduce the rescue domain as illustrating example.

Robots can move around a connected graph of positions and lift or drop victims.
The number of victims a robot can carry is limited by its capacity.
A position may be on fire, in which case a robot cannot move there. 
At every time step the fire attribute of a position may change
 depending on how many of the position's neighbors are on fire.
A safe position never catches fire.
The class diagram of the rescue domain is shown in Figure <ref>.
A particular state of the domain is an instantiation of this class diagram.

Possible system actions are:


  * Move(R,P):
Robot R moves to target position P if it is connected to the robot's current position and is not on fire.


  * Extinguish(R,P):
Robot R extinguishes fire at a neighbor position P.


  * Lift(R,V):
Robot R lifts victim V (at same location) if it has capacity left.


  * Drop(R,V): Robot R drops lifted victim V at the current location.

  * Noop: Does nothing.






 §.§ Setup & Results


Effectiveness of the MCAP framework was evaluated empirically for the rescue domain. A simulation of the domain  was used as generative model. Reward R(s) was defined as the number of victims located at safe positions in state s. Also, each victim not burning provided a reward of 0.1. Maximum search depth was set to h_max = 40 and the discount factor was set to γ = 0.9.

Experiments were conducted with randomized initial states, each consisting of twenty positions with 30% connectivity. Three positions were safe, ten victims and ten fires were located randomly on unsafe positions. Robot capacity was set to two. This setup yields a state space containing more than 10^19 possible states.

Fires ignited or ceased probabilistically at unsafe positions. Actions succeeded or failed probabilistically (p = 0.05). This yields a branching factor of 2 · 2^17 for each action.

In the experiments using plain MCTS all actions ∈ were evaluated at each step. Algorithm <ref> shows pseudocode for the program used to determine the action to evaluate in the experiments with MCAP. Both MCTS and MCAP used 1000 playouts at each step for action evaluation.


System performance was measured with the statistical model checker Multivesta <cit.>. Two metrics of system behavior with and without MCAP search space constraints were assessed: Ratios of safe victims and burning victims.

Figure <ref> compares the average results for behavior synthesis with plain MCTS and with MCAP within a 0.1 confidence interval. The effect of MCAP search space reduction on system performance can clearly be seen. The configuration making use of online MCAP interpretation achieves larger ratios of safe victims and manages the reduction of burning victim ratios better than the configuration not making use of MCAP. With plain MCTS, search is distracted by low reward regions due to avoiding burning victims. MCAP search identifies high reward regions where victims are saved within the given budget. 










A similar experiment with unexpected events illustrates robustness of the approach. Here, every twenty steps all currently carried victims fell to the ground (i.e. were located at their carrier's position). Also, fires ignited such that overall at least ten fires were burning immediately after these events.

Note that the simulation of the domain used for plain MCTS and MCAP did not simulate these events. The planning system managed to recover from the unexpected situations autonomously (Figure <ref>). As for the basic experiment, the configuration with MCAP performed significantly better that the configuration using plain MCTS.










In a third experiment the reward function was changed unexpectedly for the system. Before step 25, a reward is provided exclusively for avoiding burning victims. From step 25 on the reward function from the previous experiments was used, providing reward for safe victims. The planner did not simulate the change of reward when evaluating action traces. MCAP outperformed plain MCTS by reacting more effectively to the change of reward function. Figure <ref> shows the results of this experiment.




§ CONCLUSION



This paper proposed Monte Carlo Action Programming, a programming language framework for autonomous systems that act in large probabilistic state spaces.
It comprises formal syntax and semantics of a nondeterministic action programming language. The language is interpreted stochastically via Monte Carlo Tree Search.

The effectiveness of search space constraint specification in the MCAP framework was shown empirically. Online interpretation of MCAP provides system performance and robustness in the face of unexpected events.

A possible venue for further research is the extension of MCAP to domains with continuous time and hybrid systems. Here, discrete programs are interpreted w.r.t. continuously evolving domain values <cit.>.



It would also be interesting to evaluate to what extend manual specification techniques as MCAP could be combined with online representation learning (e.g. statistical relational learning <cit.> and deep learning <cit.>): How to constrain system behavior if perceptual abstraction is unknown at design time or changes at runtime?



splncs







§ EXAMPLE DOMAIN STATE SPACE CARDINALITY



Given a single robot, the state space cardinality takes into account the following possible configurations.


  * The possible distributions of victims carried by a robot and the others located at arbitrary positions (first term of the product in Equation <ref>).

  * The possible positions of the robot (second term).

  * Each position is either on fire or not (third term).


    ∑_i = 0^capacity[ [ victims;       i ]·[     positions; (victims - i) ]] ·positions· 2^(positions - safe)



