def testNsgaii(self): pop = [ChromosomeTestImplementation() for i in range(10)] self.assertEqual(3, len(pop[0].genes)) pop = NSGAII.nsgaii(pop, 100) expected = [5.198961969831384, 0.08305567759063237, 5.9249528286171405, -2.292726823088209, 5.9249528286171405, 2.8836408759525156, -2.292726823088209, 5.9249528286171405, 5.198961969831384, 13.01326687754792] actual = [p.x() for p in pop] self.assertEqual(expected, actual) expected = [-14.893629327366531, -14.893629327366531, -4.073355846562075, -14.893629327366531, -10.698973150220933, -14.893629327366531, -14.893629327366531, -4.073355846562075, -14.893629327366531, 1.956945448043296] actual = [p.y() for p in pop] self.assertEqual(expected, actual)
def demonstrate(seed = 42): random.seed(seed) logger = NSGAII.log_file('demonsga.log') pop = [ChromosomeTestImplementation() for i in range(10)] return NSGAII.nsgaii(pop, 100, logger.log)
def evolveMnist(seed = 42): logger = NSGAII.log_file('mnistgenerations.log') pop = chromosome.initialMnistPopulation(40) sys.stdout.flush() result = NSGAII.nsgaii(pop, 100, logger.log) print result