def tst_algo(opt, fcn, name, num): def func_wrapper(arg): return fcn(arg)[0] x0, xmin, xmax, fmin = _tstoptfct.init(name, num) result = opt(func_wrapper, x0, xmin, xmax) opt_name = opt.__class__.__name__ print(opt_name, result[2], '=', result[1], 'in', result[0], 'nfevs')
def test_watson(self): name = 'watson' npar = 6 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst( optfcts.neldermead, name + self.nm, _tstoptfct.watson, fmin, x0, xmin, xmax ) self.tst( optfcts.montecarlo, name + self.mc, _tstoptfct.watson, fmin, x0, xmin, xmax )
def test_wood(self): name = 'wood' npar = 4 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst( optfcts.neldermead, name + self.nm, _tstoptfct.wood, fmin, x0, xmin, xmax ) self.tst( optfcts.montecarlo, name + self.mc, _tstoptfct.wood, fmin, x0, xmin, xmax )
def test_trigonometric(self): name = 'trigonometric' npar = 9 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst( optfcts.neldermead, name + self.nm, _tstoptfct.trigonometric, fmin, x0, xmin, xmax ) self.tst( optfcts.montecarlo, name + self.mc, _tstoptfct.trigonometric, fmin, x0, xmin, xmax )
def test_powell_badly_scaled(self): name = 'powell_badly_scaled' npar = 2 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst( optfcts.neldermead, name + self.nm, _tstoptfct.powell_badly_scaled, fmin, x0, xmin, xmax ) self.tst( optfcts.montecarlo, name + self.mc, _tstoptfct.powell_badly_scaled, fmin, x0, xmin, xmax )
def test_biggs(self): name = 'biggs' npar = 6 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) #self.tst( optfcts.neldermead, name + self.nm, _tstoptfct.biggs_fct, # fmin, x0, xmin, xmax ) self.tst( optfcts.lmdif, name + self.lm, _tstoptfct.biggs, fmin, x0, xmin, xmax )
def test_discrete_integral(self): name = 'discrete_integral' npar = 5 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.discrete_integral, fmin, x0, xmin, xmax )
def test_discrete_boundary(self): name = 'discrete_boundary' npar = 5 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.discrete_boundary, fmin, x0, xmin, xmax )
def test_helical_valley(self): name = 'helical_valley' npar = 3 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.helical_valley, fmin, x0, xmin, xmax )
def test_chebyquad(self): name = 'chebyquad' npar = 11 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.chebyquad, fmin, x0, xmin, xmax )
def test_linear_fullrank1(self): name = 'linear_fullrank1' npar = 15 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.linear_fullrank1, fmin, x0, xmin, xmax )
def test_brown_dennis(self): name = 'brown_dennis' npar = 4 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.brown_dennis, fmin, x0, xmin, xmax )
def test_kowalik_osborne(self): name = 'kowalik_osborne' npar = 4 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.kowalik_osborne, fmin, x0, xmin, xmax )
def test_box3d(self): name = 'box3d' npar = 3 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.box3d, fmin, x0, xmin, xmax )
def test_gulf_research_development(self): name = 'gulf_research_development' npar = 3 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.gulf_research_development, fmin, x0, xmin, xmax )
def test_gaussian(self): name = 'gaussian' npar = 3 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst( optfcts.lmdif, name + self.lm, _tstoptfct.gaussian, fmin, x0, xmin, xmax )
def test_broyden_tridiagonal(self): name = 'broyden_tridiagonal' npar = 16 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.broyden_tridiagonal, fmin, x0, xmin, xmax )
def test_broyden_banded(self): name = 'broyden_banded' npar = 18 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.broyden_banded, fmin, x0, xmin, xmax )
def test_osborne2(self): name = 'osborne2' npar = 11 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.osborne2, fmin, x0, xmin, xmax )
def test_linear_fullrank0cols0rows(self): name = 'linear_fullrank0cols0rows' npar = 13 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.linear_fullrank0cols0rows, fmin, x0, xmin, xmax )
def test_beale(self): name = 'beale' npar = 2 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name,_tstoptfct.beale, fmin, x0, xmin, xmax )
def test_rosenbrock(self): name = 'rosenbrock' npar = 4 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.rosenbrock, fmin, x0, xmin, xmax )
def tst_unc_opt(algorithms, npar): """ More, J.J., Garbow, B.S. and Hillstrom, K.E., Testing Unconstrained Optimization Software, ACM Trans. Math. Software 7 (1981), 17-41. """ from sherpa.optmethods import _tstoptfct def tst_algo(opt, fcn, name, num): def func_wrapper(arg): return fcn(arg)[0] x0, xmin, xmax, fmin = _tstoptfct.init(name, num) result = opt(func_wrapper, x0, xmin, xmax) opt_name = opt.__class__.__name__ print(opt_name, result[2], '=', result[1], 'in', result[0], 'nfevs') def rosenbrock(name, opt): tst_algo(opt, _tstoptfct.rosenbrock, name, npar) name = 'rosenbrock' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: rosenbrock(name, algo) def freudenstein_roth(name, opt): tst_algo(opt, _tstoptfct.freudenstein_roth, name, npar) name = 'freudenstein_roth' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: freudenstein_roth(name, algo) def powell_badly_scaled(name, opt): tst_algo(opt, _tstoptfct.powell_badly_scaled, name, npar) name = 'powell_badly_scaled' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: powell_badly_scaled(name, algo) def brown_badly_scaled(name, opt): tst_algo(opt, _tstoptfct.brown_badly_scaled, name, npar) name = 'brown_badly_scaled' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: brown_badly_scaled(name, algo) def beale(name, opt): tst_algo(opt, _tstoptfct.beale, name, npar) name = 'beale' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: beale(name, algo) def jennrich_sampson(name, opt): tst_algo(opt, _tstoptfct.jennrich_sampson, name, npar) name = 'jennrich_sampson' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: jennrich_sampson(name, algo) def helical_valley(name, opt): tst_algo(opt, _tstoptfct.helical_valley, name, 3) name = 'helical_valley' x0, xmin, xmax, fmin = _tstoptfct.init(name, 3) print('\n', name, ' fmin =', fmin) for algo in algorithms: helical_valley(name, algo) def bard(name, opt): tst_algo(opt, _tstoptfct.bard, name, 3 * npar) name = 'bard' x0, xmin, xmax, fmin = _tstoptfct.init(name, 3 * npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: bard(name, algo) def gaussian(name, opt): tst_algo(opt, _tstoptfct.gaussian, name, 3) name = 'gaussian' x0, xmin, xmax, fmin = _tstoptfct.init(name, 3) print('\n', name, ' fmin =', fmin) for algo in algorithms: gaussian(name, algo) def meyer(name, opt): tst_algo(opt, _tstoptfct.meyer, name, 3) name = 'meyer' x0, xmin, xmax, fmin = _tstoptfct.init(name, 3) print('\n', name, ' fmin =', fmin) for algo in algorithms: meyer(name, algo) def gulf_research_development(name, opt): tst_algo(opt, _tstoptfct.gulf_research_development, name, 3) name = 'gulf_research_development' x0, xmin, xmax, fmin = _tstoptfct.init(name, 3) print('\n', name, ' fmin =', fmin) for algo in algorithms: gulf_research_development(name, algo) def box3d(name, opt): tst_algo(opt, _tstoptfct.box3d, name, 3) name = 'box3d' x0, xmin, xmax, fmin = _tstoptfct.init(name, 3) print('\n', name, ' fmin =', fmin) for algo in algorithms: box3d(name, algo) def powell_singular(name, opt): tst_algo(opt, _tstoptfct.powell_singular, name, 4 * npar) name = 'powell_singular' x0, xmin, xmax, fmin = _tstoptfct.init(name, 4 * npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: powell_singular(name, algo) def wood(name, opt): tst_algo(opt, _tstoptfct.wood, name, 4 * npar) name = 'wood' x0, xmin, xmax, fmin = _tstoptfct.init(name, 4 * npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: wood(name, algo) def kowalik_osborne(name, opt): tst_algo(opt, _tstoptfct.kowalik_osborne, name, 4) name = 'kowalik_osborne' x0, xmin, xmax, fmin = _tstoptfct.init(name, 4) print('\n', name, ' fmin =', fmin) for algo in algorithms: kowalik_osborne(name, algo) def brown_dennis(name, opt): tst_algo(opt, _tstoptfct.brown_dennis, name, 4) name = 'brown_dennis' x0, xmin, xmax, fmin = _tstoptfct.init(name, 4) print('\n', name, ' fmin =', fmin) for algo in algorithms: brown_dennis(name, algo) def osborne1(name, opt): tst_algo(opt, _tstoptfct.osborne1, name, 5) name = 'osborne1' x0, xmin, xmax, fmin = _tstoptfct.init(name, 5) print('\n', name, ' fmin =', fmin) for algo in algorithms: osborne1(name, algo) def biggs(name, opt): tst_algo(opt, _tstoptfct.biggs, name, 6) name = 'biggs' x0, xmin, xmax, fmin = _tstoptfct.init(name, 6) print('\n', name, ' fmin =', fmin) for algo in algorithms: if algo.__class__.__name__ == 'Midnight': print('Minuit aborts skip test') continue biggs(name, algo) def osborne2(name, opt): tst_algo(opt, _tstoptfct.osborne2, name, 11) name = 'osborne2' x0, xmin, xmax, fmin = _tstoptfct.init(name, 11) print('\n', name, ' fmin =', fmin) for algo in algorithms: osborne2(name, algo) def watson(name, opt): tst_algo(opt, _tstoptfct.watson, name, 6) name = 'watson' x0, xmin, xmax, fmin = _tstoptfct.init(name, 6) print('\n', name, ' fmin =', fmin) for algo in algorithms: watson(name, algo) def penaltyI(name, opt): tst_algo(opt, _tstoptfct.penaltyI, name, 4) name = 'penaltyI' x0, xmin, xmax, fmin = _tstoptfct.init(name, 4) print('\n', name, ' fmin =', fmin) for algo in algorithms: penaltyI(name, algo) def penaltyII(name, opt): tst_algo(opt, _tstoptfct.penaltyII, name, 4) name = 'penaltyII' x0, xmin, xmax, fmin = _tstoptfct.init(name, 4) print('\n', name, ' fmin =', fmin) for algo in algorithms: penaltyII(name, algo) def variably_dimensioned(name, opt): tst_algo(opt, _tstoptfct.variably_dimensioned, name, npar) name = 'variably_dimensioned' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: variably_dimensioned(name, algo) def trigonometric(name, opt): tst_algo(opt, _tstoptfct.trigonometric, name, npar) name = 'trigonometric' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: trigonometric(name, algo) def brown_almost_linear(name, opt): tst_algo(opt, _tstoptfct.brown_almost_linear, name, npar) name = 'brown_almost_linear' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: brown_almost_linear(name, algo) def discrete_boundary(name, opt): tst_algo(opt, _tstoptfct.discrete_boundary, name, npar) name = 'discrete_boundary' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: discrete_boundary(name, algo) def discrete_integral(name, opt): tst_algo(opt, _tstoptfct.discrete_integral, name, npar) name = 'discrete_integral' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: discrete_integral(name, algo) def broyden_tridiagonal(name, opt): tst_algo(opt, _tstoptfct.broyden_tridiagonal, name, npar) name = 'broyden_tridiagonal' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: broyden_tridiagonal(name, algo) def broyden_banded(name, opt): tst_algo(opt, _tstoptfct.broyden_banded, name, npar) name = 'broyden_banded' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: broyden_banded(name, algo) def linear_fullrank(name, opt): tst_algo(opt, _tstoptfct.linear_fullrank, name, npar) name = 'linear_fullrank' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: linear_fullrank(name, algo) def linear_fullrank1(name, opt): tst_algo(opt, _tstoptfct.linear_fullrank, name, npar) name = 'linear_fullrank1' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: linear_fullrank1(name, algo) def linear_fullrank0cols0rows(name, opt): tst_algo(opt, _tstoptfct.linear_fullrank0cols0rows, name, npar) name = 'linear_fullrank0cols0rows' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: if algo.__class__.__name__ == 'Midnight': print('Minuit aborts skip test') continue linear_fullrank0cols0rows(name, algo) def chebyquad(name, opt): tst_algo(opt, _tstoptfct.chebyquad, name, npar) name = 'chebyquad' x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) print('\n', name, ' fmin =', fmin) for algo in algorithms: chebyquad(name, algo)
def test_brown_badly_scaled(self): name = 'brown_badly_scaled' npar = 2 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.brown_badly_scaled, fmin, x0, xmin, xmax )
def init(name, npar): x0, xmin, xmax, fmin = _tstoptfct.init(name, npar) return x0, xmin, xmax, fmin
def test_jennrich_sampson(self): name = 'jennrich_sampson' npar = 2 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.jennrich_sampson, fmin, x0, xmin, xmax )
def test_variably_dimensioned(self): name = 'variably_dimensioned' npar = 5 x0, xmin, xmax, fmin = _tstoptfct.init( name, npar ) self.tst_all( name, _tstoptfct.variably_dimensioned, fmin, x0, xmin, xmax )