Ejemplo n.º 1
0
    def test_evaluate_leaf(self):
        game_root = Game()
        root = Node(game_root)
        model = MagicMock()

        prediction = [
            np.array([[0.25]]),
            np.reshape(np.arange(0.001, 0.897, step=0.001), newshape=(1, 896))
        ]
        model.predict.return_value = prediction

        action_encoder = ActionEncoder(DirectionResolver())
        mcts = MCTS(root,
                    config={
                        'ALPHA': 0.8,
                        'CPUCT': 1,
                        'EPSILON': 0.2
                    },
                    model=model,
                    state_encoder=StateEncoder(),
                    action_encoder=action_encoder)
        _, probs, _ = mcts.predict_state_value(game_root)
        value = mcts.evaluate_leaf(root)
        self.assertEqual(value, 0.25)
        self.assertEqual(len(root.edges), 7)
        self.assertEqual(root.edges[0].action, 8)
        self.assertEqual(root.edges[0].stats['P'], probs[8])

        self.assertEqual(root.edges[1].action, 104)
        self.assertEqual(root.edges[1].stats['P'], probs[104])
Ejemplo n.º 2
0
    def test_integration(self):
        HIDDEN_CNN_LAYERS = [{
            'filters': 75,
            'kernel_size': (4, 4)
        }, {
            'filters': 75,
            'kernel_size': (4, 4)
        }, {
            'filters': 75,
            'kernel_size': (4, 4)
        }, {
            'filters': 75,
            'kernel_size': (4, 4)
        }, {
            'filters': 75,
            'kernel_size': (4, 4)
        }, {
            'filters': 75,
            'kernel_size': (4, 4)
        }]
        model = Residual_CNN(0.0001,
                             0.1, (2, 4, 8),
                             32 * 4,
                             HIDDEN_CNN_LAYERS,
                             momentum=0.9)
        game_root = Game()
        root = Node(game_root)
        mcts = MCTS(root,
                    config={
                        'ALPHA': 0.8,
                        'CPUCT': 1,
                        'EPSILON': 0.2
                    },
                    model=model,
                    state_encoder=StateEncoder(),
                    action_encoder=ActionEncoder(DirectionResolver()))

        mcts.predict_state_value(game_root)
        mcts.evaluate_leaf(root)