예제 #1
0
 def test_genomes03(self):
     """> Test the distance and internal representations of the two given nodes."""
     # Folder must be root to load in make_net properly
     if os.getcwd().split('\\')[-1] == 'tests': os.chdir('..')
     
     # Fetch the used genomes
     cfg = get_config()
     genomes = dict()
     genomes[0] = get_deep_genome0(cfg)
     genomes[3] = get_deep_genome3(cfg)
     
     # Setup an initial genome-cache
     cache = GenomeDistanceCache(cfg.genome)
     cache.warm_up(genomes)
     
     # Get the genome-distance
     result = cache(genome0=genomes[0], genome1=genomes[3])
     self.assertGreater(result, 0)
     
     # Calculation:
     #  2 disjoint nodes
     #  4 identical nodes (outputs)
     #  5 disjoint connections (1 completely removed, 2x2 others connected to different genes)
     #  4 identical connections
     node_distance = (2 * cfg.genome.compatibility_disjoint_node + 4 * 0) / 5
     conn_distance = (5 * cfg.genome.compatibility_disjoint_conn + 4 * 0) / 6
     self.assertEqual(result, node_distance + conn_distance)
     
     # Check if all different representations
     self.assertEqual(cache.node_cache.index_map[5], cache.node_cache.index_map[14])
     self.assertEqual(cache.node_cache.index_map[6], cache.node_cache.index_map[15])
     self.assertNotEqual(cache.node_cache.index_map[7], cache.node_cache.index_map[16])
예제 #2
0
 def test_genomes01(self):
     """> Test the distance and internal representations of the two given nodes."""
     # Folder must be root to load in make_net properly
     if os.getcwd().split('\\')[-1] == 'tests': os.chdir('..')
     
     # Fetch the used genomes
     cfg = get_config()
     genomes = dict()
     genomes[0] = get_deep_genome0(cfg)
     genomes[1] = get_deep_genome1(cfg)
     
     # Setup an initial genome-cache
     cache = GenomeDistanceCache(cfg.genome)
     cache.warm_up(genomes)
     
     # Get the genome-distance
     result = cache(genome0=genomes[0], genome1=genomes[1])
     self.assertGreater(result, 0)
     
     # Calculation:
     #  6 disjoint nodes
     #  2 identical nodes (outputs)
     #  9 disjoint connections
     #  1 identical connection
     node_distance = (6 * cfg.genome.compatibility_disjoint_node + 2 * 0) / 5
     conn_distance = (9 * cfg.genome.compatibility_disjoint_conn + 1 * 0) / 6
     self.assertEqual(result, node_distance + conn_distance)
     
     # Check if all different representations
     self.assertNotEqual(cache.node_cache.index_map[5], cache.node_cache.index_map[8])
     self.assertNotEqual(cache.node_cache.index_map[6], cache.node_cache.index_map[9])
     self.assertNotEqual(cache.node_cache.index_map[7], cache.node_cache.index_map[10])
예제 #3
0
 def test_distance(self):
     """> Test if the distance holds for two completely different genomes."""
     # Folder must be root to load in make_net properly
     if os.getcwd().split('\\')[-1] == 'tests': os.chdir('..')
     
     # Fetch the used genomes
     cfg = get_config()
     genomes = dict()
     genomes[0] = get_genome0(cfg)
     genomes[3] = get_genome3(cfg)
     
     # Setup an initial genome-cache
     cache = GenomeDistanceCache(cfg.genome)
     cache.warm_up(genomes)
     
     # Get the genome-distance
     result = cache(genome0=genomes[0], genome1=genomes[3])
     self.assertGreater(result, 0)
     
     # Calculation:
     #  2 disjoint nodes
     #  2 identical nodes (outputs)
     #  5 disjoint connections (1 completely removed, 2x2 others connected to different genes)
     #  1 identical connection
     node_distance = (2 * cfg.genome.compatibility_disjoint_node + 2 * 0) / 3
     conn_distance = (5 * cfg.genome.compatibility_disjoint_conn + 1 * 0) / 4
     self.assertEqual(result, node_distance + conn_distance)
예제 #4
0
 def test_zero_distance(self):
     """> Test if False is returned when comparing nodes of different type."""
     # Folder must be root to load in make_net properly
     if os.getcwd().split('\\')[-1] == 'tests': os.chdir('..')
     
     # Fetch the used genomes (each type of genome twice)
     cfg = get_config()
     genomes = dict()
     genomes[0] = get_genome0(cfg)
     genomes[1] = get_genome0(cfg)
     genomes[1].key = 1  # Update
     genomes[2] = get_genome1(cfg)
     genomes[3] = get_genome1(cfg)
     genomes[3].key = 3  # Update
     genomes[4] = get_genome2(cfg)
     genomes[5] = get_genome2(cfg)
     genomes[5].key = 5  # Update
     
     # Setup an initial genome-cache
     cache = GenomeDistanceCache(cfg.genome)
     cache.warm_up(genomes)
     
     # Get the genome-distance
     self.assertEqual(cache(genome0=genomes[0], genome1=genomes[1]), 0)
     self.assertEqual(cache(genome0=genomes[2], genome1=genomes[3]), 0)
     self.assertEqual(cache(genome0=genomes[4], genome1=genomes[5]), 0)
예제 #5
0
 def test_same_internal_representation(self):
     """> Test if the merged hidden nodes have the same internal representation."""
     # Folder must be root to load in make_net properly
     if os.getcwd().split('\\')[-1] == 'tests': os.chdir('..')
     
     # Fetch the used genomes
     cfg = get_config()
     genomes = dict()
     genomes[0] = get_genome0(cfg)
     genomes[1] = get_genome1(cfg)
     
     # Setup an initial genome-cache
     cache = GenomeDistanceCache(cfg.genome)
     cache.warm_up(genomes)
     
     # Hidden nodes with keys 2 and 3 should have the same internal representation since they represent the same node
     self.assertEqual(cache.node_cache.index_map[2], cache.node_cache.index_map[3])
예제 #6
0
 def test_distance_similar_genome(self):
     """> Test if two different genomes with exact same architecture have zero distance."""
     # Folder must be root to load in make_net properly
     if os.getcwd().split('\\')[-1] == 'tests': os.chdir('..')
     
     # Fetch the used genomes
     cfg = get_config()
     genomes = dict()
     genomes[0] = get_genome0(cfg)
     genomes[1] = get_genome1(cfg)
     
     # Setup an initial genome-cache
     cache = GenomeDistanceCache(cfg.genome)
     cache.warm_up(genomes)
     
     # Get the genome-distance
     self.assertEqual(cache(genome0=genomes[0], genome1=genomes[1]), 0)