src.baseline.bbo.moead¶
Module Contents¶
Classes¶
Introduction¶MOEAD is a multiobjective evolutionary algorithm based on decomposition.It decomposes a multiobjective optimization problem into a number of scalar optimization subproblems and optimizes them simultaneously. Each subproblem is optimized by only using information from its several neighboring subproblems. |
|
Introduction¶The |
|
Introduction¶Represents the Inverted Generational Distance (IGD) indicator, which measures the average distance from points in a reference set to their nearest point in a given solution set. IGD is commonly used in multi-objective optimization to assess how well a set of solutions approximates the true Pareto front. |
Functions¶
Introduction¶Calculates the Chebyshev (Tchebycheff) fitness value for a multi-objective solution, assuming all objectives are to be minimized. This metric is commonly used in multi-objective optimization to aggregate multiple objectives into a single scalar value, emphasizing the worst (maximum) weighted deviation from the ideal point. |
|
Introduction¶Calculates the Penalty-based Boundary Intersection (PBI) fitness value for a solution in multi-objective optimization, assuming all objectives are to be minimized. This metric is commonly used in decomposition-based evolutionary algorithms such as MOEA/D. |
|
Introduction¶Calculates the minimum Euclidean distance between a given solution’s objective vector and a set of other objective vectors. |
|
Introduction¶Computes the Euclidean (L2) distance between two vectors |
|
Introduction¶This function scales each objective in the input solution array to the [0, 1] range using provided or computed minimum and maximum values for each objective. If minimum or maximum bounds are not provided, they are computed from the input data. |
|
Introduction¶Safely extends or appends items to a list, handling various input types such as lists, NumPy arrays, or single elements. |
Data¶
API¶
- class src.baseline.bbo.moead.MOEAD(config)[source]¶
Bases:
src.environment.optimizer.basic_optimizer.Basic_OptimizerIntroduction¶
MOEAD is a multiobjective evolutionary algorithm based on decomposition.It decomposes a multiobjective optimization problem into a number of scalar optimization subproblems and optimizes them simultaneously. Each subproblem is optimized by only using information from its several neighboring subproblems.
Original paper¶
“MOEA/D: A multiobjective evolutionary algorithm based on decomposition.” IEEE Transactions on Evolutionary Computation 11.6 (2007): 712-731.
Official Implementation¶
None
Initialization
Initializes the MOEA/D algorithm with the provided configuration.
Introduction¶
Sets up problem-related and algorithm-specific parameters for the MOEA/D (Multi-Objective Evolutionary Algorithm based on Decomposition) baseline implementation.
Args:¶
config (object): Config object containing algorithm and problem settings.
The Attributes needed for the MOEAD are the following:
maxFEs (int): Maximum number of function evaluations allowed.
n_logpoint (int): Number of log points to record.Default is 50.
log_interval (int): Interval at which logs are recorded.Default is config.maxFEs/config.n_logpoint.
Built-in Attributes:¶
self.n_ref_points(int): Number of reference points for the algorithm. Default is 1000.self.population_size(int): Size of the population.Default is 100.self.moead_neighborhood_size(int): Size of the neighborhood for each subproblem.Default is 8.self.moead_neighborhood_maxsize(int): Maximum size of the neighborhood.Default is 30.self.moead_delta(float): Probability of using the neighborhood for mating.Default is 0.8.self.moead_eta(int): Number of neighbors to consider for solution replacement.Default is 2.self.max_fes(int): Maximum number of function evaluations allowed.Default is config.maxFEs.
Raises:¶
AttributeError: If
configdoes not contain the required attributes.
- __str__()[source]¶
Introduction¶
Returns the string representation of the MOEAD class.
Returns:¶
str: The string ‘MOEAD’, representing the name of the class.
- init_population(problem)[source]¶
Introduction¶
Initializes the population and related attributes for the MOEA/D (Multi-Objective Evolutionary Algorithm based on Decomposition) algorithm.
Args:¶
problem (object): An instance representing the optimization problem, which must provide attributes such as
n_obj(number of objectives),dim(number of variables),lb(lower bounds),ub(upper bounds), and methods likeeval()andget_ref_set().
Built-in Attribute:¶
self.problem: Stores the problem instance.
self.n_obj: Number of objectives.
self.n_var: Number of decision variables.
self.weights: Weight vectors for decomposition.
self.population_size: Number of individuals in the population.
self.population: The initialized population of solutions.
self.population_obj: Objective values of the population.
self.neighborhoods: Neighborhood structure for each individual.
self.done: Boolean flag indicating if the optimization is finished.
self.fes: Number of function evaluations so far.
self.episode_limit: Maximum number of generations (episodes).
self.moead_generation: Current generation counter.
self.archive_maximum: Maximum objective values found so far.
self.archive_minimum: Minimum objective values found so far.
self.ideal_point: Current ideal point in the objective space.
self.problem_ref_points: Reference points for performance indicators.
self.igd_his: History of IGD (Inverted Generational Distance) values.
self.initial_igd: IGD value at initialization.
self.last_igd: Most recent IGD value.
self.best_igd: Best IGD value found so far.
self.hv_his: History of HV (Hypervolume) values.
self.initial_hv: HV value at initialization.
self.last_hv: Most recent HV value.
self.best_hv: Best HV value found so far.
self.metadata: Dictionary for storing additional metadata.
Returns:¶
None
Raises:¶
None
- get_neighborhoods()[source]¶
Introduction¶
Computes the neighborhoods for each weight vector in the MOEA/D algorithm by sorting all weight vectors according to their distance to the current weight and selecting the closest ones.
Returns:¶
list[list[int]]: A list where each element contains the indices of the nearest neighbors for the corresponding weight vector.
Notes:¶
The number of neighbors is determined by
self.moead_neighborhood_maxsize.The sorting of weights is performed using
self.moead_sort_weights.
- get_weights(n_obj)[source]¶
Introduction¶
Generates a set of weight vectors for multi-objective optimization based on the number of objectives.
Args:¶
n_obj (int): The number of objectives for which the weight vectors are to be generated.
Returns:¶
np.ndarray: An array of weight vectors suitable for the specified number of objectives.
Notes:¶
For specific values of
n_obj(2, 3, 5, 7, 8, 10), predefined boundary weights are generated usingnormal_boundary_weightswith preset parameters.For other values of
n_obj, random weights are generated usingrandom_weightswith the current population size.
- moead_update_ideal(solution_obj)[source]¶
Introduction¶
Updates the ideal point in the MOEA/D algorithm based on a new solution’s objective values.
Args:¶
solution_obj (np.ndarray): A 1D array containing the objective values of the new solution.
Built-in Attribute:¶
self.ideal_point (np.ndarray): The current ideal point vector, updated in-place.
Returns:¶
None
Raises:¶
IndexError: If the dimensions of
solution_objdo not matchself.ideal_point.
- run_episode(problem)[source]¶
Introduction¶
Executes one episode of the MOEA/D (Multi-Objective Evolutionary Algorithm based on Decomposition) optimization process for a given problem instance. This involves initializing the population, generating offspring through crossover and mutation, evaluating solutions, updating ideal points and solutions, and tracking performance metrics such as IGD (Inverted Generational Distance) and HV (Hypervolume).
Args:¶
problem (object): The optimization problem instance, which must provide an
evalmethod for evaluating solutions.
Built-in Attribute:¶
self.population (list): The current population of solutions.
self.fes (int): The number of function evaluations performed.
self.max_fes (int): The maximum number of function evaluations allowed.
self.done (bool): Indicates whether the optimization process is complete.
self.offspring_list (list): Stores the offspring generated in the current episode.
self.offspring_obj_list (list): Stores the objective values of the offspring.
self.moead_generation (int): The current generation count.
self.last_igd (float): The IGD value of the last generation.
self.best_igd (float): The best IGD value observed so far.
self.last_hv (float): The HV value of the last generation.
self.best_hv (float): The best HV value observed so far.
self.cost (float): The cost associated with the optimization process.
self.metadata (dict): Additional metadata collected during optimization.
self.hv_his (list): History of HV values.
self.igd_his (list): History of IGD values.
Returns:¶
dict: A dictionary containing the final cost, number of function evaluations, metadata, and histories of HV and IGD values when the episode is complete.
Raises:¶
None explicitly, but may raise exceptions if the problem instance or internal methods are misconfigured.
- update_information()[source]¶
Introduction¶
Updates the internal state of the object by identifying the non-dominated solutions (Pareto front) in the current population and storing relevant metadata.
Args:¶
None
Built-in Attribute:¶
self.population_obj (list): Objective values of the current population.
self.population (list): Current population of solutions.
self.metadata (dict): Dictionary to store historical populations and objective values.
self.cost (list): Stores the current Pareto front objective values.
Returns:¶
None
Raises:¶
None
- find_non_dominated_indices(population_list)[source]¶
Introduction¶
Identifies the indices of non-dominated solutions (Pareto optimal solutions) in a given population based on their objective values.
Args:¶
population_list (List[List[float]]): A list where each element is a list representing the objective values of a solution in the population.
Returns:¶
np.ndarray: An array of indices corresponding to the non-dominated solutions in the population.
Raises:¶
None
- moead_calculate_fitness(solution_obj, weights)[source]¶
Introduction¶
Calculates the fitness value of a solution in the MOEA/D algorithm using the Chebyshev scalarizing function.
Args:¶
solution_obj (list or np.ndarray): The objective values of the solution to be evaluated.
weights (list or np.ndarray): The weight vector associated with the subproblem.
Built-in Attribute:¶
self.ideal_point (list or np.ndarray): The ideal point in the objective space, used as a reference for scalarization.
Returns:¶
float: The computed fitness value of the solution based on the Chebyshev approach.
Raises:¶
None
- moead_update_solution(solution, solution_obj, mating_indices)[source]¶
Introduction¶
Updates the MOEA/D population by potentially replacing individuals in the mating set with a new solution if it improves the scalarized fitness value under the corresponding weight vector.
Args:¶
solution (Any): The candidate solution to potentially insert into the population.
solution_obj (Any): The objective values associated with the candidate solution.
mating_indices (List[int]): Indices of population members considered for replacement.
Returns:¶
None
Notes:¶
The method shuffles the mating indices, then iterates through them, replacing individuals if the new solution yields a better scalarized fitness.
Replacement stops after
self.moead_etasuccessful replacements.
- static moead_sort_weights(base, weights)[source]¶
Introduction¶
Sorts a list of weight vectors by their Euclidean distance to a given base weight vector, returning the indices of the weights in ascending order of distance.
Args:¶
base (list[float]): The reference weight vector to which distances are computed.
weights (list[list[float]]): A list of weight vectors to be sorted.
Returns:¶
list[int]: A list of indices representing the order of
weightssorted by increasing distance tobase.
Raises:¶
ValueError: If the dimensions of
baseand any weight vector inweightsdo not match.
- moead_get_subproblems()[source]¶
Introduction¶
Determines the order of subproblems to be searched in the MOEA/D algorithm. If utility-based updating is enabled, it follows the utility-based search; otherwise, it uses the original MOEA/D specification.
Returns:¶
list[int]: A shuffled list of indices representing the subproblems to be searched.
Built-in Attribute:¶
self.population_size (int): The total number of subproblems (population size).
self.rng (random.Random): Random number generator used for shuffling.
- moead_get_mating_indices(index)[source]¶
Introduction¶
Determines the mating indices for the MOEA/D algorithm based on the current individual’s index.
With probability
moead_delta, the method returns the neighborhood indices for the given individual; otherwise, it returns the indices of the entire population.Args:¶
index (int): The index of the current individual in the population.
Built-in Attribute:¶
self.rng (np.random.Generator): Random number generator for stochastic decisions.
self.moead_delta (float): Probability of selecting the neighborhood.
self.neighborhoods (List[List[int]]): Precomputed neighborhoods for each individual.
self.moead_neighborhood_size (int): Number of neighbors to consider.
self.population_size (int): Total number of individuals in the population.
Returns:¶
List[int]: Indices of individuals considered for mating (either the neighborhood or the entire population).
- get_hv(n_samples=100000.0)[source]¶
Introduction¶
Computes the hypervolume (HV) indicator for the current population of solutions, either exactly or approximately, depending on the problem’s dimensionality and population size.
Args:¶
n_samples (int, optional): Number of Monte Carlo samples to use for HV estimation when using the approximate method. Defaults to 1e5.
Returns:¶
float: The computed or estimated hypervolume value for the current population.
Details:¶
If the number of objectives (
self.problem.n_obj) is 3 or fewer, or the population size is 50 or fewer, the exact hypervolume is calculated.Otherwise, the hypervolume is estimated using a Monte Carlo sampling approach for efficiency.
Raises:¶
AssertionError: If the normalized population objectives are not all less than 1 during the approximate calculation.
- get_igd()[source]¶
Introduction¶
Calculates the Inverted Generational Distance (IGD) between the current population objectives and a reference set, appends the result to the IGD history, and returns the computed IGD value.
Args:¶
None
Returns:¶
float: The calculated IGD value for the current population.
Raises:¶
Any exception raised by the
InvertedGenerationalDistancecalculation if the input data is invalid.
- close()[source]¶
Introduction¶
Closes the current instance by resetting its internal state.
Args:¶
None
Returns:¶
None
Raises:¶
None
- normal_boundary_weights(nobjs, divisions_outer, divisions_inner=0)[source]¶
Introduction¶
Generates a set of uniformly distributed weight vectors on the unit simplex using the normal boundary intersection method. This is commonly used in multi-objective optimization algorithms such as MOEA/D to decompose the objective space.
Args:¶
nobjs (int): The number of objectives (dimensions) for which to generate the weights.
divisions_outer (int): The number of divisions for the outer set of weights, controlling the granularity of the weight vectors on the simplex boundary.
divisions_inner (int, optional): The number of divisions for the inner set of weights, used to generate additional weights inside the simplex. Defaults to 0 (no inner weights).
Returns:¶
list[list[float]]: A list of weight vectors, where each vector is a list of floats summing to 1, representing a point on the unit simplex.
Notes:¶
The outer weights are distributed on the boundary of the simplex, while the optional inner weights are distributed inside the simplex and averaged with the uniform vector.
Useful for decomposition-based multi-objective evolutionary algorithms.
- random_weights(nobjs, population_size)[source]¶
Introduction¶
Generates a set of randomly-generated but uniformly distributed weight vectors for multi-objective optimization. This method ensures that the generated weights are as uniformly distributed as possible by maximizing the minimum distance between selected weights. For two objectives, weights are generated directly. For more than two objectives, a large pool of candidate weights is created, and the most distant candidates are iteratively selected.
Args:¶
nobjs (int): The number of objectives (dimensions) for the weight vectors.
population_size (int): The number of weight vectors to generate.
Returns:¶
list[list[float]]: A list of weight vectors, each of length
nobjs, where each vector sums to 1.
Raises:¶
None explicitly, but may raise exceptions if invalid arguments are provided (e.g., population_size < nobjs).
- sbx(problem, parents, probability=1.0, distribution_index=20.0)[source]¶
Introduction¶
Performs Simulated Binary Crossover (SBX) on a pair of parent solutions to generate two offspring solutions for evolutionary algorithms. SBX is commonly used in real-coded genetic algorithms to recombine parent solutions while preserving variable bounds.
Args:¶
problem: An object representing the optimization problem, which must have the following attributes:
dim (int): The number of decision variables.
lb (list or array-like): Lower bounds for each variable.
ub (list or array-like): Upper bounds for each variable.
parents (list): A list containing two parent solutions (each as a list or array-like of variable values).
probability (float, optional): The probability of applying crossover to the parents. Defaults to 1.0.
distribution_index (float, optional): The distribution index (η) controlling the spread of offspring. Higher values result in offspring closer to parents. Defaults to 20.0.
Returns:¶
list: A list containing two offspring solutions (each as a list of variable values).
Notes:¶
The method uses a random number generator (
self.rng) for stochastic operations.Variable values are clipped to remain within the specified bounds after crossover.
If crossover is not applied (based on
probability), the offspring are deep copies of the parents.
- pm(problem, parent, probability=1.0, distribution_index=20.0)[source]¶
Introduction¶
Applies the Polynomial Mutation (PM) operator to a parent solution vector for evolutionary algorithms, producing a mutated child solution. This operator introduces diversity by perturbing solution variables within their bounds according to a specified probability and distribution index.
Args:¶
problem: An object representing the optimization problem, expected to have attributes
dim(int, number of dimensions),lb(list or array of lower bounds), andub(list or array of upper bounds).parent (list or array-like): The parent solution vector to be mutated.
probability (float, optional): The overall mutation probability (default is 1.0). The per-variable mutation probability is computed as
probability / problem.dim.distribution_index (float, optional): The distribution index controlling the spread of the mutation (default is 20.0). Higher values result in smaller mutations.
Returns:¶
child (list): A new solution vector resulting from applying polynomial mutation to the parent.
Notes:¶
The method uses a random number generator
self.rngfor stochasticity.Each variable in the parent has an independent chance to be mutated.
The mutated values are clipped to remain within the specified bounds.
- src.baseline.bbo.moead.chebyshev(solution_obj, ideal_point, weights, min_weight=0.0001)[source]¶
Introduction¶
Calculates the Chebyshev (Tchebycheff) fitness value for a multi-objective solution, assuming all objectives are to be minimized. This metric is commonly used in multi-objective optimization to aggregate multiple objectives into a single scalar value, emphasizing the worst (maximum) weighted deviation from the ideal point.
Args:¶
solution_obj (np.ndarray or list of float): The objective values of the solution.
ideal_point (list of float): The ideal (best known) values for each objective.
weights (list of float): The weights assigned to each objective.
min_weight (float, optional): The minimum allowable weight for any objective (default is 0.0001).
Returns:¶
float: The Chebyshev fitness value, representing the maximum weighted deviation from the ideal point.
Raises:¶
IndexError: If the lengths of
solution_obj,ideal_point, orweightsdo not match.
- src.baseline.bbo.moead.pbi(solution_obj, ideal_point, weights, theta=5)[source]¶
Introduction¶
Calculates the Penalty-based Boundary Intersection (PBI) fitness value for a solution in multi-objective optimization, assuming all objectives are to be minimized. This metric is commonly used in decomposition-based evolutionary algorithms such as MOEA/D.
Args:¶
solution_obj (list or array-like of float): The objective values of the solution.
ideal_point (list or array-like of float): The ideal (reference) point in the objective space.
weights (list or array-like of float): The weight vector associated with the subproblem.
theta (float, optional): The penalty parameter controlling the balance between convergence and diversity (default is 5).
Returns:¶
float: The computed PBI fitness value for the given solution.
Raises:¶
ImportError: If numpy is not installed.
- class src.baseline.bbo.moead.Hypervolume(reference_set=None, minimum=None, maximum=None)[source]¶
Bases:
src.baseline.bbo.moead.IndicatorIntroduction¶
The
Hypervolumeclass is an indicator used to calculate the hypervolume metric for multi-objective optimization problems. The hypervolume measures the volume of the objective space dominated by a set of solutions, bounded by a reference point. This implementation is specifically designed for minimization problems.Initialization
Initializes the Hypervolume object with either a reference set or explicit minimum and maximum values.
Args:¶
reference_set (array-like, optional): A set of reference points used for normalization. If provided,
minimumandmaximummust not be specified.minimum (array-like, optional): The minimum values for normalization. Must be specified if
reference_setis not provided.maximum (array-like, optional): The maximum values for normalization. Must be specified if
reference_setis not provided.
Returns:¶
None
Raises:¶
ValueError: If both
reference_setand (minimumormaximum) are specified.ValueError: If neither
reference_setnor bothminimumandmaximumare specified.
- invert(solution_normalized_obj: src.environment.problem.MOO.MOO_synthetic.dtlz_numpy.np.ndarray)[source]¶
Introduction¶
Inverts the normalized objective values for each objective in the solution array. Each value is clipped to the [0.0, 1.0] range before inversion.
Args:¶
solution_normalized_obj (np.ndarray): A 2D NumPy array of shape (n_solutions, n_objectives) containing normalized objective values in the range [0.0, 1.0].
Returns:¶
np.ndarray: The input array with each objective value inverted (i.e., 1.0 - value).
Raises:¶
None
- dominates(solution1_obj, solution2_obj, nobjs)[source]¶
Introduction¶
Determines whether the first solution dominates the second solution in a multi-objective optimization context.
Args:¶
solution1_obj (list or array-like): Objective values of the first solution.
solution2_obj (list or array-like): Objective values of the second solution.
nobjs (int): Number of objectives.
Returns:¶
bool: True if
solution1_objdominatessolution2_obj, False otherwise.
Notes:¶
Dominance is determined by comparing each objective value. The function assumes a maximization problem, where higher objective values are better.
- swap(solutions_obj, i, j)[source]¶
Introduction¶
Swaps the positions of two elements in the given solutions object at indices
iandj.Args:¶
solutions_obj (array-like): The collection (e.g., numpy array) containing the solutions.
i (int): The index of the first element to swap.
j (int): The index of the second element to swap.
Returns:¶
array-like: The solutions object with the elements at indices
iandjswapped.
Raises:¶
IndexError: If
iorjare out of bounds forsolutions_obj.
- filter_nondominated(solutions_obj, nsols, nobjs)[source]¶
Introduction¶
Filters out dominated solutions from a set of solutions based on their objective values, leaving only the non-dominated (Pareto optimal) solutions.
Args:¶
solutions_obj (list or np.ndarray): A collection of solution objective vectors to be filtered.
nsols (int): The number of solutions in the input collection.
nobjs (int): The number of objectives for each solution.
Returns:¶
int: The number of non-dominated solutions remaining after filtering.
Raises:¶
None
- surface_unchanged_to(solutions_normalized_obj, nsols, obj)[source]¶
Introduction¶
Computes the minimum value of a specified objective across a subset of normalized solutions.
Args:¶
solutions_normalized_obj (np.ndarray): A 2D array containing normalized objective values for all solutions.
nsols (int): The number of solutions to consider from the beginning of the array.
obj (int): The index of the objective to evaluate.
Returns:¶
float: The minimum value of the specified objective among the first
nsolssolutions.
Raises:¶
IndexError: If
objis out of bounds for the number of objectives insolutions_normalized_obj.ValueError: If
nsolsis greater than the number of available solutions.
- reduce_set(solutions, nsols, obj, threshold)[source]¶
Introduction¶
Reduces the set of solutions by removing those whose value for a specified objective is less than or equal to a given threshold. The removal is performed in-place by swapping qualifying solutions to the end of the array.
Args:¶
solutions (np.ndarray): Array of candidate solutions, where each row represents a solution and columns represent objective values.
nsols (int): The current number of solutions in the set.
obj (int): The index of the objective to be considered for threshold comparison.
threshold (float): The threshold value for the specified objective. Solutions with values less than or equal to this threshold are removed.
Returns:¶
int: The updated number of solutions after reduction.
Notes:¶
The function modifies the
solutionsarray in-place by swapping removed solutions to the end.
- calc_internal(solutions_obj: src.environment.problem.MOO.MOO_synthetic.dtlz_numpy.np.ndarray, nsols, nobjs)[source]¶
Introduction¶
Recursively calculates the hypervolume (or a similar metric) of a set of solutions in a multi-objective optimization context using a divide-and-conquer approach.
Args:¶
solutions_obj (np.ndarray): A 2D array containing the objective values of the solutions.
nsols (int): The number of solutions to consider from
solutions_obj.nobjs (int): The number of objectives.
Returns:¶
float: The calculated hypervolume (or related metric) for the given set of solutions.
Raises:¶
None explicitly, but may raise exceptions if input arrays are malformed or if called recursively with invalid parameters.
- calculate(solutions_obj: src.environment.problem.MOO.MOO_synthetic.dtlz_numpy.np.ndarray)[source]¶
Introduction¶
Calculates the hypervolume indicator for a set of solution objective values, considering only feasible solutions within normalized bounds.
Args:¶
solutions_obj (np.ndarray): A 2D array of shape (n_solutions, n_objectives) containing the objective values of the solutions.
Returns:¶
float: The computed hypervolume for the feasible solutions. Returns 0.0 if no feasible solutions are found.
Notes:¶
Solutions are first normalized using predefined minimum and maximum values.
Only solutions with all normalized objectives less than or equal to 1.0 are considered feasible.
The feasible solutions are inverted before hypervolume calculation.
- class src.baseline.bbo.moead.InvertedGenerationalDistance(reference_set)[source]¶
Bases:
src.baseline.bbo.moead.IndicatorIntroduction¶
Represents the Inverted Generational Distance (IGD) indicator, which measures the average distance from points in a reference set to their nearest point in a given solution set. IGD is commonly used in multi-objective optimization to assess how well a set of solutions approximates the true Pareto front.
Args:¶
reference_set (Iterable): The set of reference points (typically representing the true Pareto front) against which the solution set will be evaluated.
Methods:¶
calculate(set): Computes the IGD value for a given solution set.
set (Iterable): The solution set to be evaluated.
Returns:¶
float: The IGD value, representing the average distance from each reference point to its nearest solution in the set.
Raises:¶
ZeroDivisionError: If the reference set is empty, as division by zero will occur.
Initialization
- src.baseline.bbo.moead.distance_to_nearest(solution_obj, set)[source]¶
Introduction¶
Calculates the minimum Euclidean distance between a given solution’s objective vector and a set of other objective vectors.
Args:¶
solution_obj (array-like): The objective vector of the solution for which the nearest distance is to be calculated.
set (Iterable[array-like]): A collection of objective vectors to compare against.
Returns:¶
float: The smallest Euclidean distance between
solution_objand any element inset. ReturnsPOSITIVE_INFINITYifsetis empty.
Raises:¶
NameError: If
POSITIVE_INFINITYoreuclidean_distare not defined in the scope.
- src.baseline.bbo.moead.euclidean_dist(x, y)[source]¶
Introduction¶
Computes the Euclidean (L2) distance between two vectors
xandy. Both inputs must be either lists or NumPy arrays of equal length.Args:¶
x (list or numpy.ndarray): The first vector.
y (list or numpy.ndarray): The second vector.
Returns:¶
float: The Euclidean distance between
xandy.
Raises:¶
TypeError: If
xoryis not a list or numpy.ndarray.IndexError: If
xandyare not of the same length.
- src.baseline.bbo.moead.normalize(solutions_obj: src.environment.problem.MOO.MOO_synthetic.dtlz_numpy.np.ndarray, minimum: src.environment.problem.MOO.MOO_synthetic.dtlz_numpy.np.ndarray = None, maximum: src.environment.problem.MOO.MOO_synthetic.dtlz_numpy.np.ndarray = None) src.environment.problem.MOO.MOO_synthetic.dtlz_numpy.np.ndarray[source]¶
Introduction¶
This function scales each objective in the input solution array to the [0, 1] range using provided or computed minimum and maximum values for each objective. If minimum or maximum bounds are not provided, they are computed from the input data.
Args:¶
solutions_obj (np.ndarray): A 2D numpy array of shape (n_solutions, n_objectives) representing the objective values of solutions to be normalized.
minimum (np.ndarray, optional): A 1D numpy array of minimum values for each objective. If not provided, computed from
solutions_obj.maximum (np.ndarray, optional): A 1D numpy array of maximum values for each objective. If not provided, computed from
solutions_obj.
Returns:¶
np.ndarray: A 2D numpy array of the same shape as
solutions_obj, containing the normalized objective values.
Raises:¶
ValueError: If any objective has an empty range (i.e., maximum - minimum < EPSILON).
- src.baseline.bbo.moead.safe_extend(lst, items)[source]¶
Introduction¶
Safely extends or appends items to a list, handling various input types such as lists, NumPy arrays, or single elements.
Args:¶
lst (list): The list to which items will be added.
items (Any): The items to add. Can be None, a list, a NumPy ndarray, or a single element.
Returns:¶
None: The function modifies
lstin place and does not return a value.
Notes:¶
If
itemsis None, the function does nothing.If
itemsis a multi-dimensional list or ndarray, it extendslstwith its elements.If
itemsis a one-dimensional list or ndarray, it appends the entire object as a single element.For other types, it appends
itemsas a single element.