def __init__(self, num_variables=30, phenome_preprocessor=None, **kwargs): f2 = ZDT_f2(ZDT1to4_f1, ZDT1to3_g(num_variables), self.h) self.min_bounds = [0.0] * num_variables self.max_bounds = [1.0] * num_variables bounds = (self.min_bounds, self.max_bounds) preprocessor = BoundConstraintsChecker(bounds, phenome_preprocessor) ZDTBaseProblem.__init__(self, [ZDT1to4_f1, f2], num_objectives=2, phenome_preprocessor=preprocessor, **kwargs) self.is_deterministic = True self.do_maximize = False self.num_variables = num_variables
def __init__(self, objective_function, num_objectives, num_variables, phenome_preprocessor=None, **kwargs): assert num_variables > num_objectives self.num_variables = num_variables self.min_bounds = [0.0] * num_variables self.max_bounds = [1.0] * num_variables bounds = (self.min_bounds, self.max_bounds) preprocessor = BoundConstraintsChecker(bounds, phenome_preprocessor) self.is_deterministic = True self.do_maximize = False MultiObjectiveTestProblem.__init__(self, objective_function, num_objectives, phenome_preprocessor=preprocessor, **kwargs)
def __init__(self, num_variables, matrices=None, offsets=None, phenome_preprocessor=None, **kwargs): rastrigin = RastriginFunction() weierstrass = WeierstrassFunction() basic_functions = [ rastrigin, rastrigin, weierstrass, weierstrass, griewank, griewank, ackley, ackley, sphere, sphere ] if matrices is None: matrices = [np.identity(num_variables)] * 10 if offsets is None: offsets = self.offsets self.hybrid_composition_function = HybridCompositionFunction( num_variables, basic_functions, matrices, self.sigmas, self.lambdas, self.biases, offsets, 2000.0, name="Hybrid Composition Function 1") self.num_variables = num_variables self.is_deterministic = True self.do_maximize = False self.min_bounds = [-5.0] * num_variables self.max_bounds = [5.0] * num_variables bounds = (self.min_bounds, self.max_bounds) preprocessor = BoundConstraintsChecker(bounds, phenome_preprocessor) TestProblem.__init__(self, self.objective_function, phenome_preprocessor=preprocessor, **kwargs)
def __init__(self, num_points=10, dimension=2, existing_points=None, noise_strength=0.0, dist_matrix_function=None, phenome_preprocessor=None, **kwargs): """Constructor. .. note:: If existing points are not given, this constructor creates a randomly initialized problem instance by drawing `num_points` randomly. (Note that in general, the number of existing points does not necessarily have to be equal to the number of optimized points.) Parameters ---------- num_points : int, optional The number of points whose uniformity is to be optimized. dimension : int, optional The dimension of the unit cube. existing_points : list, optional A set of existing points influencing the optimized points. By default `num_points` are drawn randomly. noise_strength : float, optional If this value is larger than zero, points are perturbed by a multivariate Gaussian distribution with this standard deviation, before the distances are measured. dist_matrix_function : callable, optional A callable that returns a distance matrix for two sequences of points as input. Default is Euclidean distance. phenome_preprocessor : callable, optional A callable potentially applying transformations or checks to the phenome. Modifications should only be applied to a copy of the input. The (modified) phenome must be returned. When this pre-processing raises an exception, no function evaluations are counted. By default, no pre-processing is applied. kwargs Arbitrary keyword arguments, passed through to the constructor of the super class. """ assert num_points > 0 assert dimension > 0 assert noise_strength >= 0.0 self.num_points = num_points self.dimension = dimension if existing_points is None: existing_points = self.create_existing_points() self.existing_points = np.asarray(existing_points) self.noise_strength = noise_strength if dist_matrix_function is None: dist_matrix_function = calc_euclidean_dist_matrix self.dist_matrix_function = dist_matrix_function self.num_variables = num_points * dimension self.min_bounds = [0.0] * self.num_variables self.max_bounds = [1.0] * self.num_variables bounds = (self.min_bounds, self.max_bounds) preprocessor = BoundConstraintsChecker(bounds, phenome_preprocessor) Problem.__init__(self, self.obj_function, num_objectives=num_points, phenome_preprocessor=preprocessor, **kwargs)
def __init__(self, num_objectives=1, noisy=False, algo_max_it=100, params_to_optimize=None, internal_problem=None, start_point=None, phenome_preprocessor=None, **kwargs): """Constructor. .. note:: If the starting point is not given, this constructor creates a randomly initialized problem instance by selecting the starting point randomly. Parameters ---------- num_objectives : int, optional The number of objectives to consider. Must be one (default) or two. The first objective is the best objective value obtained by the algorithm, the second one is the number of function evaluations consumed. noisy : bool, optional If True, a new starting point is drawn for each algorithm run. Otherwise, the same starting point is used for all runs. algo_max_it : int, optional The maximal number of iterations to execute for the algorithm. This should be kept relatively low to keep the function evaluation of this problem cheap. params_to_optimize : list, optional This problem has at most four real-valued decision variables. By providing this argument, a subset and the order can be selected. The object provided here must have the format described in :func:`get_default_params <optproblems.realworld.GradientMethodConfiguration.get_default_params>`. internal_problem : optproblems.Problem, optional The problem the gradient method has to optimize. By default, the :class:`Himmelblau <optproblems.continuous.Himmelblau>` problem is chosen. start_point : list, optional The starting point for the gradient method. If none is provided, the starting point is drawn with the method :func:`create_start_point <optproblems.realworld.GradientMethodConfiguration.create_start_point>`. If ``noisy == True``, this argument is ignored. phenome_preprocessor : callable, optional A callable potentially applying transformations or checks to the phenome. Modifications should only be applied to a copy of the input. The (modified) phenome must be returned. When this pre-processing raises an exception, no function evaluations are counted. By default, no pre-processing is applied. kwargs Arbitrary keyword arguments, passed through to the constructor of the super class. """ assert num_objectives in (1, 2) self.noisy = noisy if algo_max_it is None: algo_max_it = float("inf") self.algo_max_it = algo_max_it if params_to_optimize is None: params_to_optimize = self.get_default_params() self.params_to_optimize = params_to_optimize self.num_variables = len(params_to_optimize) self.min_bounds = [params_to_optimize[i][1][0] for i in range(self.num_variables)] self.max_bounds = [params_to_optimize[i][1][1] for i in range(self.num_variables)] bounds = (self.min_bounds, self.max_bounds) preprocessor = BoundConstraintsChecker(bounds, phenome_preprocessor) Problem.__init__(self, self.obj_function, num_objectives, phenome_preprocessor=preprocessor, **kwargs) if internal_problem is None: internal_problem = Himmelblau() if not isinstance(internal_problem, Problem): internal_problem = Problem(internal_problem) self.internal_problem = internal_problem if start_point is None: start_point = self.create_start_point() self.start_point = start_point