Cs 234 lecture 14 monte carlo tree search

Model Free and Model Based RL

Monte Carlo Tree Search Is Model-Based Reinforcement Learning. Deep RL has not been so successful in Model-Based RL so far, so Model-free approaches have dominated so far.

Model-Free RL:

Model-Based RL

Def: MDP Model

A model M is a representation of an MDP <S,A,P,R>, parameterized by $\eta$. Assume the state space $S$ and action space $A$ is fixed and known. A model $M = <P_\eta, R_\eta>$ represents state transitions $P_\eta \approx P$ and $R_\eta \approx R$ s.t. We typically assume conditional independence between state transitions and rewards

Model Learning

Goal: Estimate model $M_\eta$ from experience ${S_1, A_1, R_2, …, S_T}$. This is a supervised learning problem Learning $s,a \rightarrow r$ is a regression problem. Learning $s,a, \rightarrow s’$ is a density estimation problem. Pick loss function e.g. MSE, KL divergence, and find parameters $\eta$ that minimize empirical loss.

Possible Models: Table Lookup Model, Linear Gaussian Networks, Bayesian DNNs (very exciting - but have been hard to train so far). (Appendix 1. for Table Lookup Model)

Sample-Based Plannig

Use the model only to generate samples Then apply model-free RL to samples, eg MC Control, SARSA, Q-learning.

Note: You built the model with data. We do not reuse that data to generate our actual training examples, we only use data generated by the current version of our model! Why: Sample-based planning methods are often more data efficient.

Search Algorithms

Screenshot 2020-04-12 at 5.47.46 PM.png

In order to figure out the value of each state in the tree, take a max over actions and take an expectation over states. There might be too many states and actions so often we just use simulation based search:

Screenshot 2020-04-12 at 5.50.55 PM.png

Starting from a current state, perform a lot of simulations about the rewards from the current state $s_t$, then take one action (depth 1) from that state. Works but slow since we are only taking one step at a time.

Given a model $M_v$ and a simulation policy $\pi$, and that we are currently at a real state $s_t$. For each possible action $a \in A$:

Select current (real) action with maximal value $a_t = \arg \max _{a \in A} Q(s_t,a)$. This is essentially doing 1 step of policy improvement according to the simulation policy.

Expectimax Tree

Full depth simulation, and then take the optimal path found my simulation. Tree gets very big, grows exponentially with the horizon.

We can do better than 1 step of policy improvement. If we have the MDP model $M_v$, we can compute the optimal q(s,a) values for the current state by constructing an expectimax tree. Expectatons over states, max over actions. But problem: tree gets very big, grows exponentially with the horizon $O((|S||A|^T))$

Note: In 2 player adversarial settings, use minimax instead of expectimax tree.

Monte Carlo Tree Search (MCTS)

This is what the robot does in its head to simulate and plan for the next action:

Medium depth simulation, trying to compute the value at a higher depth than 1 but in a computationally tractable way. Given Model $M_v$, build a search tree rooted at the current state $s_t$. Samples actions and next states. Iteratively constriuct and update tree by performing K simulation episodes starting from the root state. After search is finished, select current (real) action with maximum value in each search tree: $a_t = \arg \max_{a \in A}Q(s_t,a)$

Sample until termination or a horizon H, and then go back to start state and start another trajectory. Then take the expectimax reward over the partial tree computed so far to propagate the reward back to the root state. “Slowly fill in the expectimax tree but only have a partial tree because Expextimax tree might be intractible” (Appendix 2)

Simulating an episode involves two phases (in-tree, out-of-tree)

To evaluate the value of a tree node $i$ at state action pair $(s,a)$, average over all rewards recieved from that node onwards across simulated episodes in which this tree node was reached.

Under mild conditions, this converges to the optimal search tree $Q(S,A) \rightarrow q^*(S,A)$. Note that we’re no longer doing expectation or max anymore, but this is okay because we are going to sample actions in a way that over time we will sample actions that look better much more.

Advantages of MC Tree Search

This is a way to implement the tree policy above in MCTS. Idea: borrow idea from banit literature and treat each node where we can selection each action as a multi-armed bandit problem. Treat every distinct node in the tree (could be very many) as a bandits problem, and uses optimism.

For each node $s_i$ and action from that state $a_j$, we compute a empirical Q function $\hat Q(s_i,a_j)$ based on adding the future rewards we obtained every time we were in that node during simulation previously, and also add a optimistic confidence bound adjustment (usually in the form of $\sqrt{\frac{\cdot}{n(s_1,a,1)}}$, $\sqrt{\frac{\ln (n(s))}{n(s_1,a,1)}}$ is a common pick) such that our final $Q$ functions we compare to pick the next action is $\hat Q(s_i,a_j) + \sqrt{\frac{\cdot}{n(s_1,a,1)}}$.

In other words, we maintain an upper confidence bound for every action and every state in our tree. Formally

(Appendix 3)

Other parts of Alpha Go

Action heuristics (what order to try actions in was pretty important) Self-play - use the current agent as the opponent as the minimizer of the minimax.

Appendix 1: Table Lookup Model

LIterally the current reward and transition model is just the proportions of the counts seen so far.

Screenshot 2020-04-12 at 5.24.36 PM.png

Screenshot 2020-04-12 at 5.26.01 PM.png

MC methods will converge to the min MSE model, and does not make a Markovian assumption, so it will converge in all cases including the case above. But in general it will will not converge to the same policy as if we took the MLE model and did planning.

Screenshot 2020-04-12 at 5.37.46 PM.png

Screenshot 2020-04-12 at 5.39.41 PM.png

Solution 1: It depends why the model is wrong. If you assumed the world is not Markov, Q learning wont help because it also assumes Markov

Solution 2 still makes the basic assumption that your model class is correct.

The models we need to make decisions are not the models that we need for preductive accuracy. It doesn’t matter that we can represent many parts of our world accurately, if those parts are irrelevant to our decision-making.

Appendix 2:** Monte Carlo Tree Search**

Screenshot 2020-04-12 at 6.04.37 PM.png** **