algorithms/mcts_basic.py
def _uct_select(self, node):
        "Select a child of node, balancing exploration & exploitation"

        # All children of node should already be expanded:
        assert all(n in self.children for n in self.children[node])
        assert all(n in self.N for n in self.children[node])

        if len(self.children[node]) == 1:
            return list(self.children[node])[0]

        sqrt_parent_visits = math.sqrt(self.N[node])
        player = node.active_player
        avgs = {n: self.Q[n][player] / self.N[n] for n in self.children[node]}

        baseline_probabilities = np.array(
            [1.0 / len(self.children[node])] * 32)
        if self.policy_model is not None and self.policy_ucb_coef > 0.0:
            policy_probabilities = node.policy_estimate(self.policy_model)
            policy_probabilities = (self.policy_ucb_coef * policy_probabilities +
                                    (1 - self.policy_ucb_coef) * baseline_probabilities)
        else:
            policy_probabilities = baseline_probabilities

        def uct(n):
            "Upper confidence bound for trees"
            policy_value = policy_probabilities[n.last_played_card]
            exploration_value = self.exploration_weight * \
                policy_value * sqrt_parent_visits / (self.N[n])
            return avgs[n] + exploration_value

        return max(self.children[node], key=uct)
Select a child of node, balancing exploration & exploitation
Select a child of node, balancing exploration & exploitation
Select a child of node balancing exploration & exploitation
def _uct_select(self, node):
        assert all(n in self.children for n in self.children[node])
        assert all(n in self.N for n in self.children[node])
        if len(self.children[node]) == 1:
            return list(self.children[node])[0]
        sqrt_parent_visits = math.sqrt(self.N[node])
        player = node.active_player
        avgs = {n: self.Q[n][player] / self.N[n] for n in self.children[node]}
        baseline_probabilities = np.array(
            [1.0 / len(self.children[node])] * 32)
        if self.policy_model is not None and self.policy_ucb_coef > 0.0:
            policy_probabilities = node.policy_estimate(self.policy_model)
            policy_probabilities = (self.policy_ucb_coef * policy_probabilities +
                                    (1 - self.policy_ucb_coef) * baseline_probabilities)
        else:
            policy_probabilities = baseline_probabilities
        def uct(n):
            policy_value = policy_probabilities[n.last_played_card]
            exploration_value = self.exploration_weight * \
                policy_value * sqrt_parent_visits / (self.N[n])
            return avgs[n] + exploration_value
        return max(self.children[node], key=uct)
def _uct_select ( self , node ) : assert all ( n in self . children for n in self . children [ node ] ) assert all ( n in self . N for n in self . children [ node ] ) if len ( self . children [ node ] ) == 1 : return list ( self . children [ node ] ) [ 0 ] sqrt_parent_visits = math . sqrt ( self . N [ node ] ) player = node . active_player avgs = { n : self . Q [ n ] [ player ] / self . N [ n ] for n in self . children [ node ] } baseline_probabilities = np . array ( [ 1.0 / len ( self . children [ node ] ) ] * 32 ) if self . policy_model is not None and self . policy_ucb_coef > 0.0 : policy_probabilities = node . policy_estimate ( self . policy_model ) policy_probabilities = ( self . policy_ucb_coef * policy_probabilities + ( 1 - self . policy_ucb_coef ) * baseline_probabilities ) else : policy_probabilities = baseline_probabilities def uct ( n ) : "Upper confidence bound for trees" policy_value = policy_probabilities [ n . last_played_card ] exploration_value = self . exploration_weight * policy_value * sqrt_parent_visits / ( self . N [ n ] ) return avgs [ n ] + exploration_value return max ( self . children [ node ] , key = uct )
Select a child of node, balancing exploration & exploitation
Select a child of node balancing exploration & exploitation
"Select a child of node, balancing exploration & exploitation" # All children of node should already be expanded: "Upper confidence bound for trees"
self
node