def __init__(self, problem_idx): SyntheticEnv.__init__(self, problem_idx) self.name = 'synthetic_griewank' if problem_idx == 0: self.dim_x = 3 self.feasible_action_value_threshold = -2 elif problem_idx == 1: self.dim_x = 10 self.feasible_action_value_threshold = -50 elif problem_idx == 2: self.dim_x = 20 self.feasible_action_value_threshold = -50 self.feasible_reward = 100 self.reward_function = lambda sol: -benchmarks.griewank(sol)[0]
def get_objective_function(sol): if obj_fcn == 'shekel': return shekel(sol, A, C)[0] elif obj_fcn == 'schwefel': return -benchmarks.schwefel(sol)[0] elif obj_fcn == 'griewank': return -benchmarks.griewank(sol)[0] elif obj_fcn == 'rastrigin': return -benchmarks.rastrigin(sol)[0] elif obj_fcn == 'ackley': return -benchmarks.ackley(sol)[0] elif obj_fcn == 'rosenbrock': return -benchmarks.rosenbrock(sol)[0] elif obj_fcn == 'schaffer': return -benchmarks.schaffer(sol)[0] else: print "wrong function name" sys.exit(-1)
def test_function(param): """ Griewank testing function (the minus is to convert the problem into a maximization) """ return -1 * griewank((param["x0"], param["x1"], param["x2"]))[0],
def griewank_on_cube(u: [float]) -> float: # https://deap.readthedocs.io/en/master/api/benchmarks.html#deap.benchmarks.griewank u_squished = [1200 * (ui**1.1 - 0.5) for ui in u] return benchmarks.griewank(u_squished)[0]
def evaluate(self, x): return griewank(x)[0]
def griewank_arg0(sol): return benchmarks.griewank(sol)[0]
_delta = self._fBest_DoE - self.fopt if self.iter_count > 1 and \ np.mean(self._hist_EI[0:min(3, self.iter_count - 1)]) < 0.01 * _delta: self.stop_dict['low-EI'] = np.mean(self._hist_EI) if self.eval_count >= (self.max_FEs / 2): self.stop_dict['max_FEs'] = self.eval_count return super().check_stop() np.random.seed(42) dim = 2 max_FEs = 100 obj_fun = lambda x: benchmarks.griewank(x)[0] lb, ub = -600, 600 search_space = ContinuousSpace([lb, ub]) * dim mean = constant_trend(dim, beta=None) # autocorrelation parameters of GPR thetaL = 1e-10 * (ub - lb) * np.ones(dim) thetaU = 10 * (ub - lb) * np.ones(dim) theta0 = np.random.rand(dim) * (thetaU - thetaL) + thetaL model = GaussianProcess(corr='squared_exponential', theta0=theta0, thetaL=thetaL, thetaU=thetaU, nugget=1e-6,
def fitness(x): return benchmarks.griewank(x)[0]