Esempio n. 1
0
def check_add_connection(genome_type, feed_forward):
    indexer = InnovationIndexer(0)
    local_dir = os.path.dirname(__file__)
    config = Config(os.path.join(local_dir, 'test_configuration'))
    config.input_nodes = 3
    config.output_nodes = 4
    config.hidden_nodes = 5
    config.feedforward = feed_forward
    N = config.input_nodes + config.hidden_nodes + config.output_nodes

    connections = {}
    for a in range(100):
        g = genome_type.create_unconnected(a, config)
        g.add_hidden_nodes(config.hidden_nodes)
        for b in range(1000):
            g.mutate_add_connection(indexer)
        for c in g.conn_genes.values():
            connections[c.key] = connections.get(c.key, 0) + 1

    # TODO: The connections should be returned to the caller and checked
    # against the constraints/assumptions particular to the network type.
    for i in range(N):
        values = []
        for j in range(N):
            values.append(connections.get((i, j), 0))
        print("{0:2d}: {1}".format(i, " ".join("{0:3d}".format(x) for x in values)))
def run():
    # load settings file
    local_dir = os.path.dirname(__file__)
    config = Config(os.path.join(local_dir, 'dpole_config'))

    # change the number of inputs accordingly to the type
    # of experiment: markov (6) or non-markov (3)
    # you can also set the configs in dpole_config as long
    # as you have two config files for each type of experiment
    config.input_nodes = 3

    pop = population.Population(config)
    pop.epoch(evaluate_population, 200, report=1, save_best=0)

    winner = pop.most_fit_genomes[-1]

    print('Number of evaluations: {0:d}'.format(winner.ID))
    print('Winner fitness: {0:f}'.format(winner.fitness))

    # save the winner
    with open('winner_chromosome', 'w') as f:
        cPickle.dump(winner, f)

    # Plots the evolution of the best/average fitness
    visualize.plot_stats(pop, ylog=True)
    # Visualizes speciation
    visualize.plot_species(pop)
    # visualize the best topology
    visualize.draw_net(winner, view=True)
Esempio n. 3
0
def run():
    # load settings file
    local_dir = os.path.dirname(__file__)
    config = Config(os.path.join(local_dir, 'dpole_config'))

    # change the number of inputs accordingly to the type
    # of experiment: markov (6) or non-markov (3)
    # you can also set the configs in dpole_config as long
    # as you have two config files for each type of experiment
    config.input_nodes = 3

    pop = population.Population(config)
    pop.epoch(evaluate_population, 200, report=1, save_best=0)

    winner = pop.most_fit_genomes[-1]

    print('Number of evaluations: {0:d}'.format(winner.ID))
    print('Winner fitness: {0:f}'.format(winner.fitness))

    # save the winner
    with open('winner_chromosome', 'w') as f:
        cPickle.dump(winner, f)

    # Plots the evolution of the best/average fitness
    visualize.plot_stats(pop, ylog=True)
    # Visualizes speciation
    visualize.plot_species(pop)
    # visualize the best topology
    visualize.draw_net(winner, view=True)