Exemplo n.º 1
0
 def test_halt_not(self):
     """
     Ensures if the fittest genome has fitness < MAX_REWARD then halt
     doesn't succeed.
     """
     halt = make_halt_function([3, 2, 1])
     g1 = Genome([1, 2, 3])
     g1.fitness = MAX_REWARD - 0.1
     g2 = Genome([1, 2, 3])
     g2.fitness = 3
     g3 = Genome([1, 2, 3])
     g3.fitness = 2
     # Any fittest solution with fitness < MAX_REWARD means no halt.
     population = [g1, g2, g3]
     result = halt(population, 1)
     self.assertFalse(result)
Exemplo n.º 2
0
 def test_halt_not(self):
     """
     Ensures if the fittest genome has fitness < MAX_REWARD then halt
     doesn't succeed.
     """
     halt = make_halt_function([3, 2, 1])
     g1 = Genome([1, 2, 3])
     g1.fitness = MAX_REWARD - 0.1
     g2 = Genome([1, 2, 3])
     g2.fitness = 3
     g3 = Genome([1, 2, 3])
     g3.fitness = 2
     # Any fittest solution with fitness < MAX_REWARD means no halt.
     population = [g1, g2, g3]
     result = halt(population, 1)
     self.assertFalse(result)
Exemplo n.º 3
0
 def test_fitness_function_uses_cached_genome_fitness(self):
     """
     Ensures the fitness function bails if there is already a score set for
     the genome.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     genome.fitness = 12345
     result = fitness_function(genome)
     self.assertEqual(12345, result)
Exemplo n.º 4
0
 def test_fitness_function_uses_cached_genome_fitness(self):
     """
     Ensures the fitness function bails if there is already a score set for
     the genome.
     """
     fitness_function = make_fitness_function(CANTUS_FIRMUS)
     genome = Genome([1, 2, 3])
     genome.fitness = 12345
     result = fitness_function(genome)
     self.assertEqual(12345, result)
Exemplo n.º 5
0
 def test_halt_checks_suspension_count(self):
     """
     If the solution contains suspensions the halt function should ensure
     that the MAX_REWARD is incremented by the number of suspensions
     (rewarded because they're part of a valid step wise motion).
     """
     halt = make_halt_function([9, 8, 7, 6, 5])
     g1 = Genome([11, 10, 9, 8, 7])
     # only one our of two "correct" dissonances
     g1.fitness = MAX_REWARD + REWARD_SUSPENSION
     population = [g1, ]
     result = halt(population, 1)
     self.assertFalse(result)
     # Try again
     # two out of two "correct" dissonances
     g1.fitness = MAX_REWARD + (REWARD_SUSPENSION * 2)
     population = [g1, ]
     result = halt(population, 1)
     self.assertTrue(result)
Exemplo n.º 6
0
 def test_halt_expected(self):
     """
     Ensure the function returns true if we're in a halting state.
     """
     halt = make_halt_function([6, 5])
     g1 = Genome([6, 5])
     g1.fitness = MAX_REWARD
     population = [g1, ]
     result = halt(population, 1)
     self.assertTrue(result)
Exemplo n.º 7
0
 def test_halt_expected(self):
     """
     Ensure the function returns true if we're in a halting state.
     """
     halt = make_halt_function([6, 5])
     g1 = Genome([6, 5])
     g1.fitness = MAX_REWARD
     population = [
         g1,
     ]
     result = halt(population, 1)
     self.assertTrue(result)
Exemplo n.º 8
0
 def test_halt_checks_suspension_count(self):
     """
     If the solution contains suspensions the halt function should ensure
     that the MAX_REWARD is incremented by the number of suspensions
     (rewarded because they're part of a valid step wise motion).
     """
     halt = make_halt_function([9, 8, 7, 6, 5])
     g1 = Genome([11, 10, 9, 8, 7])
     # only one our of two "correct" dissonances
     g1.fitness = MAX_REWARD + REWARD_SUSPENSION
     population = [
         g1,
     ]
     result = halt(population, 1)
     self.assertFalse(result)
     # Try again
     # two out of two "correct" dissonances
     g1.fitness = MAX_REWARD + (REWARD_SUSPENSION * 2)
     population = [
         g1,
     ]
     result = halt(population, 1)
     self.assertTrue(result)