Answers.Body: <p>The first thing to consider in this question is: what do we mean when we talk about "generating a child/node". Just creating a node for a tree data structure, and allocating some memory (initialised to nulls / zeros) for data like deeper children, visit counts, backpropagated scores, etc., is rarely a problem in terms of efficiency. </p>
  
  <p>If you also include generating a game state to store in that node when you say "generating a node", that can be a whole lot more expensive, since it requires applying the effects of a move to the previous game state to generate the new game state (and, depending on implementation, probably also requires first copying that previous game state). But you don't have to do this generally. You can just generate nodes, and only actually put a game state in them if you later on reach them again through the MCTS Selection phase.</p>
  
  <p>For example, you could say that AlphaZero does indeed generate all the nodes for all actions immediately, but they're generally "empty" nodes without game states. They do get "primed" with probabilities computed by the policy network, but that policy network doesn't require successor states inside those nodes; it's a function <span class="math-container">$\pi(s, a)$</span> of the <strong>current</strong> state <span class="math-container">$s$</span> (inside the previous node), and the action <span class="math-container">$a$</span> leading to the newly-generated node.</p>
  
  <hr>
  
  <p>But if you're really sure that, for your particular problem domain, the generation of nodes itself already is inefficient, then...</p>
  
  <blockquote>
    <p>[...] This is clearly biased in favor of children earlier in the stream.</p>
  </blockquote>
  
  <p>Yes, you would get a significant bias with such a stream-based approach, probably wouldn't work well.</p>
  
  <blockquote>
    <p>[...] This may be harder to implement than the previous version because computing the number of children may be as hard as computing the children themselves. [...]</p>
  </blockquote>
  
  <p>Again I agree with your observation, I don't think there are many problems where this would be a feasible solution.</p>
  
  <blockquote>
    <p>I believe that if the number of iterations of MCTS remaining, X_t, is larger than the number of children, N, then it doesn't matter what you do, because you'll find this node again the next iteration and expand one of the children.</p>
  </blockquote>
  
  <p>This would only be correct for the children of the root node. For any nodes deeper in the tree, it is possible that MCTS never reaches them again even if <span class="math-container">$X_t &gt; N$</span>, because it could dedicate most of it search effort to different subtrees.</p>
  
  <hr>
  
  <p>I think your solution would have to involve some sort of learned function (like the policy network in AlphaZero) which can efficiently compute a recommendation for a node to generate, only using the inputs that are already available before you pick a node to generate. In AlphaZero's policy network, those inputs would be the state <span class="math-container">$s$</span> in your current node, and the outward actions <span class="math-container">$a$</span> (each of which could lead to a node to be generated). <strong>This would often actually be very far from unbiased</strong>, but I imagine a strong, learned bias would likely be desireable anyway if you're in a situation where the mere generation of nodes is a legitimate concern for performance.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-31T05:44:28.113Z
Answers.Text: "AlphaZero does indeed generate all the nodes for all actions immediately, but they're generally "empty" node " Not quite empty. They generate Q for each action, and that's because of specific architecture which generate all Q's for state. In general getting Q for action could be expensive,
Answers.UserDisplayName: mirror2image
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-31T08:15:00.480Z
Answers.Text: @mirror2image I don't believe they generate $Q$ for every action. I don't have the paper in front of me, going by memory here, but... their network doesn't output $Q(s, a)$ for actions. It outputs $V(s)$ (value for a single state only, the current state), and $\pi(s, a)$ (the policy's "probability value") for every action available in $s$. Child nodes are only primed with $\pi(s, a)$ values because those are required by the Selection phase when it's in the current node $s$. Child nodes are not primed with $Q$-values (only once the selection phase picks a **single** child we need a $Q$ value).
Answers.UserDisplayName: Dennis Soemers
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-31T09:27:40.193Z
Answers.Text: Yes you correct, they generate V per state and p for each action. I mistake with different algorithm
Answers.UserDisplayName: mirror2image
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-30T19:07:09.143Z
Answers.LastActivityDate: 2019-07-30T19:07:09.143Z
Answers.UserDisplayName: Dennis Soemers
Answers.Body: <p>Dennis' answer is very helpful. I also found section 5.5 of the <a href="http://mcts.ai/pubs/mcts-survey-master.pdf" rel="nofollow noreferrer">MCTS survey</a> very useful, in particular the widening discussion. Another useful reference was <a href="https://project.dke.maastrichtuniversity.nl/games/files/msc/Roelofs_thesis.pdf" rel="nofollow noreferrer">https://project.dke.maastrichtuniversity.nl/games/files/msc/Roelofs_thesis.pdf</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-04T20:30:39.687Z
Answers.LastActivityDate: 2019-08-04T20:30:39.687Z
Answers.UserDisplayName: Jay McCarthy
Body: <p>When executing MCTS' expansion phase, where you create a number of child nodes, select one of the numbers, and simulate from that child, how can you efficiently and unbiasedly decide which child(ren) to generate?</p>
  
  <p>One strategy is to always generate all possible children. I believe that <a href="https://ai.stackexchange.com/a/12913/2444">this answer</a> says that AlphaZero always generates all possible (<span class="math-container">$\sim 300$</span>) children. If it were expensive to compute the children or if there were many of them, this might not be efficient.</p>
  
  <p>One strategy is to generate a lazy stream of possible children. That is, generate one child and a promise to generate the rest. You could then randomly select one by flipping a coin: heads you take the first child, tails you keep going. This is clearly biased in favor of children earlier in the stream.</p>
  
  <p>Another strategy is to compute how many <span class="math-container">$N$</span> children there are and provide a function to generate child <span class="math-container">$X &lt; N$</span> (of type Nat -> State). You could then randomly select one by choosing uniformly in the range <span class="math-container">$[0, N)$</span>. This may be harder to implement than the previous version because computing the number of children may be as hard as computing the children themselves. Alternatively, you could compute an upper-bound on the number of children and the function is partial (of type Nat -> Maybe State), but you'd be doing something like rejection sampling.</p>
  
  <p>I believe that if the number of iterations of MCTS remaining, <span class="math-container">$X_t$</span>, is larger than the number of children, <span class="math-container">$N$</span>, then it doesn't matter what you do, because you'll find this node again the next iteration and expand one of the children. This seems to suggest that the only time it matters is when <span class="math-container">$X_t &lt; N$</span> and in situations like AlphaZero, <span class="math-container">$N$</span> is so much smaller than <span class="math-container">$X_0$</span>, that this basically never matters.</p>
  
  <p>In cases where <span class="math-container">$X_0$</span> and <span class="math-container">$N$</span> are of similar size, then it seems like the number of iterations really needs to be changed into something like an amount of time and sometimes you spend your time doing playouts while other times you spend your time computing children.</p>
  
  <p>Have I thought about this correctly?</p>
  
Tags: <monte-carlo-tree-search>
Title: How can we efficiently and unbiasedly decide which children to generate in the expansion phase of MCTS?
UserDisplayName: Jay McCarthy
ThreadText: # How can we efficiently and unbiasedly decide which children to generate in the expansion phase of MCTS?
  
  (Asked by: username_0 on 2019-07-30)
  
  When executing MCTS' expansion phase, where you create a number of child nodes, select one of the numbers, and simulate from that child, how can you efficiently and unbiasedly decide which child(ren) to generate?
  
  One strategy is to always generate all possible children. I believe that [this answer](https://ai.stackexchange.com/a/12913/2444) says that AlphaZero always generates all possible ($\sim 300$) children. If it were expensive to compute the children or if there were many of them, this might not be efficient.
  
  One strategy is to generate a lazy stream of possible children. That is, generate one child and a promise to generate the rest. You could then randomly select one by flipping a coin: heads you take the first child, tails you keep going. This is clearly biased in favor of children earlier in the stream.
  
  Another strategy is to compute how many $N$ children there are and provide a function to generate child $X < N$ (of type Nat -> State). You could then randomly select one by choosing uniformly in the range $[0, N)$. This may be harder to implement than the previous version because computing the number of children may be as hard as computing the children themselves. Alternatively, you could compute an upper-bound on the number of children and the function is partial (of type Nat -> Maybe State), but you'd be doing something like rejection sampling.
  
  I believe that if the number of iterations of MCTS remaining, $X\_t$, is larger than the number of children, $N$, then it doesn't matter what you do, because you'll find this node again the next iteration and expand one of the children. This seems to suggest that the only time it matters is when $X\_t < N$ and in situations like AlphaZero, $N$ is so much smaller than $X\_0$, that this basically never matters.
  
  In cases where $X\_0$ and $N$ are of similar size, then it seems like the number of iterations really needs to be changed into something like an amount of time and sometimes you spend your time doing playouts while other times you spend your time computing children.
  
  Have I thought about this correctly?
  
  **Tags:** monte-carlo-tree-search
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-07-30. Score: 1 | Accepted answer
  
  The first thing to consider in this question is: what do we mean when we talk about "generating a child/node". Just creating a node for a tree data structure, and allocating some memory (initialised to nulls / zeros) for data like deeper children, visit counts, backpropagated scores, etc., is rarely a problem in terms of efficiency.
  
  If you also include generating a game state to store in that node when you say "generating a node", that can be a whole lot more expensive, since it requires applying the effects of a move to the previous game state to generate the new game state (and, depending on implementation, probably also requires first copying that previous game state). But you don't have to do this generally. You can just generate nodes, and only actually put a game state in them if you later on reach them again through the MCTS Selection phase.
  
  For example, you could say that AlphaZero does indeed generate all the nodes for all actions immediately, but they're generally "empty" nodes without game states. They do get "primed" with probabilities computed by the policy network, but that policy network doesn't require successor states inside those nodes; it's a function $\pi(s, a)$ of the **current** state $s$ (inside the previous node), and the action $a$ leading to the newly-generated node.
  
  ---
  
  But if you're really sure that, for your particular problem domain, the generation of nodes itself already is inefficient, then...
  
  > [...] This is clearly biased in favor of children earlier in the stream.
  
  Yes, you would get a significant bias with such a stream-based approach, probably wouldn't work well.
  
  > [...] This may be harder to implement than the previous version because computing the number of children may be as hard as computing the children themselves. [...]
  
  Again I agree with your observation, I don't think there are many problems where this would be a feasible solution.
  
  > I believe that if the number of iterations of MCTS remaining, X\_t, is larger than the number of children, N, then it doesn't matter what you do, because you'll find this node again the next iteration and expand one of the children.
  
  This would only be correct for the children of the root node. For any nodes deeper in the tree, it is possible that MCTS never reaches them again even if $X\_t > N$, because it could dedicate most of it search effort to different subtrees.
  
  ---
  
  I think your solution would have to involve some sort of learned function (like the policy network in AlphaZero) which can efficiently compute a recommendation for a node to generate, only using the inputs that are already available before you pick a node to generate. In AlphaZero's policy network, those inputs would be the state $s$ in your current node, and the outward actions $a$ (each of which could lead to a node to be generated). **This would often actually be very far from unbiased**, but I imagine a strong, learned bias would likely be desireable anyway if you're in a situation where the mere generation of nodes is a legitimate concern for performance.
  
  > **Comments:**
  > **username_2**: "AlphaZero does indeed generate all the nodes for all actions immediately, but they're generally "empty" node " Not quite empty. They generate Q for each action, and that's because of specific architecture which generate all Q's for state. In general getting Q for action could be expensive,  
  > **username_1**: @username_2 I don't believe they generate $Q$ for every action. I don't have the paper in front of me, going by memory here, but... their network doesn't output $Q(s, a)$ for actions. It outputs $V(s)$ (value for a single state only, the current state), and $\pi(s, a)$ (the policy's "probability value") for every action available in $s$. Child nodes are only primed with $\pi(s, a)$ values because those are required by the Selection phase when it's in the current node $s$. Child nodes are not primed with $Q$-values (only once the selection phase picks a **single** child we need a $Q$ value).  
  > **username_2**: Yes you correct, they generate V per state and p for each action. I mistake with different algorithm  
  
  ---
  
  ### Answer by username_0 on 2019-08-04. Score: 1
  
  username_1' answer is very helpful. I also found section 5.5 of the [MCTS survey](http://mcts.ai/pubs/mcts-survey-master.pdf) very useful, in particular the widening discussion. Another useful reference was <https://project.dke.maastrichtuniversity.nl/games/files/msc/Roelofs_thesis.pdf>
  
  
  ---
  
  