Esempio n. 1
0
 def test_optimizer_1dim_brent_0(self):
     fct = self._init_polynom()
     opt = Optimizer1Dim(minimize_algorithm=brent)
     result = []
     result.append(opt.optimize(fct, Constraint(0.0, 2.0), 1.0))
     result.append(opt.optimize(fct, Constraint(0.0, 2.7), 1.0))
     result.append(opt.optimize(fct, Constraint(0.0, 4.2), 1.0))
     benchmark = []
     benchmark.append(OptimizerResult.create_succesful(1.07728364364, -6.07916570029, 32))
     benchmark.append(OptimizerResult.create_succesful(1.07728363789, -6.07916570029, 40))
     benchmark.append(OptimizerResult.create_succesful(1.07728363067, -6.07916570029, 50))
     for i in xrange(3):
         self._assert_optimizer_results(benchmark[i], result[i], 7)
Esempio n. 2
0
    def test_optimizer_1dim_golden_0(self):
        fct = self._init_polynom()
        opt = Optimizer1Dim(minimize_algorithm=golden)
        result = []
        result.append(opt.optimize(fct, Constraint(0.0, 2.0), 1.0))
        result.append(opt.optimize(fct, Constraint(0.0, 2.7), 1.0))
        result.append(opt.optimize(fct, Constraint(0.0, 4.2), 1.0))

        benchmark = []
        benchmark.append(OptimizerResult.create_succesful(1.0, -6.0, 6))
        benchmark.append(OptimizerResult.create_succesful(1.0, -6.0, 80))
        benchmark.append(OptimizerResult.create_succesful(1.0, -6.0, 80))
        for i in xrange(3):
            self._assert_optimizer_results(benchmark[i], result[i])
Esempio n. 3
0
 def test_optimizer_1dim_brent_2(self):
     fct = lambda x: x * (x - PI) * (x - PI)
     constraint = Constraint(0.0, 5.0)
     opt = Optimizer1Dim(minimize_algorithm=brent)
     result = opt.optimize(fct, constraint, 1.0)
     benchmark = OptimizerResult.create_succesful(3.14159265057, 2.87208663251e-17, 43)
     self._assert_optimizer_results(benchmark, result)
Esempio n. 4
0
 def test_minimum_bracketing_scaled(self):
     constraint = Constraint(0.0, 5.0)
     t = TangentsTransformation(constraint)
     p = self._init_polynom()
     fct = CompositionFct(p, t)
     result = mn_brak(0.1, 1.0, fct)
     benchmark = (0.1, 1.0, 1.556230591, 46343.60499652936, -8.949238582537712, 1.3006670200315953)
     self._assertEqual(benchmark, result, 7)
Esempio n. 5
0
 def test_tangents_tangents_invers_transformation(self):
     constraint = Constraint(-30.0, 1002.0)
     t = TangentsTransformation(constraint)
     tinv = TangentsInverseTransformation(constraint)
     values = [-4.2, -2.03, -1.0, 0.0, 1.0, 2.3, 4.5, 1001.01]
     for x in values:
         z = tinv(t(x))
         self.assertAlmostEqual(x, z, 8)
Esempio n. 6
0
 def test_minimize_algorithm_1dim_brent_scaled(self):
     constraint = Constraint(0.0, 4.0)
     t = TangentsTransformation(constraint)
     tinv = TangentsInverseTransformation(constraint)
     p = self._init_polynom()
     fct = CompositionFct(p, tinv)
     result_scaled = brent(fct, t(0.1), t(1.0), t(3.9))
     benchmark_rescaled = (-0.8854173749579757, -6.079165700291461)
     result = (tinv(result_scaled[0]), result_scaled[1])
     benchmark = (1.0772836393669956, -6.079165700291461)
     self._assertEqual(benchmark_rescaled, result_scaled)
     self._assertEqual(benchmark, result)
Esempio n. 7
0
 def test_optimizer_1dim_brent_1(self):
     fct = self._init_polynom()
     opt = Optimizer1Dim(minimize_algorithm=brent)
     result = opt.optimize(fct, Constraint(-10.0, -2.0), 1.0)
     benchmark = OptimizerResult.create_succesful(-3.70107061641, -74.1359364077, 40)
     self._assert_optimizer_results(benchmark, result)