def test_json_generation(self): genome = Genome([[1, 3, 0, True], [1, 4, 0, True], [2, 3, 0, True], [2, 4, 0, True]], 2, 2) genome_from_json = Genome.from_json(genome.to_json()) self.assertEqual(genome.get_connections(), genome_from_json.get_connections()) self.assertEqual(genome.input_size, genome_from_json.input_size) self.assertEqual(genome.output_size, genome_from_json.output_size) self.assertEqual(genome.input_node_ids, genome_from_json.input_node_ids) self.assertEqual(genome.output_node_ids, genome_from_json.output_node_ids)
def test_mutate_for_100_percent_chance_for_weight_mutation(self): # probability for each mutation mutation_coefficients = dict(add_connection=0.0, split_connection=0.0, change_weight=1.0, new_connection_abs_max_weight=5.0, max_weight_mutation=5.0) weight = 0.0 genome = Genome([[1, 2, weight, True]], 1, 1) genome.mutate(mutation_coefficients) # add new connection/node mutation (source_id, dest_id, new_weight, enable) = genome.get_connections()[0] self.assertNotAlmostEqual(weight, new_weight)
def test_mutate_change_weight_for_genome_with_disabled_connection(self): weight = 0.0 genome = Genome([[1, 2, weight, False]], 1, 1) genome._mutate_change_weight(1.0) (source_id, dest_id, new_weight, enable) = genome.get_connections()[0] self.assertAlmostEqual(weight, new_weight)
def test_get_connections(self): genome = Genome([[2, 3, 0, True], [1, 4, 0, True], [1, 3, 0, True], [2, 4, 0, True]], 2, 2) connections = sorted(genome.get_connections()) self.assertEqual(connections, [(1, 3, 0, True), (1, 4, 0, True), (2, 3, 0, True), (2, 4, 0, True)])