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)))
def test_config_options(): # sample fitness function def eval_fitness(population): for individual in population: individual.fitness = 1.0 local_dir = os.path.dirname(__file__) config = Config(os.path.join(local_dir, 'test_configuration')) for hn in (0, 1, 2): config.hidden_nodes = hn for fc in (0, 1): config.fully_connected = fc for act in activation_functions.functions.keys(): config.allowed_activation = [act] for ff in (0, 1): config.feedforward = ff pop = Population(config) pop.run(eval_fitness, 250)
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)