예제 #1
0
"""Classes and functions related to dataset generation for learning Q
functions.  Datasets in this sense are mappings from board positions
(represented as flattened arrays of tile numbers) to score values.
"""

import argparse
import sys

import numpy as np

from game.common import *
from game.board import Board
from game.game import Game

EXAMPLE_WIDTH = Board.vector_width()
MAX_BATCH_SIZE = 4096  # numpy arrays get slow to update beyond this size.

class Dataset(object):
    """A set of training data (held as matrices whose rows are examples) and a
    column vector of the example scores.."""

    def __init__(self):
        """Creates a new empty dataset."""
        self._num_examples = 0
        self._example_batches = [np.zeros((0, EXAMPLE_WIDTH))]
        self._score_batches = [np.zeros((0, 1))]

    def add_game(self, player_strategy, rnd, starting_game_position=None):
        """Runs a game with the given strategy and randomness source, then
        enrolls the outcome in the dataset.
예제 #2
0
 def test_encoding(self):
     board = self.realistic_board
     encoding = board.as_vector()
     self.assertEqual(encoding.size, Board.vector_width())
     decoding = Board.from_vector(encoding)
     self.assertEqual(board, decoding)