def shekel_on_cube(u: [float]) -> float: # https://deap.readthedocs.io/en/master/api/benchmarks.html#deap.benchmarks.schaffer n_dim = len(u) NUMMAX = 15 A = 10 * np.random.rand(NUMMAX, n_dim) C = np.random.rand(NUMMAX) u_squished = [800 * (smoosh(ui) - 0.5) for ui in u] return 1.2298 - benchmarks.shekel(u_squished, A, C)[0]
def draw_points(points, ax): points = np.array(points) evaluations = [benchmarks.shekel(x, A, C)[0] for x in points] #ax.scatter(points[:, 0], points[:, 1], evaluations, c='black', marker='>') if len(points) >= 0: ax.view_init(azim=-90, elev=70) plt.plot(points[:, 0], points[:, 1], 'ro', markerfacecolor='None', markeredgewidth=1, markersize=2.5) #plt.show() #import pdb;pdb.set_trace() plt.savefig(save_dir + '/' + str(points.shape[0]) + '.png')
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 __init__(self, problem_idx): SyntheticEnv.__init__(self, problem_idx) self.name = 'synthetic_shekel' if problem_idx == 0: self.dim_x = 3 self.feasible_action_value_threshold = 3.0 elif problem_idx == 1: self.dim_x = 10 self.feasible_action_value_threshold = 2.0 elif problem_idx == 2: self.dim_x = 20 self.feasible_action_value_threshold = 1.0 config = pickle.load( open( './test_results/function_optimization/shekel/shekel_dim_' + str(self.dim_x) + '.pkl', 'r')) A = config['A'] C = config['C'] self.reward_function = lambda sol: benchmarks.shekel(sol, A, C)[0] self.feasible_reward = 1.0
def shekel_arg0(sol): return benchmarks.shekel(sol, A, C)[0]
def get_objective_function(sol): return shekel(sol, A, C)[0]
def shekel_arg0(sol): return np.nan if w_obstacles and sol[2] == 1 else benchmarks.shekel(sol[:2], a, c)[0]
def shekel_arg0(self, sol): return np.nan if self.grid[sol[1]][sol[0]] == 1 else \ benchmarks.shekel(sol[:2]/np.array(self.grid.shape)*10, self.A, self.C)[0]