sigma = 1e6,
            )
    basis_NB = specmine.spectral.laplacian_basis(affinity_NN, k = 32)
    feature_map = \
        specmine.discovery.InterpolationFeatureMap(
            basis_NB,
            avectors_ND,
            specmine.go.board_to_affinity,
            )
    rows = [["eigenvector", "x", "y", "value"]]

    for x in xrange(9):
        for y in xrange(9):
            grid = numpy.zeros((9, 9), numpy.int8)

            grid[x, y] = 1

            features = feature_map[specmine.go.BoardState(grid)]

            for i in xrange(features.shape[0]):
                rows.append([i, x, y, features[i]])

    with specmine.util.openz(out_path, "wb") as out_file:
        writer = csv.writer(out_file)

        writer.writerows(rows)

if __name__ == "__main__":
    specmine.script(main)

Esempio n. 2
0
        # randomly sample subset
        value_dict = dict(shuffled_values[:samples])

        test_samples = 20000
        if off_graph:
            test_values = dict(shuffled_values[-test_samples:])
        else: 
            test_values = dict(shuffled_values[:test_samples])

        logger.info("kept %i board samples", len(value_dict))

        avectors_ND = numpy.array(map(specmine.go.board_to_affinity, value_dict))

        #for B in numpy.r_[1:200:8j].round().astype(int):
        for B in [200]:
            yield (run_graph_features, ["affinity", B, avectors_ND, test_values])

    with open(out_path, "wb") as out_file:
        writer = csv.writer(out_file)

        writer.writerow(["map_name", "features", "score_mean", "score_variance"])

        for (_, row) in condor.do(yield_jobs(), workers):
            writer.writerow(row)

            out_file.flush()

if __name__ == "__main__":
    specmine.script(main)
 
Esempio n. 3
0
# TODO move to tools/util
def get_value_list(games_path,values_path):
    ''' takes a list of games and a dictionary of values and builds a list of
    (BoardState, value) pairs '''

    with specmine.util.openz(games_path) as games_file:
        games = pickle.load(games_file)

    with specmine.util.openz(values_path) as values_file:
        values = pickle.load(values_file)

    value_list = []

    for game in values.keys():
        try:
            vals = values[game]
            boards = map(specmine.go.BoardState, games[game].grids)
            value_list.extend(zip(boards,vals))
        except KeyError:
            print 'game unkown for ',game

    # remove duplicates
    value_dict = dict(value_list) 
    value_keys = value_dict.keys()
    value_list = zip(value_keys,map(value_dict.__getitem__,value_keys))

    return value_list

if __name__ == "__main__":
    specmine.script(measure_feature_performance)
            avectors_ND = numpy.array(map(specmine.go.board_to_affinity, boards))
            affinity_NN = specmine.discovery.affinity_graph(avectors_ND, neighbors, sigma = 1e6)

            for B in numpy.r_[0:250:10j].round().astype(int):
                if interpolate:
                    yield (run_template_features, [2, 2, B, test_values])
                    #yield (run_template_features, [2, 3, B, test_values])
                    yield (run_template_features, [3, 3, B, test_values])
                    yield (run_random_features, [B, avectors_ND, index, test_values, interpolate], dict(aff_map = affinity_map))
                    yield (run_laplacian_features, ["Laplacian",B,avectors_ND, affinity_NN, index, test_values, interpolate], dict(aff_map = affinity_map))
                else:
                    yield (run_template_features, [2, 2, B, test_values])
                    #yield (run_template_features, [2, 3, B, test_values])
                    yield (run_template_features, [3, 3, B, test_values])
                    yield (run_random_features, [B, avectors_ND, index, test_values, interpolate])
                    yield (run_laplacian_features, ["Laplacian",B,avectors_ND, affinity_NN, index, test_values, interpolate])


    with open(out_path, "wb") as out_file:
        writer = csv.writer(out_file)

        writer.writerow(["map_name", "features", "samples", "score_mean", "score_variance"])

        for (_, row) in condor.do(yield_jobs(), workers):
            writer.writerow(row)

if __name__ == "__main__":
    specmine.script(flat_affinity_test)
    #specmine.script(clustered_affinity_test)