def test_optima_noisy(self): """Ensure that noisy functions keep the optimum.""" for name in self.function_list: bb = tf.TestBlackBox(name) noisybb = tf.TestNoisyBlackBox(bb, 0.0, 0.1) self.assertAlmostEqual( noisybb.evaluate(bb._function.optimum_point), bb._function.optimum_value, delta=0.1, msg='Noisy function ' + name + ': absolute error exceeded') for name in self.function_list: bb = tf.TestBlackBox(name) noisybb = tf.TestNoisyBlackBox(bb, 0.1, 0.0) funval = noisybb.evaluate(bb._function.optimum_point) if (abs(bb._function.optimum_value) > 1.0e-8): error = (abs(funval - bb._function.optimum_value) / abs(bb._function.optimum_value)) else: error = abs(funval - bb._function.optimum_value) self.assertLessEqual(error, 0.1, msg='Noisy function ' + name + ': relative error exceeded') # -- end function
def test_msrsm_st_miqp3_noisy(self): """Check solution of noisy st_miqp3 with MSRSM, genetic.""" bb = tf.TestNoisyBlackBox(tf.TestBlackBox('st_miqp3'), 0.1, 0.01) optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving st_miqp3 with random seed ' + '{:d}'.format(seed)) settings = RbfoptSettings(algorithm='MSRSM', global_search_method='genetic', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, rand_seed=seed) alg = ra.RbfoptAlgorithm(settings, bb) res = alg.optimize() msg = 'Could not solve st_miqp3 with MSRSM algorithm' target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg)
def test_msrsm_branin_noisy_with_init(self): """Check solution of noisy branin with MSRSM, sampling.""" bb = tf.TestNoisyBlackBox(tf.TestBlackBox('branin'), 0.1, 0.01) optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving branin with random seed ' + '{:d}'.format(seed)) settings = RbfoptSettings(algorithm='MSRSM', global_search_method='sampling', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, rand_seed=seed) init_node_pos = [[0, 0], [-2, 2], [5, 10], [-2.5, 1]] alg = ra.RbfoptAlgorithm(settings, bb, init_node_pos) res = alg.optimize() msg = ('Could not solve noisy branin with init and ' + 'MSRSM algorithm') target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg)
def test_gutmann_parallel_st_miqp3_noisy(self): """Check solution of noisy st_miqp3 with Gutmann, solver.""" bb = tf.TestNoisyBlackBox(tf.TestBlackBox('st_miqp3'), 0.1, 0.01) optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving st_miqp3 with random seed ' + '{:d}'.format(seed)) settings = RbfoptSettings(algorithm='Gutmann', global_search_method='solver', rbf_shape_parameter=0.01, rbf='gaussian', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, num_cpus=2, rand_seed=seed) alg = ra.RbfoptAlgorithm(settings, bb) res = alg.optimize() msg = 'Could not solve st_miqp3 with Gutmann\'s algorithm' target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg)
def test_gutmann_branin_cat_noisy_with_init(self): """Check solution of noisy branin_cat with Gutmann, solver.""" bb = tf.TestNoisyBlackBox(tf.TestBlackBox('branin_cat'), 0.1, 0.01) optimum = bb._function.optimum_value for seed in self.rand_seeds: print() print('Solving branin_cat with random seed ' + '{:d}'.format(seed)) settings = RbfoptSettings(algorithm='Gutmann', global_search_method='solver', target_objval=optimum, eps_opt=self.eps_opt, max_iterations=200, max_evaluations=300, rand_seed=seed) init_node_pos = [[0, 0, 0], [-2, 2, 1], [5, 10, 2]] init_node_val = [bb._function.evaluate(x) for x in init_node_pos] alg = ra.RbfoptAlgorithm(settings, bb, init_node_pos, init_node_val) res = alg.optimize() msg = ('Could not solve noisy branin with init and ' + 'Gutmann\'s algorithm') target = optimum + (abs(optimum) * self.eps_opt if abs(optimum) > settings.eps_zero else self.eps_opt) self.assertLessEqual(res[0], target, msg=msg)