alpaca/alpacka/agents/stochastic_mcts.py
def _expand_leaf(self, leaf, observation, done, visited):
        """Expands a leaf and returns its quality.

        The leaf's new children are assigned initial rewards and values. The
        reward and value of the "best" new leaf is then backpropagated.

        Only modifies leaf - assigns a GraphNode and adds children.

        Args:
            leaf (TreeNode): Leaf to expand.
            observation (np.ndarray): Observation received at leaf.
            done (bool): "Done" flag received at leaf.
            visited (set): Set of GraphNodes visited on the path from the root.

        Yields:
            Network prediction requests.

        Returns:
            float: Quality of a chosen child of the expanded leaf, or None if we
            shouldn't backpropagate quality beause the node has already been
            visited.
        """
        assert leaf.is_leaf

        if done:
            leaf.is_terminal = True
            # In a "done" state, cumulative future return is 0.
            return 0

        already_in_graph = False
        if self._graph_mode:
            state = self._model.clone_state()
            graph_node = self._state_to_graph_node.get(state, None)
            leaf.init_graph_node(graph_node)
            if graph_node is not None:
                already_in_graph = True
            else:
                self._state_to_graph_node[state] = leaf.graph_node
        else:
            leaf.init_graph_node()

        child_ratings = yield from self._rate_new_leaves(
            leaf, observation, self._model, self._discount
        )
        leaf.children = [
            TreeNode(reward, value) for (reward, value) in child_ratings
        ]
        if already_in_graph:
            # Node is already in graph, don't backpropagate quality.
            return None
        action = self._choose_action(leaf, visited)
        return leaf.children[action].quality(self._discount)
Expands a leaf and returns its quality.

        The leaf's new children are assigned initial rewards and values. The
        reward and value of the "best" new leaf is then backpropagated.

        Only modifies leaf - assigns a GraphNode and adds children.

        Args:
            leaf (TreeNode): Leaf to expand.
            observation (np.ndarray): Observation received at leaf.
            done (bool): "Done" flag received at leaf.
            visited (set): Set of GraphNodes visited on the path from the root.

        Yields:
            Network prediction requests.

        Returns:
            float: Quality of a chosen child of the expanded leaf, or None if we
            shouldn't backpropagate quality beause the node has already been
            visited.
        
Expands a leaf and returns its quality.
The leaf's new children are assigned initial rewards and values. The
reward and value of the "best" new leaf is then backpropagated.

Only modifies leaf - assigns a GraphNode and adds children.
Expands a leaf and returns its quality . The leaf ' s new children are assigned initial rewards and values . The reward and value of the " best " new leaf is then backpropagated . Only modifies leaf - assigns a GraphNode and adds children .
def _expand_leaf(self, leaf, observation, done, visited):
        assert leaf.is_leaf
        if done:
            leaf.is_terminal = True
            return 0
        already_in_graph = False
        if self._graph_mode:
            state = self._model.clone_state()
            graph_node = self._state_to_graph_node.get(state, None)
            leaf.init_graph_node(graph_node)
            if graph_node is not None:
                already_in_graph = True
            else:
                self._state_to_graph_node[state] = leaf.graph_node
        else:
            leaf.init_graph_node()
        child_ratings = yield from self._rate_new_leaves(
            leaf, observation, self._model, self._discount
        )
        leaf.children = [
            TreeNode(reward, value) for (reward, value) in child_ratings
        ]
        if already_in_graph:
            return None
        action = self._choose_action(leaf, visited)
        return leaf.children[action].quality(self._discount)
def _expand_leaf ( self , leaf , observation , done , visited ) : assert leaf . is_leaf if done : leaf . is_terminal = True return 0 already_in_graph = False if self . _graph_mode : state = self . _model . clone_state ( ) graph_node = self . _state_to_graph_node . get ( state , None ) leaf . init_graph_node ( graph_node ) if graph_node is not None : already_in_graph = True else : self . _state_to_graph_node [ state ] = leaf . graph_node else : leaf . init_graph_node ( ) child_ratings = yield from self . _rate_new_leaves ( leaf , observation , self . _model , self . _discount ) leaf . children = [ TreeNode ( reward , value ) for ( reward , value ) in child_ratings ] if already_in_graph : return None action = self . _choose_action ( leaf , visited ) return leaf . children [ action ] . quality ( self . _discount )
Expands a leaf and returns its quality.
Expands a leaf and returns its quality .
"""Expands a leaf and returns its quality.

        The leaf's new children are assigned initial rewards and values. The
        reward and value of the "best" new leaf is then backpropagated.

        Only modifies leaf - assigns a GraphNode and adds children.

        Args:
            leaf (TreeNode): Leaf to expand.
            observation (np.ndarray): Observation received at leaf.
            done (bool): "Done" flag received at leaf.
            visited (set): Set of GraphNodes visited on the path from the root.

        Yields:
            Network prediction requests.

        Returns:
            float: Quality of a chosen child of the expanded leaf, or None if we
            shouldn't backpropagate quality beause the node has already been
            visited.
        """ # In a "done" state, cumulative future return is 0. # Node is already in graph, don't backpropagate quality.
Network prediction requests.
Network prediction requests .
Quality of a chosen child of the expanded leaf, or None if we
shouldn't backpropagate quality beause the node has already been
visited.
Quality of a chosen child of the expanded leaf or None if we shouldn ' t backpropagate quality beause the node has already been visited .
float
self
leaf
Leaf to expand.
Leaf to expand .
observation
Observation received at leaf.
Observation received at leaf .
done
"Done" flag received at leaf.
" Done " flag received at leaf .
visited
Set of GraphNodes visited on the path from the root.
Set of GraphNodes visited on the path from the root .