def test_crossover(self): genome1 = Genome(self.genome_params) genome2 = Genome(self.genome_params) genome1.connect() genome2.connect() genome1.fitness = 5 genome2.fitness = 20 genome2.mutate() assert len(genome2.nodes) == 4 assert len(genome2.connection_genes) == 4 assert genome2.connection_genes[3].innovation_number == 4 disabled_gene = None for idx, cg in enumerate(genome2.connection_genes): if not cg.enabled: disabled_gene = idx break child = genome2.crossover(genome1, genome2) # child inherited fittest parent nodes assert len(child.nodes) == len(genome2.nodes) # should be of same length despite some being disjoint genes assert len(child.connection_genes) == len(genome2.connection_genes) # check child got disabled gene transferred assert not child.connection_genes[disabled_gene].enabled
pool = Pool(processes=N_PROCESSES, initializer=process_initialization, initargs=(config.dataset, True)) for genome in genomes: logger.debug(f'Genome {genome.key}: {genome.get_graph()}') # x = torch.zeros(2, 784).float() # y = torch.zeros(2).long() # x=dataset.x.clone().detach() # y=dataset.y.clone().detach() loss = get_loss('classification') beta_type = 'other' problem_type = 'classification' batch_size = 100000 n_samples = 20 is_gpu = False x = (genome.copy(), # x, y, loss, beta_type, problem_type, batch_size, n_samples, is_gpu) tasks.append(x) # TODO: fix logging when using multiprocessing. Easy fix is to disable fitnesses = list(pool.imap(evaluate_genome_parallel, tasks, chunksize=max([len(genomes)//N_PROCESSES, 1]))) pool.close() for i, genome in enumerate(genomes): print(fitnesses[i]) genome.fitness = fitnesses[i] print('finished')