### Initialization point logging Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_algorithm.html Calculates the gap and logs initialization points during the algorithm setup. ```python gap = ru.compute_gap(self.l_settings, self.fbest + self.all_node_err_bounds[self.fbest_index, 1]) self.current_step = self.first_step self.cyclecount += 1 # Print the initialization points for (i, val) in enumerate(self.node_val): min_dist = ru.get_min_distance(self.node_pos[i], np.vstack((self.node_pos[:i], self.node_pos[(i+1):]))) self.update_log('Initialization', self.node_is_noisy[i], val, gap) ``` -------------------------------- ### Genetic Algorithm Optimization Setup Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_aux_problems.html Initializes parameters for a simple genetic algorithm used to minimize a subproblem. ```python assert(isinstance(var_lower, np.ndarray)) assert(isinstance(var_upper, np.ndarray)) assert(isinstance(integer_vars, np.ndarray)) assert(len(var_lower) == n) assert(len(var_upper) == n) assert(isinstance(settings, RbfoptSettings)) # Define parameters here, for now. Will move them to # rbfopt_settings later if it seems that the user should be able # to change their value. population_size = settings.ga_base_population_size + 20 * n//5 mutation_rate = 0.1 # Derived parameters. Since the best individual will always remain # and mutate, there is a -1 in the count for new individuals. num_surviving = population_size//4 num_new = population_size - 2*num_surviving - 1 ``` -------------------------------- ### Integer variable model setup Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_degree1_models.html Defines parameters and variables for integer variables within a Pyomo model. ```python ni = len(integer_vars) # Number of integer variables model.ni = Param(initialize=ni) model.NI = RangeSet(0, model.ni-1) # Parameter: list of indices of integer variables int_var_param = {} for i in range(ni): int_var_param[i] = integer_vars[i] model.integer_vars = Param(model.NI, initialize=int_var_param) # Variable: the point in the space model.y = Var(model.NI, domain=Integers, bounds=_y_bounds) # Constraints: every integer variable is simply equal to one # of the existing variables model.IntConstraint = Constraint(model.NI, rule=_int_constraint_rule) ``` -------------------------------- ### Initialize instance variables function Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_aux_problems.html Initializes the variables of a problem instance to assist local search by starting at a feasible point. ```python [docs]def initialize_instance_variables(settings, instance, start_point=None): """Initialize the variables of a problem instance. Initialize the x variables of a problem instance, and set the corresponding values for the vectors :math:`(u,\pi)`. This helps the local search by starting at a feasible point. Parameters ---------- settings : :class:`rbfopt_settings.RbfoptSettings` Global and algorithmic settings. instance : pyomo.ConcreteModel A concrete instance of mathematical optimization model. ``` -------------------------------- ### restart(pool=None, remaining_eval=None) Source: https://rbfopt.readthedocs.io/en/latest/rbfopt_algorithm.html Perform a complete restart of the optimization. Discards the current RBF model and selects new sample points to start the algorithm from scratch. ```APIDOC ## restart(pool=None, remaining_eval=None) ### Description Perform a complete restart of the optimization. Discards the current RBF model and selects new sample points to start the algorithm from scratch. Previous point evaluations are ignored but still recorded. ### Method Function ### Parameters - **pool** (multiprocessing.Pool()) - Optional - A pool of workers to evaluate the initialization points in parallel. If None, parallel evaluation will not be performed. - **remaining_eval** (list()) - Optional - A list to which any outstanding initialization point evaluation is appended. If None, these evaluations will be discarded. ### Raises - **RuntimeError** - If the routine does not find enough good initialization points. ``` -------------------------------- ### Settings constructor with all default parameters Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_settings.html Defines the __init__ method that sets every configuration parameter with its default value, enabling full customization of the optimization settings. ```python def __init__(self, max_iterations=1000, max_evaluations=300, max_noisy_evaluations=200, max_cycles=1000, max_clock_time=1.0e30, num_cpus=1, parallel_wakeup_time=0.1, algorithm='MSRSM', rbf='auto', rbf_shape_parameter=0.1, target_objval=-1.0e10, eps_opt=1.0e-2, eps_zero=1.0e-15, eps_impr=1.0e-4, eps_linear_dependence=1.0e-6, min_dist=1.0e-5, do_infstep=False, do_local_search=True, num_global_searches=5, init_strategy='lhd_maximin', init_include_midpoint=True, init_sample_fraction=-1.0, init_sample_increase_parallel=0.05, max_random_init=50, function_scaling='auto', log_scaling_threshold=1.0e6, domain_scaling='auto', dynamism_clipping='auto', dynamism_threshold=1.0e3, local_search_threshold=0.25, local_search_box_scaling=0.5, max_stalled_iterations=100, discarded_window_size=30, max_fraction_discarded=0.5, max_consecutive_restoration=15, max_cross_validations=50, max_noisy_restarts=2, max_noisy_iterations=200, targetval_clipping=True, global_search_method='genetic', ga_base_population_size=400, ga_num_generations=20, num_samples_aux_problems=1000, modified_msrsm_score=True, max_consecutive_refinement=5, thresh_unlimited_refinement=0.9, thresh_unlimited_refinement_stalled=0.9, refinement_frequency=3, ref_num_integer_candidates=10, ref_acceptable_decrease_shrink=0.2, ref_acceptable_decrease_enlarge=0.6, ref_acceptable_decrease_move=0.1, ref_min_radius=1.0e-3, ref_init_radius_multiplier=2.0, ref_min_grad_norm=1.0e-2, ``` -------------------------------- ### RbfoptAlgorithm constructor Source: https://rbfopt.readthedocs.io/en/latest/rbfopt_algorithm.html Initializes the optimization algorithm with settings, a black box describing the problem, and optional initial points and values. The do_init_strategy parameter controls whether the algorithm generates an initial set of points. ```APIDOC ## RbfoptAlgorithm(settings, black_box, init_node_pos=None, init_node_val=None, do_init_strategy=True) ### Description Creates an instance of the RbfoptAlgorithm class, which implements the main optimization algorithm. The algorithm can be warm-started from a given state. ### Parameters - **settings** (rbfopt_settings.RbfoptSettings) - Required - Global and algorithmic settings. - **black_box** (rbfopt_black_box.RbfoptBlackBox) - Required - An object derived from class RbfoptBlackBox that describes the problem. - **init_node_pos** (2D numpy.ndarray[float] or None) - Optional - Coordinates of points at which the function value is known. These points will be added to the points generated by the algorithm. If None, all initial points will be generated by the algorithm. - **init_node_val** (1D numpy.ndarray[float] or None) - Optional - Function values corresponding to the points given in init_node_pos. Should be None if the previous argument is None. If init_node_pos is not None but init_node_val is None, the points in init_node_pos will be evaluated in the initialization phase. - **do_init_strategy** (bool) - Optional - Perform initialization strategy. If True, the algorithm will generate an initial set of points on top of any user-provided points. If False, we will rely on user-provided points only. Default True. ### Attributes - **elapsed_time** (float) - Elapsed CPU time up to the point where state was last saved. - **best_local_rbf** (string, float) - Best RBF type to construct model for local search, and the corresponding shape parameter. - **best_global_rbf** (string, float) - Best RBF type to construct model for global search, and the corresponding shape parameter. - **n** (int) - Dimension of the problem. - **itercount** (int) - Iteration number. - **evalcount** (int) - Total number of function evaluations in accurate mode. - **noisy_evalcount** (int) - Total number of function evaluations in noisy mode. - **current_step** (int) - Identifier of the current step within the cyclic optimization strategy counter. - **cyclecount** (int) - Number of cycles. - **num_cons_refinement** (int) - Current number of consecutive refinement steps. - **num_stalled_iter** (int) - Number of consecutive iterations without improvement. - **num_noisy_restarts** (int) - Number of restarts in noisy mode. - **discarded_iters** (collections.deque) - Rolling window to keep track of discarded iterations. - **do_init_strategy** (bool) - If True, perform initialization strategy on first cycle. - **inf_step** (int) - Identifier of the InfStep. - **local_search_step** (int) - Identifier of the LocalSearchStep. - **refinement_step** (int) - Identifier of the Step. - **cycle_length** (int) - Length of an optimization cycle. - **restoration_step** (int) - Identifier of the RestorationStep. - **first_step** (int) - Identifier of the first step of an optimization cycle. - **two_phase_optimization** (bool) - Is the fast but noisy objective function available? - **eval_mode** (string) - Evaluation mode for the objective function at a given stage. Can be either 'noisy' or 'accurate'. - **node_pos** (2D numpy.ndarray[float]) - Coordinates of the interpolation nodes (i.e., the points where the objective function has already been evaluated). The coordinates may be in the transformed space. This matrix only includes points since the last restart. - **node_val** (1D numpy.ndarray[float]) - Objective function value at the points in node_pos. This array only includes points since the last restart. - **node_is_noisy** (1D numpy.ndarray[bool]) - For each interpolation node in node_pos, was it evaluated in 'noisy' mode? - **node_err_bounds** (2D numpy.ndarray[float]) - The lower and upper variation of the function value for the nodes in node_pos. The variation is assumed 0 for nodes evaluated in accurate mode. - **all_node_pos** (2D numpy.ndarray[float]) - Coordinates of the interpolation nodes. This matrix contains all evaluated points in the original space, and is persistent across restarts. - **all_node_val** (1D numpy.ndarray[float]) - Objective function value at the points in all_node_pos. ``` -------------------------------- ### Get Dimension Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_test_functions.html Returns the total dimension of the function, calculated as the base dimension multiplied by the dimension multiplier. ```python [docs] def get_dimension(self): return self._function.dimension * self.dimension_multiplier ``` -------------------------------- ### Get most common element in a list Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_utils.html Returns the most frequent element in a list, optionally excluding specific values. ```python def get_most_common_element(array, to_exclude=[]): """Get most common element in a list. Parameters ---------- array : List[any] The list whose most common element is sought. to_exclude : List[any] A list of elements to exclude from the count. Returns ------- Any The most common element, None if all elements were excluded. """ counter = collections.Counter( val for val in array if val not in to_exclude) if (counter.most_common(1)): return counter.most_common(1)[0][0] return None ``` -------------------------------- ### print_init_line() Source: https://rbfopt.readthedocs.io/en/latest/rbfopt_algorithm.html Prints the first line of the output, with headers. ```APIDOC ## print_init_line() ### Description Print first line of the output, with headers. ### Parameters None ### Returns None (prints to standard output). ``` -------------------------------- ### RbfoptSettings.print Source: https://rbfopt.readthedocs.io/en/latest/rbfopt_settings.html Prints the value of all settings to the specified output stream on a single line. ```APIDOC ## RbfoptSettings.print ### Description Prints the value of all settings to the specified output stream on a single line. ### Method _instance method_ ### Signature `print(output_stream)` ### Parameters - **output_stream** (file) - Required - The stream on which messages are printed. ``` -------------------------------- ### RbfoptUserBlackBox Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_user_black_box.html A class that implements the necessary methods to describe the black-box function to be minimized, and gets all the required data from the user. ```APIDOC ## RbfoptUserBlackBox ### Description A class that implements the necessary methods to describe the black-box function to be minimized, and gets all the required data from the user. ### Constructor #### Parameters - **dimension** (int) - Required - Dimension of the problem. - **var_lower** (1D numpy.ndarray[float]) - Required - Lower bounds of the decision variables. - **var_upper** (1D numpy.ndarray[float]) - Required - Upper bounds of the decision variables. - **var_type** (1D numpy.ndarray[char]) - Required - An array of length equal to dimension, specifying the type of each variable. Possible types are 'R' for real (continuous) variables, 'I' for integer (discrete, ordered) variables, 'C' for categorical (discrete, unordered) variables. Bounds for categorical variables are interpreted the same way as for integer variables, but categorical variables are handled differently by the optimization algorithm; e.g., a categorical variable with bounds [2, 4] can take the value 2, 3 or 4. - **obj_funct** (Callable[1D numpy.ndarray[float]]) - Required - The function to optimize. Must take a numpy array as argument, and return a float. - **obj_funct_noisy** (Callable[1D numpy.ndarray[float]] or None) - Optional - The noisy but fast version of the function to optimize. If given, it must take a numpy array as argument, and return a numpy array with three floats, in the following order: the approximate function value, its lower variation, and its upper variation, where lower <= 0 and upper >= 0 and the true function value is contained between value + lower and value + upper. If it is None, we assume that there is no fast version of the objective function. ### See Also - :class:`rbfopt_black_box.BlackBox` ``` -------------------------------- ### Get Variable Bounds and Types Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_test_functions.html Methods to retrieve the lower bounds, upper bounds, and variable types for the test function. ```python [docs] def get_var_lower(self): return self.var_lower [docs] def get_var_upper(self): return self.var_upper [docs] def get_var_type(self): return self.var_type ``` -------------------------------- ### rbfopt_utils.initialize_nodes(settings, var_lower, var_upper, integer_vars, categorical_info) Source: https://rbfopt.readthedocs.io/en/latest/rbfopt_utils.html Computes the initial sample points for the optimization algorithm based on the provided settings and variable bounds. ```APIDOC ## rbfopt_utils.initialize_nodes(settings, var_lower, var_upper, integer_vars, categorical_info) ### Description Compute the initial sample points using the initialization strategy indicated in the algorithmic settings. ### Parameters - **settings** (rbfopt_settings.RbfoptSettings) - Required - Global and algorithmic settings. - **var_lower** (1D numpy.ndarray[float]) - Required - List of lower bounds of the variables. - **var_upper** (1D numpy.ndarray[float]) - Required - List of upper bounds of the variables. - **integer_vars** (1D numpy.ndarray[int]) - Required - A list containing the indices of the integrality constrained variables. If empty, all variables are assumed to be continuous. - **categorical_info** ((1D numpy.ndarray[int], 1D numpy.ndarray[int], List[(int, 1D numpy.ndarray[int])]) or None) - Required - Information on categorical variables: array of indices of categorical variables in original space, array of indices of noncategorical variables in original space, and expansion of each categorical variable, given as a tuple (original index, indices of expanded variables). ### Returns - 2D numpy.ndarray[float] - Matrix containing at least n+1 corner points, one for each row, where n is the dimension of the space. The number and position of points depends on the chosen strategy. ### Raises - RuntimeError - If a set of feasible and linearly independent sample points cannot be computed within the prescribed number of iterations. ``` -------------------------------- ### Initialize environment settings Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_utils.html Sets the random seed and suppresses Pyomo logging output based on the provided settings object. ```python def init_environment(settings): """Initialize the random seed and disable Pyomo output. Parameters ---------- settings : :class:`rbfopt_settings.RbfoptSettings` Global and algorithmic settings. """ assert(isinstance(settings, RbfoptSettings)) # Numpy's random seed np.random.seed(settings.rand_seed) # Disable Pyomo's logger if necessary if (not settings.debug): logging.getLogger('pyomo.core').setLevel(logging.CRITICAL) logging.getLogger('pyomo.opt').setLevel(logging.CRITICAL) logging.getLogger('pyomo.solvers').setLevel(logging.CRITICAL) ``` -------------------------------- ### TestBlackBox Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_test_functions.html A black-box constructed from a known test function. It provides methods to get dimension, bounds, variable types, and evaluate the function. ```APIDOC ## TestBlackBox ### Description A black-box constructed from a known test function. It provides methods to get dimension, bounds, variable types, and evaluate the function. ### Constructor #### `__init__(self, name)` - **name** (string) - Required - The name of the function to be implemented. ### Methods #### `get_dimension(self)` Returns the dimension of the black-box function. #### `get_var_lower(self)` Returns the lower bounds of the variables. #### `get_var_upper(self)` Returns the upper bounds of the variables. #### `get_var_type(self)` Returns the variable types (e.g., 'R' for real, 'I' for integer, 'C' for categorical). #### `evaluate(self, point)` Evaluates the black-box function at the given point. #### `evaluate_noisy(self, point)` Raises `NotImplementedError` because noisy evaluation is not implemented. #### `has_evaluate_noisy(self)` Returns `False` indicating noisy evaluation is not available. ``` -------------------------------- ### Get index of ready async computation Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_utils.html Returns the index of the last completed asynchronous computation in a list, or the list length if none are ready. ```python def get_one_ready_index(results): """Get index of a single async computation result that is ready. Given a list containing results of asynchronous computations dispatched to a worker pool, obtain the index of the last computation that has concluded. (Last is better to use the pop() function in the list.) Parameters ---------- results : List[(multiprocessing.pool.AsyncResult, any)] A list of tasks, where each task is a list and the first element is the output of a call to apply_async. The other elements of the list will never be scanned by this function, and they could be anything. Returns ------- int Index of last computation that completed, or len(results) if no computation is ready. """ for i in reversed(range(len(results))): if results[i][0].ready(): return i return len(results) ``` -------------------------------- ### initialize_nodes Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_utils.html Computes the initial sample points using the initialization strategy indicated in the algorithmic settings. ```APIDOC ## initialize_nodes ### Description Computes the initial sample points using the initialization strategy indicated in the algorithmic settings. ### Parameters - **settings** (RbfoptSettings) - Required - Global and algorithmic settings. - **var_lower** (1D numpy.ndarray[float]) - Required - List of lower bounds of the variables. - **var_upper** (1D numpy.ndarray[float]) - Required - List of upper bounds of the variables. - **integer_vars** (1D numpy.ndarray[int]) - Required - A List containing the indices of the integrality constrained variables. If empty, all variables are assumed to be continuous. - **categorical_info** (tuple or None) - Required - Information on categorical variables: array of indices of categorical variables in original space, array of indices of noncategorical variables in original space, and expansion of each categorical variable, given as a tuple (original index, indices of expanded variables). ### Returns - **2D numpy.ndarray[float]** - Matrix containing at least n+1 corner points, one for each row, where n is the dimension of the space. The number and position of points depends on the chosen strategy. ### Raises - **RuntimeError** - If a set of feasible and linearly independent sample points cannot be computed within the prescribed number of iterations. ``` -------------------------------- ### Algorithm Parameter Assertions and Initialization Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_algorithm.html Validates input dimensions and initialization strategies, then sets up RBF model references and environment settings. ```python assert(len(var_lower) == dimension) assert(len(var_upper) == dimension) assert((len(integer_vars) == 0) or (max(integer_vars) < dimension)) assert(init_node_pos is None or init_node_val is None or len(init_node_pos) == len(init_node_val)) assert(do_init_strategy or (init_node_pos is not None and len(init_node_pos) >= round((dimension + 1)*settings.init_sample_fraction))) # Set the value of 'auto' parameters if necessary l_settings = settings.set_auto_parameters(dimension, var_lower, var_upper, integer_vars) # Save references self.l_settings = l_settings # Local and global RBF models are initially the same self.best_local_rbf = (l_settings.rbf, l_settings.rbf_shape_parameter) self.best_global_rbf = (l_settings.rbf, l_settings.rbf_shape_parameter) self.best_local_rbf_list = list() self.best_global_rbf_list = list() # We use n to denote the dimension of the problem, same notation # of the paper. This is redundant but it simplifies our life. self.n = dimension # Set random seed and external loggers. We always use numpy's # random generator. This is taken care of by an appropriate # function (useful for parallelization). ru.init_environment(l_settings) ``` -------------------------------- ### get_integer_candidate(settings, n, k, h, start_point, ref_radius, candidate, integer_vars, categorical_info) Source: https://rbfopt.readthedocs.io/en/latest/rbfopt_refinement.html Gets an integer candidate point from a fractional point. ```APIDOC ## get_integer_candidate(settings, n, k, h, start_point, ref_radius, candidate, integer_vars, categorical_info) ### Description Gets an integer candidate point from a fractional point. It looks for integer points around the given fractional point, trying to find one with a good value of the linear model. ### Parameters - **settings** (rbfopt_settings.RbfoptSettings) - Required - Global and algorithmic settings. - **n** (int) - Required - Dimension of the problem. - **k** (int) - Required - Number of interpolation nodes. - **h** (1D numpy.ndarray[float]) - Required - Linear coefficients of the model. - **start_point** (1D numpy.ndarray[float]) - Required - Starting point for the descent. - **ref_radius** (float) - Required - Radius of the local search. - **candidate** (1D numpy.ndarray[float]) - Required - Fractional point to begin the search. - **integer_vars** (1D numpy.ndarray[int]) - Required - Indices of the integer variables. - **categorical_info** ((1D numpy.ndarray[int], 1D numpy.ndarray[int], List[(int, 1D numpy.ndarray[int])]) or None) - Required - Information on categorical variables: array of indices of categorical variables in original space, array of indices of noncategorical variables in original space, and expansion of each categorical variable, given as a tuple (original index, indices of expanded variables). ### Returns - (1D numpy.ndarray[float], float) - Next candidate point for the search, and the corresponding change in model value compared to the given point. ``` -------------------------------- ### get_num_init_samples Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_utils.html Computes the number of initial sample points based on problem dimension and settings. ```APIDOC ## get_num_init_samples ### Description Computes the number of initial sample points based on problem dimension and settings. ### Parameters - **settings** (RbfoptSettings) - Required - Global and algorithmic settings. - **n** (int) - Required - Dimension of the problem, i.e. number of variables. ### Returns - **int** - Number of samples, depending on problem dimension and settings. ``` -------------------------------- ### global_step(settings, n, k, var_lower, var_upper, integer_vars, categorical_info, node_pos, rbf_lambda, rbf_h, tfv, Amatinv, fmin_index, current_step) Source: https://rbfopt.readthedocs.io/en/latest/rbfopt_algorithm.html Perform a global search step, with a different methodology depending on the algorithm chosen. ```APIDOC ## global_step(settings, n, k, var_lower, var_upper, integer_vars, categorical_info, node_pos, rbf_lambda, rbf_h, tfv, Amatinv, fmin_index, current_step) ### Description Perform a global search step, with a different methodology depending on the algorithm chosen. ### Method Function ### Parameters - **settings** (rbfopt_settings.RbfoptSettings) - Required - Global and algorithmic settings. - **n** (int) - Required - The dimension of the problem, i.e. size of the space. - **k** (int) - Required - Number of nodes, i.e. interpolation points. - **var_lower** (1D numpy.ndarray[float]) - Required - Vector of variable lower bounds. - **var_upper** (1D numpy.ndarray[float]) - Required - Vector of variable upper bounds. - **integer_vars** (1D numpy.ndarray[int]) - Required - A list containing the indices of the integrality constrained variables. If empty list, all variables are assumed to be continuous. - **categorical_info** ((1D numpy.ndarray[int], 1D numpy.ndarray[int], List[(int, 1D numpy.ndarray[int])])) - Required - Information on categorical variables: array of indices of categorical variables in original space, array of indices of noncategorical variables in original space, and expansion of each categorical variable, given as a tuple (original index, indices of expanded variables). - **node_pos** (2D numpy.ndarray[float]) - Required - List of coordinates of the nodes. - **rbf_lambda** (1D numpy.ndarray[float]) - Required - The lambda coefficients of the RBF interpolant, corresponding to the radial basis functions. List of dimension k. - **rbf_h** (1D numpy.ndarray[float]) - Required - The h coefficients of the RBF interpolant, corresponding to the polynomial. List of dimension n+1. - **tfv** ((List[float], float, float, List[(float, float)])) - Required - Transformed function values: scaled node values, scaled minimum, scaled maximum, and node error bounds. - **Amatinv** (2D numpy.ndarray[float]) - Required - Inverse of the RBF matrix. - **fmin_index** (int) - Required - Index of the node with the minimum function value. - **current_step** (int) - Required - Current step number. ``` -------------------------------- ### Compute RBF Interpolant Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_utils.html Example of computing the RBF interpolant by transforming function values and selecting the appropriate coefficient calculation method based on the number of nodes. ```python tfv = transform_function_values(settings, node_val, fmin, fmax, node_err_bounds) (scaled_node_val, scaled_fmin, scaled_fmax, scaled_err_bounds, rescale_function) = tfv Amat = get_rbf_matrix(settings, n, k, node_pos) # Compute RBF interpolant at current stage if (k < n+1): # Underdetermined RBF rbf_l, rbf_h = get_rbf_coefficients_underdet( settings, n, k, Amat, scaled_node_val, categorical_info) else: # Fully accurate RBF rbf_l, rbf_h = get_rbf_coefficients( settings, n, k, Amat, scaled_node_val, categorical_info) return bulk_evaluate_rbf(settings, points, n, k, node_pos, rbf_l, rbf_h) ``` -------------------------------- ### Initialize MSRSM auxiliary variables Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_aux_problems.html Initializes the rbfval and mindist variables of a problem instance using existing x and u_pi values to facilitate local search starting at a feasible point. ```python def initialize_msrsm_aux_variables(settings, instance): """Initialize auxiliary variables for the MSRSM model. Initialize the rbfval and mindist variables of a problem instance, using the values for for x and u_pi already given. This helps the local search by starting at a feasible point. Parameters ---------- settings : :class:`rbfopt_settings.RbfoptSettings` Global and algorithmic settings. instance : pyomo.ConcreteModel A concrete instance of mathematical optimization model. """ assert(isinstance(settings, RbfoptSettings)) dist = min(sum((instance.x[j].value - instance.node[i, j])**2 for j in instance.N) for i in instance.K) instance.mindistsq = dist ``` -------------------------------- ### Initialize and Solve RBF Coefficients Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_aux_problems.html Initializes RBF coefficients from provided values to ensure feasibility, then solves the optimization problem and loads the results. ```python # Initialize instance variables with the solution provided (if # available). This should avoid any infeasibility. if (init_rbf_lambda is not None and init_rbf_h is not None): for i in range(len(init_rbf_lambda)): instance.rbf_lambda[i] = init_rbf_lambda[i] for i in range(len(init_rbf_h)): instance.rbf_h[i] = init_rbf_h[i] # Solve and load results try: results = opt.solve(instance, keepfiles=False, tee=settings.print_solver_output) if ((results.solver.status == pyomo.opt.SolverStatus.ok) and (results.solver.termination_condition == pyomo.opt.TerminationCondition.optimal)): # this is feasible and optimal instance.solutions.load_from(results) rbf_lambda = np.array([instance.rbf_lambda[i].value for i in instance.K]) if (ru.get_size_P_matrix(settings, n) > 0): rbf_h = np.array([instance.rbf_h[i].value for i in instance.P]) else: rbf_h = np.array([]) else: # If we have initialization information, return it. It is # a feasible solution. Otherwise, this will be None. rbf_lambda = init_rbf_lambda rbf_h = init_rbf_h except: # If we have initialization information, return it. It is # a feasible solution. Otherwise, this will be None. rbf_lambda = init_rbf_lambda rbf_h = init_rbf_h return (rbf_lambda, rbf_h) ``` -------------------------------- ### Build Pyomo model for minimum-distance subproblem (rbfopt_degreem1_models) Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_degreem1_models.html The first block builds a Pyomo ConcreteModel for the minimum-distance subproblem: it sets node coordinates, variable bounds, the decision variable x, the auxiliary mindistsq variable, the objective, and the distance constraint, then adds integrality and categorical constraints if needed. The second block contains the assertion checks and the initial model setup (dimension and node count parameters) that precede the model construction. Both blocks are part of the same function body in the source, so they are grouped as one snippet. ```python # Coordinates of the nodes node_param = {} for i in range(k): for j in range(n): node_param[i, j] = float(node_pos[i][j]) model.node = Param(model.K, model.N, initialize=node_param) # Variable bounds var_lower_param = {} var_upper_param = {} for i in range(n): var_lower_param[i] = float(var_lower[i]) var_upper_param[i] = float(var_upper[i]) model.var_lower = Param(model.N, initialize=var_lower_param) model.var_upper = Param(model.N, initialize=var_upper_param) # Variable: the point in the space model.x = Var(model.N, domain=Reals, bounds=_x_bounds) # Auxiliary variable: value of the minimum distance to the nodes model.mindistsq = Var(domain=NonNegativeReals, bounds=(settings.min_dist,float('inf'))) # Objective function. model.OBJ = Objective(expr=(model.mindistsq), sense=maximize) model.MdistdefConstraint = Constraint(model.K, rule=_mdistdef_constraint_rule) # Add integer variables if necessary if (len(integer_vars)): add_integrality_constraints(model, integer_vars) # Add categorical variables if necessary if (categorical_info is not None and categorical_info[2]): add_categorical_constraints(model, *categorical_info) return model # -- end function ``` ```python assert(isinstance(var_lower, np.ndarray)) assert(isinstance(var_upper, np.ndarray)) assert(isinstance(integer_vars, np.ndarray)) assert(isinstance(node_pos, np.ndarray)) assert(isinstance(rbf_lambda, np.ndarray)) assert(isinstance(rbf_h, np.ndarray)) assert(len(var_lower) == n) assert(len(var_upper) == n) assert(len(rbf_lambda) == k) assert(len(rbf_h) == 0) assert(len(node_pos) == k) assert(isinstance(settings, RbfoptSettings)) assert(ru.get_degree_polynomial(settings) == -1) assert(0 <= dist_weight <= 1) assert(dist_max >= dist_min >= 0) model = ConcreteModel() # Dimension of the space model.n = Param(initialize=n) model.N = RangeSet(0, model.n - 1) # Number of interpolation nodes model.k = Param(initialize=k) model.K = RangeSet(0, model.k - 1) ``` -------------------------------- ### Define schoen_6_2_int configuration Source: https://rbfopt.readthedocs.io/en/latest/_modules/rbfopt_test_functions.html Sets up the data arrays, bounds, and variable types for the schoen_6_2_int function. ```python z = np.array( [[0.298854, 0.181010, 0.984817, 0.125272, 0.548396, 0.894658], [0.800371, 0.817380, 0.398577, 0.652349, 0.250843, 0.130235], [0.268631, 0.929778, 0.640422, 0.462004, 0.492930, 0.434955], [0.257863, 0.729198, 0.210810, 0.364378, 0.228216, 0.947432], [0.767627, 0.592150, 0.103788, 0.696895, 0.472449, 0.244504], [0.369630, 0.110889, 0.072344, 0.515753, 0.068087, 0.103057], [0.425457, 0.807081, 0.491209, 0.449497, 0.065690, 0.592775], [0.544229, 0.619841, 0.704609, 0.573098, 0.044844, 0.305800], [0.164031, 0.722884, 0.670496, 0.517915, 0.176386, 0.921565], [0.153788, 0.703577, 0.899129, 0.406134, 0.941356, 0.538215], [0.984781, 0.510479, 0.573361, 0.884599, 0.399472, 0.712935], [0.488416, 0.403997, 0.888823, 0.048434, 0.265197, 0.478025], [0.047985, 0.280071, 0.709960, 0.278919, 0.035737, 0.037699], [0.656172, 0.498412, 0.458622, 0.982970, 0.041234, 0.921127], [0.590802, 0.359690, 0.396516, 0.338153, 0.320793, 0.847369], [0.649160, 0.846974, 0.451818, 0.064864, 0.818545, 0.955844], [0.583716, 0.669610, 0.463098, 0.492710, 0.989690, 0.002397], [0.097300, 0.112389, 0.128759, 0.182995, 0.262808, 0.701887], [0.487363, 0.892520, 0.269056, 0.116046, 0.905416, 0.808013], [0.908316, 0.023997, 0.670399, 0.985859, 0.178548, 0.450410], [0.230409, 0.381732, 0.613667, 0.697260, 0.016950, 0.736507], [0.132544, 0.526349, 0.650042, 0.084086, 0.979257, 0.771499], [0.872978, 0.008826, 0.587481, 0.624637, 0.623175, 0.939539], [0.447828, 0.836386, 0.223285, 0.422756, 0.344488, 0.555953], [0.546839, 0.153934, 0.953017, 0.640891, 0.666774, 0.647583], [0.762237, 0.608920, 0.401447, 0.056202, 0.203535, 0.890609], [0.655150, 0.444544, 0.495582, 0.247926, 0.155128, 0.188004], [0.481813, 0.387178, 0.597276, 0.634671, 0.285404, 0.714793], [0.976385, 0.018854, 0.262585, 0.640434, 0.086314, 0.669879], [0.120164, 0.882300, 0.057626, 0.695111, 0.735135, 0.004711], [0.414644, 0.715618, 0.642033, 0.770645, 0.407019, 0.502945], [0.257475, 0.620029, 0.840603, 0.638546, 0.636521, 0.883558], [0.788980, 0.374926, 0.448016, 0.081941, 0.225763, 0.944905], [0.661591, 0.178832, 0.790349, 0.141653, 0.424235, 0.571960], [0.546361, 0.624907, 0.190470, 0.412713, 0.124748, 0.662788], [0.226384, 0.065829, 0.960836, 0.767766, 0.089695, 0.441792], [0.303675, 0.370047, 0.973692, 0.830432, 0.424719, 0.173571], [0.548375, 0.823234, 0.334253, 0.078398, 0.097269, 0.195120], [0.646225, 0.100478, 0.723833, 0.891035, 0.386094, 0.360272], [0.362757, 0.114700, 0.731020, 0.783785, 0.250399, 0.244399], [0.904335, 0.869074, 0.479004, 0.525872, 0.359411, 0.338333], [0.563175, 0.245903, 0.694417, 0.833524, 0.205055, 0.132535], [0.401356, 0.920963, 0.401902, 0.120625, 0.765834, 0.381552], [0.769562, 0.279591, 0.567598, 0.017192, 0.697366, 0.813451], [0.738572, 0.984740, 0.007616, 0.005382, 0.592976, 0.771773], [0.683721, 0.824097, 0.731623, 0.936945, 0.182420, 0.393537], [0.375859, 0.541929, 0.974640, 0.377459, 0.754060, 0.019335], [0.4, 0.6, 0.1, 0.4, 0.637412, 0.204038], [0.5, 0.4, 0.4, 0.0, 0.198525, 0.074668], [0.7, 0.1, 0.3, 0.5, 0.143614, 0.961610]]) f = np.array( [672.2, 861.4, 520.9, 121.0, 11.5, 48.2, 702.4, 536.2, 457.7, 801.3, 787.7, 768.6, 292.4, 960.0, 573.1, 303.7, 283.3, 474.1, 216.9, 462.2, 853.6, 677.1, 464.6, 830.6, 831.8, 109.6, 967.6, 122.9, 896.2, 490.2, 710.4, 81.1, 802.9, 999.8, 945.5, 672.3, 712.9, 235.8, 266.5, 772.4, 326.6, 585.5, 16.9, 135.9, 224.2, 382.1, 614.6, -1000, -1000, -1000]) dimension = 6 var_lower = np.array([0 for i in range(6)]) var_upper = np.array([10 for i in range(6)]) optimum_point = np.array([04., 06., 01., 04., 06.37412, 02.04038]) optimum_value = -1000 var_type = np.array(['I'] * 4 + ['R'] * 2) ```