def test_3_2_disp_sobol(self): """Iterative sampling on TestFunction 1 and 2 (multi and univariate)""" def callback_func(x): print("Local minimization callback test") for test in [test1_1, test2_1]: res = shgo(test.f, test.bounds, iters=1, sampling_method='sobol', callback=callback_func, options={'disp': True}) res = shgo(test.f, test.bounds, n=1, sampling_method='simplicial', callback=callback_func, options={'disp': True})
def run_test(test, args=(), test_atol=1e-5, n=100, iters=None, callback=None, minimizer_kwargs=None, options=None, sampling_method='sobol'): res = shgo(test.f, test.bounds, args=args, constraints=test.cons, n=n, iters=iters, callback=callback, minimizer_kwargs=minimizer_kwargs, options=options, sampling_method=sampling_method) logging.info(res) if test.expected_x is not None: numpy.testing.assert_allclose(res.x, test.expected_x, rtol=test_atol, atol=test_atol) # (Optional tests) if test.expected_fun is not None: numpy.testing.assert_allclose(res.fun, test.expected_fun, atol=test_atol) if test.expected_xl is not None: numpy.testing.assert_allclose(res.xl, test.expected_xl, atol=test_atol) if test.expected_funl is not None: numpy.testing.assert_allclose(res.funl, test.expected_funl, atol=test_atol) return
def test_3_2_no_min_pool_simplicial(self): """Check that the routine stops when no minimiser is found after maximum specified sampling evaluations""" options = {'maxev': 10, 'disp': True} res = shgo(test_table.f, test_table.bounds, n=3, options=options, sampling_method='simplicial') numpy.testing.assert_equal(False, res.success)
def test_1_maxiter(self): """Test failure on insufficient iterations""" options = {'maxiter': 2} res = shgo(test4_1.f, test4_1.bounds, n=2, iters=None, options=options, sampling_method='sobol') numpy.testing.assert_equal(False, res.success) numpy.testing.assert_equal(4, res.nfev)
def test_6_2_simplicial_min_iter(self): """Test that maximum iteration option works on TestFunction 3""" options = {'min_iter': 2} res = shgo(test3_1.f, test3_1.bounds, constraints=test3_1.cons, options=options, sampling_method='simplicial') numpy.testing.assert_allclose(res.x, test3_1.expected_x, rtol=1e-5, atol=1e-5) numpy.testing.assert_allclose(res.fun, test3_1.expected_fun, atol=1e-5)
def test_2_2_sobol_iter(self): """Iterative Sobol sampling on TestFunction 2 (univariate)""" res = shgo(test2_1.f, test2_1.bounds, constraints=test2_1.cons, n=None, iters=1, sampling_method='sobol') numpy.testing.assert_allclose(res.x, test2_1.expected_x, rtol=1e-5, atol=1e-5) numpy.testing.assert_allclose(res.fun, test2_1.expected_fun, atol=1e-5)
def test_5_2_infeasible_simplicial(self): """Ensures the algorithm terminates on infeasible problems after maxev is exceeded.""" options = {'maxev': 1000, 'disp': False} res = shgo(test_infeasible.f, test_infeasible.bounds, constraints=test_infeasible.cons, n=100, options=options, sampling_method='simplicial') numpy.testing.assert_equal(False, res.success)
def test_4_4_known_f_min(self): """Test Global mode limiting local evalutions for 1D funcs""" options = { # Specify known function value 'f_min': test2_1.expected_fun, 'f_tol': 1e-6, # Specify number of local iterations to perform+ 'minimize_every_iter': True, 'local_iter': 1, 'infty_constraints': False} res = shgo(test2_1.f, test2_1.bounds, constraints=test2_1.cons, n=None, iters=None, options=options, sampling_method='sobol') numpy.testing.assert_allclose(res.x, test2_1.expected_x, rtol=1e-5, atol=1e-5)
def test_12_sobol_inf_cons(self): """Test to cover the case where f_lowest == 0""" options = {'maxtime': 1e-15, 'f_min': 0.0} res = shgo(test1_2.f, test1_2.bounds, n=1, iters=None, options=options, sampling_method='sobol')
def test_10_finite_time(self): """Test single function constraint passing""" options = {'maxtime': 1e-15} res = shgo(test1_1.f, test1_1.bounds, n=1, iters=None, options=options, sampling_method='sobol')
def test_5_2_sobol_argless(self): """Test Default sobol sampling settings on TestFunction 1""" res = shgo(test1_1.f, test1_1.bounds, constraints=test1_1.cons, sampling_method='sobol') numpy.testing.assert_allclose(res.x, test1_1.expected_x, rtol=1e-5, atol=1e-5)
def test_5_1_simplicial_argless(self): """Test Default simplicial sampling settings on TestFunction 1""" res = shgo(test1_1.f, test1_1.bounds, constraints=test1_1.cons) numpy.testing.assert_allclose(res.x, test1_1.expected_x, rtol=1e-5, atol=1e-5)