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


Python go.N属性代码示例

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


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

示例1: get_default_hyperparams

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def get_default_hyperparams(**overrides):
    """Returns the hyperparams for the neural net.

    In other words, returns a dict whose parameters come from the AGZ
    paper:
      k: number of filters (AlphaGoZero used 256). We use 128 by
        default for a 19x19 go board.
      fc_width: Dimensionality of the fully connected linear layer
      num_shared_layers: number of shared residual blocks.  AGZ used both 19
        and 39. Here we use 19 because it's faster to train.
      l2_strength: The L2 regularization parameter.
      momentum: The momentum parameter for training
    """
    k = _round_power_of_two(go.N ** 2 / 3)  # width of each layer
    hparams = {
        'k': k,  # Width of each conv layer
        'fc_width': 2 * k,  # Width of each fully connected layer
        'num_shared_layers': go.N,  # Number of shared trunk layers
        'l2_strength': 1e-4,  # Regularization strength
        'momentum': 0.9,  # Momentum used in SGD
    }
    hparams.update(**overrides)
    return hparams 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:25,代码来源:dual_net.py

示例2: incorporate_results

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def incorporate_results(self, move_probabilities, value, up_to):
        assert move_probabilities.shape == (go.N * go.N + 1,)
        # A finished game should not be going through this code path - should
        # directly call backup_value() on the result of the game.
        assert not self.position.is_game_over()
        if self.is_expanded:
            self.revert_visits(up_to=up_to)
            return
        self.is_expanded = True
        self.original_prior = self.child_prior = move_probabilities
        # initialize child Q as current node's value, to prevent dynamics where
        # if B is winning, then B will only ever explore 1 move, because the Q
        # estimation will be so much larger than the 0 of the other moves.
        #
        # Conversely, if W is winning, then B will explore all 362 moves before
        # continuing to explore the most favorable move. This is a waste of search.
        #
        # The value seeded here acts as a prior, and gets averaged into Q calculations.
        self.child_W = np.ones([go.N * go.N + 1], dtype=np.float32) * value
        self.backup_value(value, up_to=up_to) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:22,代码来源:mcts.py

示例3: stone_features

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def stone_features(position):
    # a bit easier to calculate it with axis 0 being the 16 board states,
    # and then roll axis 0 to the end.
    features = np.zeros([16, go.N, go.N], dtype=np.uint8)

    num_deltas_avail = position.board_deltas.shape[0]
    cumulative_deltas = np.cumsum(position.board_deltas, axis=0)
    last_eight = np.tile(position.board, [8, 1, 1])
    # apply deltas to compute previous board states
    last_eight[1:num_deltas_avail + 1] -= cumulative_deltas
    # if no more deltas are available, just repeat oldest board.
    last_eight[num_deltas_avail +
               1:] = last_eight[num_deltas_avail].reshape(1, go.N, go.N)

    features[::2] = last_eight == position.to_play
    features[1::2] = last_eight == -position.to_play
    return np.rollaxis(features, 0, 3) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:19,代码来源:features.py

示例4: make_tf_example

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def make_tf_example(features, pi, value):
    '''
    Args:
        features: [N, N, FEATURE_DIM] nparray of uint8
        pi: [N * N + 1] nparray of float32
        value: float
    '''
    return tf.train.Example(features=tf.train.Features(feature={
        'x': tf.train.Feature(
            bytes_list=tf.train.BytesList(
                value=[features.tostring()])),
        'pi': tf.train.Feature(
            bytes_list=tf.train.BytesList(
                value=[pi.tostring()])),
        'outcome': tf.train.Feature(
            float_list=tf.train.FloatList(
                value=[value]))}))

# Write tf.Example to files 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:21,代码来源:preprocessing.py

示例5: test_pick_moves

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def test_pick_moves(self):
        player = initialize_basic_player()
        root = player.root
        root.child_N[coords.to_flat((2, 0))] = 10
        root.child_N[coords.to_flat((1, 0))] = 5
        root.child_N[coords.to_flat((3, 0))] = 1

        root.position.n = go.N ** 2  # move 81, or 361, or... Endgame.

        # Assert we're picking deterministically
        self.assertTrue(root.position.n > player.temp_threshold)
        move = player.pick_move()
        self.assertEqual(move, (2, 0))

        # But if we're in the early part of the game, pick randomly
        root.position.n = 3
        self.assertFalse(player.root.position.n > player.temp_threshold)

        with mock.patch('random.random', lambda: .5):
            move = player.pick_move()
            self.assertEqual(move, (2, 0))

        with mock.patch('random.random', lambda: .99):
            move = player.pick_move()
            self.assertEqual(move, (3, 0)) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:27,代码来源:test_strategies.py

示例6: test_dont_pass_if_losing

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def test_dont_pass_if_losing(self):
        player = initialize_almost_done_player()

        # check -- white is losing.
        self.assertEqual(player.root.position.score(), -0.5)

        for i in range(20):
            player.tree_search()
        # uncomment to debug this test
        # print(player.root.describe())

        # Search should converge on D9 as only winning move.
        flattened = coords.to_flat(coords.from_kgs('D9'))
        best_move = np.argmax(player.root.child_N)
        self.assertEqual(best_move, flattened)
        # D9 should have a positive value
        self.assertGreater(player.root.children[flattened].Q, 0)
        self.assertGreaterEqual(player.root.N, 20)
        # passing should be ineffective.
        self.assertLess(player.root.child_Q[-1], 0)
        # no virtual losses should be pending
        self.assertNoPendingVirtualLosses(player.root)
        # uncomment to debug this test
        # print(player.root.describe()) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:26,代码来源:test_strategies.py

示例7: test_only_check_game_end_once

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def test_only_check_game_end_once(self):
        # When presented with a situation where the last move was a pass,
        # and we have to decide whether to pass, it should be the first thing
        # we check, but not more than that.

        white_passed_pos = go.Position(
        ).play_move((3, 3)  # b plays
                    ).play_move((3, 4)  # w plays
                                ).play_move((4, 3)  # b plays
                                            ).pass_move()  # w passes - if B passes too, B would lose by komi.

        player = MCTSPlayerMixin(DummyNet())
        player.initialize_game(white_passed_pos)
        # initialize the root
        player.tree_search()
        # explore a child - should be a pass move.
        player.tree_search()
        pass_move = go.N * go.N
        self.assertEqual(player.root.children[pass_move].N, 1)
        self.assertEqual(player.root.child_N[pass_move], 1)
        player.tree_search()
        # check that we didn't visit the pass node any more times.
        self.assertEqual(player.root.child_N[pass_move], 1) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:25,代码来源:test_strategies.py

示例8: test_never_select_illegal_moves

# 需要导入模块: import go [as 别名]
# 或者: from go import N [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

示例9: load_board

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def load_board(string):
    reverse_map = {
        'X': go.BLACK,
        'O': go.WHITE,
        '.': go.EMPTY,
        '#': go.FILL,
        '*': go.KO,
        '?': go.UNKNOWN
    }

    string = re.sub(r'[^XO\.#]+', '', string)
    assert len(string) == go.N ** 2, "Board to load didn't have right dimensions"
    board = np.zeros([go.N, go.N], dtype=np.int8)
    for i, char in enumerate(string):
        np.ravel(board)[i] = reverse_map[char]
    return board 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:18,代码来源:test_utils.py

示例10: make_sgf

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def make_sgf(
    move_history,
    result_string,
    ruleset="Chinese",
    komi=7.5,
    white_name=PROGRAM_IDENTIFIER,
    black_name=PROGRAM_IDENTIFIER,
    comments=[]
):
    '''Turn a game into SGF.

    Doesn't handle handicap games or positions with incomplete history.

    Args:
        move_history: iterable of PlayerMoves
        result_string: "B+R", "W+0.5", etc.
        comments: iterable of string/None. Will be zipped with move_history.
    '''
    boardsize = go.N
    game_moves = ''.join(translate_sgf_move(*z)
                         for z in itertools.zip_longest(move_history, comments))
    result = result_string
    return SGF_TEMPLATE.format(**locals()) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:25,代码来源:sgf_wrapper.py

示例11: __init__

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def __init__(self, position, fmove=None, parent=None):
        if parent is None:
            parent = DummyNode()
        self.parent = parent
        self.fmove = fmove  # move that led to this position, as flattened coords
        self.position = position
        self.is_expanded = False
        self.losses_applied = 0  # number of virtual losses on this node
        # using child_() allows vectorized computation of action score.
        self.illegal_moves = 1000 * (1 - self.position.all_legal_moves())
        self.child_N = np.zeros([go.N * go.N + 1], dtype=np.float32)
        self.child_W = np.zeros([go.N * go.N + 1], dtype=np.float32)
        # save a copy of the original prior before it gets mutated by d-noise.
        self.original_prior = np.zeros([go.N * go.N + 1], dtype=np.float32)
        self.child_prior = np.zeros([go.N * go.N + 1], dtype=np.float32)
        self.children = {}  # map of flattened moves to resulting MCTSNode 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:18,代码来源:mcts.py

示例12: select_leaf

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def select_leaf(self):
        current = self
        pass_move = go.N * go.N
        while True:
            current.N += 1
            # if a node has never been evaluated, we have no basis to select a child.
            if not current.is_expanded:
                break
            # HACK: if last move was a pass, always investigate double-pass first
            # to avoid situations where we auto-lose by passing too early.
            if (current.position.recent
                and current.position.recent[-1].move is None
                    and current.child_N[pass_move] == 0):
                current = current.maybe_add_child(pass_move)
                continue

            best_move = np.argmax(current.child_action_score)
            current = current.maybe_add_child(best_move)
        return current 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:21,代码来源:mcts.py

示例13: batch_parse_tf_example

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def batch_parse_tf_example(batch_size, example_batch):
    '''
    Args:
        example_batch: a batch of tf.Example
    Returns:
        A tuple (feature_tensor, dict of output tensors)
    '''
    features = {
        'x': tf.FixedLenFeature([], tf.string),
        'pi': tf.FixedLenFeature([], tf.string),
        'outcome': tf.FixedLenFeature([], tf.float32),
    }
    parsed = tf.parse_example(example_batch, features)
    x = tf.decode_raw(parsed['x'], tf.uint8)
    x = tf.cast(x, tf.float32)
    x = tf.reshape(x, [batch_size, go.N, go.N,
                       features_lib.NEW_FEATURES_PLANES])
    pi = tf.decode_raw(parsed['pi'], tf.float32)
    pi = tf.reshape(pi, [batch_size, go.N * go.N + 1])
    outcome = parsed['outcome']
    outcome.set_shape([batch_size])
    return (x, {'pi_tensor': pi, 'value_tensor': outcome}) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:24,代码来源:preprocessing.py

示例14: generate

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def generate(model_num):
    if model_num == 0:
        new_name = 'bootstrap'
    elif go.N == 19:
        new_name = random.choice(NAMES)
    else:
        new_name = petname.generate()
    full_name = "%06d-%s" % (model_num, new_name)
    return full_name 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:11,代码来源:shipname.py

示例15: get_inference_input

# 需要导入模块: import go [as 别名]
# 或者: from go import N [as 别名]
def get_inference_input():
    """Set up placeholders for input features/labels.

    Returns the feature, output tensors that get passed into model_fn."""
    return (tf.placeholder(tf.float32,
                           [None, go.N, go.N, features.NEW_FEATURES_PLANES],
                           name='pos_tensor'),
            {'pi_tensor': tf.placeholder(tf.float32, [None, go.N * go.N + 1]),
             'value_tensor': tf.placeholder(tf.float32, [None])}) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:11,代码来源:dual_net.py


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