Пример #1
0
def check_add_connection(genome_type, feed_forward):
    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()
        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)))
Пример #2
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)
Пример #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)
Пример #4
0
    return pop.statistics, out
    # return winner.fitness, out


def evolve_cppn(config, pattern, generations):
    return evolve(config, express_cppn, pattern, generations)


def evolve_recurrent_cppn(config, pattern, max_steps, generations):
    def eval_func(net, w, h):
        return express_recurrent_cppn(net, w, h, max_steps)

    return evolve(config, eval_func, pattern, generations)


if __name__ == '__main__':
    import numpy as np
    from neat.config import Config  # Python neat library
    from neat import nn
    import patterns
    target = patterns.checkerboard(16, 16, 4)
    config = Config('config.txt')
    config.pop_size = 50

    config.hidden_nodes = 0
    config.initial_connection = 'fully_connected'

    config.input_nodes = 7
    evolve_recurrent_cppn(config, target, 16, 50)