当前位置: 首页>>代码示例>>Python>>正文


Python mcts.MCTSNode方法代码示例

本文整理汇总了Python中mcts.MCTSNode方法的典型用法代码示例。如果您正苦于以下问题:Python mcts.MCTSNode方法的具体用法?Python mcts.MCTSNode怎么用?Python mcts.MCTSNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mcts的用法示例。


在下文中一共展示了mcts.MCTSNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_never_select_illegal_moves

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_never_select_illegal_moves(self):
        probs = np.array([0.02] * (go.N * go.N + 1))
        # let's say the NN were to accidentally put a high weight on an illegal move
        probs[1] = 0.99
        root = MCTSNode(SEND_TWO_RETURN_ONE)
        root.incorporate_results(probs, 0, root)
        # and let's say the root were visited a lot of times, which pumps up the
        # action score for unvisited moves...
        root.N = 100000
        root.child_N[root.position.all_legal_moves()] = 10000
        # this should not throw an error...
        leaf = root.select_leaf()
        # the returned leaf should not be the illegal move
        self.assertNotEqual(leaf.fmove, 1)

        # and even after injecting noise, we should still not select an illegal move
        for i in range(10):
            root.inject_noise()
            leaf = root.select_leaf()
            self.assertNotEqual(leaf.fmove, 1) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:22,代码来源:test_mcts.py

示例2: test_action_flipping

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_action_flipping(self):
    np.random.seed(1)
    probs = np.array([.02] * (
        utils_test.BOARD_SIZE * utils_test.BOARD_SIZE + 1))
    probs += np.random.random(
        [utils_test.BOARD_SIZE * utils_test.BOARD_SIZE + 1]) * 0.001
    black_root = MCTSNode(
        utils_test.BOARD_SIZE, go.Position(utils_test.BOARD_SIZE))
    white_root = MCTSNode(utils_test.BOARD_SIZE, go.Position(
        utils_test.BOARD_SIZE, to_play=go.WHITE))
    black_root.select_leaf().incorporate_results(probs, 0, black_root)
    white_root.select_leaf().incorporate_results(probs, 0, white_root)
    # No matter who is to play, when we know nothing else, the priors
    # should be respected, and the same move should be picked
    black_leaf = black_root.select_leaf()
    white_leaf = white_root.select_leaf()
    self.assertEqual(black_leaf.fmove, white_leaf.fmove)
    self.assertEqualNPArray(
        black_root.child_action_score, white_root.child_action_score) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:21,代码来源:mcts_test.py

示例3: test_never_select_illegal_moves

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_never_select_illegal_moves(self):
    probs = np.array([0.02] * (
        utils_test.BOARD_SIZE * utils_test.BOARD_SIZE + 1))
    # let's say the NN were to accidentally put a high weight on an illegal move
    probs[1] = 0.99
    root = MCTSNode(utils_test.BOARD_SIZE, SEND_TWO_RETURN_ONE)
    root.incorporate_results(probs, 0, root)
    # and let's say the root were visited a lot of times, which pumps up the
    # action score for unvisited moves...
    root.N = 100000
    root.child_N[root.position.all_legal_moves()] = 10000
    # this should not throw an error...
    leaf = root.select_leaf()
    # the returned leaf should not be the illegal move
    self.assertNotEqual(leaf.fmove, 1)

    # and even after injecting noise, we should still not select an illegal move
    for _ in range(10):
      root.inject_noise()
      leaf = root.select_leaf()
      self.assertNotEqual(leaf.fmove, 1) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:23,代码来源:mcts_test.py

示例4: test_never_select_illegal_moves

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_never_select_illegal_moves(self):
        probs = np.array([0.02] * (go.N * go.N + 1))
        # let's say the NN were to accidentally put a high weight on an illegal move
        probs[1] = 0.99
        root = mcts.MCTSNode(SEND_TWO_RETURN_ONE)
        root.incorporate_results(probs, 0, root)
        # and let's say the root were visited a lot of times, which pumps up the
        # action score for unvisited moves...
        root.N = 100000
        root.child_N[root.position.all_legal_moves()] = 10000
        # this should not throw an error...
        leaf = root.select_leaf()
        # the returned leaf should not be the illegal move
        self.assertNotEqual(1, leaf.fmove)

        # and even after injecting noise, we should still not select an illegal move
        for i in range(10):
            root.inject_noise()
            leaf = root.select_leaf()
            self.assertNotEqual(1, leaf.fmove) 
开发者ID:mlperf,项目名称:training,代码行数:22,代码来源:test_mcts.py

示例5: initialize_game

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def initialize_game(self, position=None):
        if position is None:
            position = go.Position()
        self.root = MCTSNode(position)
        self.result = 0
        self.result_string = None
        self.comments = []
        self.searches_pi = []
        self.qs = [] 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:11,代码来源:strategies.py

示例6: test_action_flipping

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_action_flipping(self):
        np.random.seed(1)
        probs = np.array([.02] * (go.N * go.N + 1))
        probs = probs + np.random.random([go.N * go.N + 1]) * 0.001
        black_root = MCTSNode(go.Position())
        white_root = MCTSNode(go.Position(to_play=go.WHITE))
        black_root.select_leaf().incorporate_results(probs, 0, black_root)
        white_root.select_leaf().incorporate_results(probs, 0, white_root)
        # No matter who is to play, when we know nothing else, the priors
        # should be respected, and the same move should be picked
        black_leaf = black_root.select_leaf()
        white_leaf = white_root.select_leaf()
        self.assertEqual(black_leaf.fmove, white_leaf.fmove)
        self.assertEqualNPArray(
            black_root.child_action_score, white_root.child_action_score) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:17,代码来源:test_mcts.py

示例7: test_select_leaf

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_select_leaf(self):
        flattened = coords.to_flat(coords.from_kgs('D9'))
        probs = np.array([.02] * (go.N * go.N + 1))
        probs[flattened] = 0.4
        root = MCTSNode(SEND_TWO_RETURN_ONE)
        root.select_leaf().incorporate_results(probs, 0, root)

        self.assertEqual(root.position.to_play, go.WHITE)
        self.assertEqual(root.select_leaf(), root.children[flattened]) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:11,代码来源:test_mcts.py

示例8: test_do_not_explore_past_finish

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_do_not_explore_past_finish(self):
        probs = np.array([0.02] * (go.N * go.N + 1), dtype=np.float32)
        root = MCTSNode(go.Position())
        root.select_leaf().incorporate_results(probs, 0, root)
        first_pass = root.maybe_add_child(coords.to_flat(None))
        first_pass.incorporate_results(probs, 0, root)
        second_pass = first_pass.maybe_add_child(coords.to_flat(None))
        with self.assertRaises(AssertionError):
            second_pass.incorporate_results(probs, 0, root)
        node_to_explore = second_pass.select_leaf()
        # should just stop exploring at the end position.
        self.assertEqual(node_to_explore, second_pass) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:14,代码来源:test_mcts.py

示例9: test_add_child_idempotency

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_add_child_idempotency(self):
        root = MCTSNode(go.Position())
        child = root.maybe_add_child(17)
        current_children = copy.copy(root.children)
        child2 = root.maybe_add_child(17)
        self.assertEqual(child, child2)
        self.assertEqual(current_children, root.children) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:9,代码来源:test_mcts.py

示例10: test_dont_pick_unexpanded_child

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_dont_pick_unexpanded_child(self):
        probs = np.array([0.001] * (go.N * go.N + 1))
        # make one move really likely so that tree search goes down that path twice
        # even with a virtual loss
        probs[17] = 0.999
        root = MCTSNode(go.Position())
        root.incorporate_results(probs, 0, root)
        leaf1 = root.select_leaf()
        self.assertEqual(leaf1.fmove, 17)
        leaf1.add_virtual_loss(up_to=root)
        # the second select_leaf pick should return the same thing, since the child
        # hasn't yet been sent to neural net for eval + result incorporation
        leaf2 = root.select_leaf()
        self.assertIs(leaf1, leaf2) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:16,代码来源:test_mcts.py

示例11: test_add_child

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_add_child(self):
        root = MCTSNode(go.Position())
        child = root.maybe_add_child(17)
        self.assertIn(17, root.children)
        self.assertEqual(child.parent, root)
        self.assertEqual(child.fmove, 17) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:8,代码来源:test_mcts.py

示例12: initialize_game

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def initialize_game(self, position=None):
    if position is None:
      position = go.Position(self.board_size)
    self.root = MCTSNode(self.board_size, position)
    self.result = 0
    self.result_string = None
    self.comments = []
    self.searches_pi = []
    self.qs = [] 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:11,代码来源:strategies.py

示例13: test_select_leaf

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_select_leaf(self):
    flattened = coords.to_flat(utils_test.BOARD_SIZE, coords.from_kgs(
        utils_test.BOARD_SIZE, 'D9'))
    probs = np.array([.02] * (
        utils_test.BOARD_SIZE * utils_test.BOARD_SIZE + 1))
    probs[flattened] = 0.4
    root = MCTSNode(utils_test.BOARD_SIZE, SEND_TWO_RETURN_ONE)
    root.select_leaf().incorporate_results(probs, 0, root)

    self.assertEqual(root.position.to_play, go.WHITE)
    self.assertEqual(root.select_leaf(), root.children[flattened]) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:13,代码来源:mcts_test.py

示例14: test_do_not_explore_past_finish

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_do_not_explore_past_finish(self):
    probs = np.array([0.02] * (
        utils_test.BOARD_SIZE * utils_test.BOARD_SIZE + 1), dtype=np.float32)
    root = MCTSNode(utils_test.BOARD_SIZE, go.Position(utils_test.BOARD_SIZE))
    root.select_leaf().incorporate_results(probs, 0, root)
    first_pass = root.maybe_add_child(
        coords.to_flat(utils_test.BOARD_SIZE, None))
    first_pass.incorporate_results(probs, 0, root)
    second_pass = first_pass.maybe_add_child(
        coords.to_flat(utils_test.BOARD_SIZE, None))
    with self.assertRaises(AssertionError):
      second_pass.incorporate_results(probs, 0, root)
    node_to_explore = second_pass.select_leaf()
    # should just stop exploring at the end position.
    self.assertEqual(node_to_explore, second_pass) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:17,代码来源:mcts_test.py

示例15: test_add_child_idempotency

# 需要导入模块: import mcts [as 别名]
# 或者: from mcts import MCTSNode [as 别名]
def test_add_child_idempotency(self):
    root = MCTSNode(utils_test.BOARD_SIZE, go.Position(utils_test.BOARD_SIZE))
    child = root.maybe_add_child(17)
    current_children = copy.copy(root.children)
    child2 = root.maybe_add_child(17)
    self.assertEqual(child, child2)
    self.assertEqual(current_children, root.children) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:9,代码来源:mcts_test.py


注:本文中的mcts.MCTSNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。