class RosenbrockTestCase(unittest.TestCase): def setUp(self): benchmark = benchmarks.Rosenbrock() self.model = Model(algorithm='PSO') self.model.configuration.terminator = inspyred.ec.terminators.generation_termination x = Variable('x', lb=0, ub=2) y = Variable('y', lb=0, ub=2) rosenbrock_obj = Objective((1 - x) ** 2 + 100 * (y - y ** 2) ** 2, name="Rosenbrock function", direction='min') self.model.objective = rosenbrock_obj def test_evolutionary_strategy(self): self.model.configuration.max_generations = 100 self.model.configuration.terminator = inspyred.ec.terminators.generation_termination self.model.configuration.observer = my_observer self.model.configuration.selector = inspyred.ec.selectors.tournament_selection final_pop = self.model.optimize() best = max(final_pop) self.assertAlmostEqual(best.fitness, 0) def test_pso(self): self.model.algorithm = 'PSO' self.model.configuration.max_generations = 100 final_pop = self.model.optimize() best = max(final_pop) self.assertAlmostEqual(best.fitness, 0)
class RosenbrockTestCase(unittest.TestCase): def setUp(self): self.model = Model(algorithm='PSO') self.model.configuration.terminator = inspyred.ec.terminators.generation_termination x = Variable('x', lb=0, ub=2) y = Variable('y', lb=0, ub=2) rosenbrock_obj = Objective((1 - x)**2 + 100 * (y - y**2)**2, name="Rosenbrock function", direction='min') self.model.objective = rosenbrock_obj def test_evolutionary_strategy(self): self.model.configuration.max_generations = 100 self.model.configuration.terminator = inspyred.ec.terminators.generation_termination self.model.configuration.observer = my_observer self.model.configuration.selector = inspyred.ec.selectors.tournament_selection final_pop = self.model.optimize() best = max(final_pop) self.assertAlmostEqual(best.fitness, 0) def test_pso(self): self.model.algorithm = 'PSO' self.model.configuration.max_generations = 100 final_pop = self.model.optimize() best = max(final_pop) self.assertAlmostEqual(best.fitness, 0)
def setUp(self): self.model = Model(algorithm='PSO') self.model.configuration.terminator = inspyred.ec.terminators.generation_termination x = Variable('x', lb=0, ub=2) y = Variable('y', lb=0, ub=2) rosenbrock_obj = Objective((1 - x)**2 + 100 * (y - y**2)**2, name="Rosenbrock function", direction='min') self.model.objective = rosenbrock_obj
def setUp(self): benchmark = benchmarks.Rosenbrock() self.model = Model(algorithm='PSO') self.model.configuration.terminator = inspyred.ec.terminators.generation_termination x = Variable('x', lb=0, ub=2) y = Variable('y', lb=0, ub=2) rosenbrock_obj = Objective((1 - x) ** 2 + 100 * (y - y ** 2) ** 2, name="Rosenbrock function", direction='min') self.model.objective = rosenbrock_obj