示例#1
0
def load_and_train(epochs=50, vectorlength=16):
    # Set up logging
    dictConfig(LOG_CONFIG)
    games = Games()

    # Use the following to load already parsed data
    games.load()
    games.flatten(vectorlength=vectorlength)

    # Network structure
    # Structure: [input_layer, hidden_layer, hidden_layer ... , output_layer]
    # Example: [784, 620, 100, 10]
    layer_structure = [vectorlength, 192, 128, 96, 4]
    # Example: [rectify, rectify, softmax]
    activation_functions = [rectify, rectify, rectify, rectify, softmax]
    # Remeber to change num_labels to 4, since we have Up, Right, Down, Left
    # Also we normalize the values. Don't know if it will affect anything,
    # but not taking any chances.
    cfg = {
        'learning_rate': 0.00001,
        'num_labels': 4,
        'training_batch_size': 512,
    }

    # Create a network using the default parameters
    net = ANN(layer_structure, activation_functions, config=cfg)
    net.load_input_data(normalize=False, module6_file=True)

    net.train(epochs=epochs, include_test_set=False)

    return net
示例#2
0
def load_raw_and_save(alternate=False, num_games=16, only_successful=False, vectorlength=16):
    """
    Loads raw data from game_data.txt, parses, transforms to alternate repr if set to True,
    then flattens the data, and pickles and saves the data to disk.
    """

    games = Games()

    # Use the following to parse 512 games from scratch, that have at least reached 2048,
    # then add an additional filter of min_maxtile 4096, flatten to Nx16 np.ndArray and gzip pickle

    games.parse_from_raw_game_data(num_games=num_games, only_successful=only_successful)
    if alternate:
        games.transform_to_alternate_representation()
    boards, labels = games.flatten(vectorlength=vectorlength)
    print('Total labels: %d' % len(labels))
    print('Total board states: %d' % len(boards))
    games.save()