src.baseline.bbo.jde21¶
Module Contents¶
Classes¶
Introduction¶A DE for solving single-objective real-parameter bound-constrained optimization problems. It uses several mechanisms to tackle optimization problems efficiently: two populations with different sizes, restart mechanism in both populations, self-adaptive control parameters F and CR, the extended range of values for CR in thebigger population, migration of the best individual from the big population into the small population, modified mutation strategy in the bigger population, crowding mechanism and population size reduction in the bigger population. |
API¶
- class src.baseline.bbo.jde21.JDE21(config)[source]¶
Bases:
src.environment.optimizer.basic_optimizer.Basic_OptimizerIntroduction¶
A DE for solving single-objective real-parameter bound-constrained optimization problems. It uses several mechanisms to tackle optimization problems efficiently: two populations with different sizes, restart mechanism in both populations, self-adaptive control parameters F and CR, the extended range of values for CR in thebigger population, migration of the best individual from the big population into the small population, modified mutation strategy in the bigger population, crowding mechanism and population size reduction in the bigger population.
Original paper¶
“Self-adaptive differential evolution algorithm with population size reduction for single objective bound-constrained optimization: Algorithm j21.” 2021 IEEE Congress on Evolutionary Computation (CEC). IEEE, 2021.
Initialization
Introduction¶
Initializes the JDE21 optimizer with configuration parameters and sets up internal variables according to the JDE21 algorithm.
Args:¶
config (object): Configuration object containing algorithm parameters.
The Attributes needed for the JDE21 optimizer in config are the following:
maxFEs (int): Maximum number of function evaluations allowed. Default value depends on the type of the problem.
n_logpoint (int): Number of log points for tracking progress. Default is 50.
log_interval (int): Interval at which logs are recorded. Default is maxFEs // n_logpoint.
full_meta_data (bool): Flag indicating whether to store complete solution history. Default is False.
seed (int): Random seed for reproducibility. Used for initializing populations and control parameters.
Attributes:¶
__sNP (int): Size of the small population. Default is 10.
__bNP (int): Size of the big population. Default is 160.
__NP (int): Total population size. Default is 170.
__tao1 (float): Parameter for mutation strategy. Default is 0.1.
__tao2 (float): Parameter for crossover strategy. Default is 0.1.
__Finit (float): Initial scaling factor. Default is 0.5.
__CRinit (float): Initial crossover rate. Default is 0.9.
__Fl_b (float): Lower bound for scaling factor in big population. Default is 0.1.
__Fl_s (float): Lower bound for scaling factor in small population. Default is 0.17.
__Fu (float): Upper bound for scaling factor. Default is 1.1.
__CRl_b (float): Lower bound for crossover rate in big population. Default is 0.0.
__CRl_s (float): Lower bound for crossover rate in small population. Default is 0.1.
__CRu_b (float): Upper bound for crossover rate in big population. Default is 1.1.
__CRu_s (float): Upper bound for crossover rate in small population. Default is 0.8.
Notes:¶
The meaning and usage of the parameters are based on the JDE21 paper. This constructor prepares all necessary internal state for running the JDE21 optimization algorithm.
- __str__()[source]¶
Returns the string representation of the JDE21 class.
Returns:¶
str: The string ‘JDE21’.
- __prevecEnakih(cost, best)[source]¶
Introduction¶
Determines if there are a significant number of elements in
costthat are approximately equal tobest, based on specified tolerances.Args:¶
cost (np.ndarray): Array of cost values.
best (float): The reference value to compare against.
Returns:¶
bool: True if the number of elements in
costclose tobestexceeds both 2 and a fraction (__MyEps) of the total number of elements; otherwise, False.
- __crowding(group, vs)[source]¶
Introduction¶
Computes the index of the closest vector in
vsto each vector ingroupbased on squared Euclidean distance.Args:¶
group (np.ndarray): An array representing a group of vectors, shape (NP, dim).
vs (np.ndarray): An array of vectors to compare against, shape (NP, dim).
Returns:¶
np.ndarray: An array of indices indicating, for each vector in
group, the index of the closest vector invs.
Notes:¶
The function assumes that
groupandvshave the same shape.
- __evaluate(problem, Xs)[source]¶
Introduction¶
Evaluates the cost of a solution or set of solutions
Xsfor a given optimizationproblem, optionally normalizing by the problem’s known optimum. Also stores meta-data if enabled.Args:¶
problem:The problem object representing the optimization problem.
Xs: The candidate solution(s) to be evaluated, typically as a NumPy array or compatible structure.
Returns:¶
cost: The evaluated cost(s) of the solution(s).
Notes:¶
If
self.full_meta_dataisTrue, the method appends the cost and solution to internal meta-data lists.
- __sort()[source]¶
Introduction¶
Sorts the population and corresponding cost arrays in ascending order based on the cost values.
Args:¶
None
Returns:¶
None
Side Effects:¶
Updates
self.__costandself.__populationso that both are sorted according to the ascending order ofself.__cost.
- __reinitialize(size, problem)[source]¶
Introduction¶
Reinitializes a population of candidate solutions within the problem’s bounds using uniform random sampling.
Args:¶
size (int): The number of candidate solutions to generate.
problem (object): The problem object representing the optimization problem. Must have the following attributes:
dim (int): Dimensionality of the problem.
ub (float or np.ndarray): Upper bound(s) for each dimension.
lb (float or np.ndarray): Lower bound(s) for each dimension.
Returns:¶
np.ndarray: An array of shape (size, problem.dim) containing the reinitialized candidate solutions.
Notes:¶
The method uses the instance’s random number generator (
self.rng) to ensure reproducibility.
- __init_population(problem)[source]¶
Introduction¶
Initializes the population and related attributes for the evolutionary optimization algorithm.
Args:¶
problem (object): The problem object representing the optimization problem.
Side Effects:¶
Initializes the population matrix with random values within the problem bounds.
Evaluates the initial population and stores their costs.
Sets up internal counters and parameters for the algorithm, such as population size, best cost, scaling factors, and crossover rates.
Initializes logging variables for tracking optimization progress.
Attributes Set:¶
__sNP (int): Size of the small population.Default is 10.
__bNP (int): Size of the big population. Default is 160.
__NP (int): Total population size. Default is 170.
__population (np.ndarray): The initial population matrix, shape (NP, problem.dim).
__cost (np.ndarray): The cost of each individual in the population, shape (NP,).
__FEs (int): Total number of function evaluations performed. Initialized to NP.
__cbest (float): The best cost found so far.
__cbest_id (int): The index of the best individual in the population.
__F (np.ndarray): Scaling factors for each individual in the population, shape (NP,).
__Cr (np.ndarray): Crossover rates for each individual in the population, shape (NP,).
log_index (int): Index for logging progress, initialized to 1.
cost (list): List to store the best cost found at each logging interval.
- __update(problem)[source]¶
Introduction¶
Performs one iteration of the population update for a differential evolution algorithm variant (likely NL-SHADE-RSP), including mutation, crossover, selection, population reinitialization, and population reduction. Handles both “big” and “small” subpopulations, manages best solution tracking, and logs progress.
Args:¶
problem: The problem object, which must provide at least the following attributes:
dim (int): Dimensionality of the problem.
lb (array-like): Lower bounds for each dimension.
ub (array-like): Upper bounds for each dimension.
optimum (optional): The known optimum value for early stopping (can be None).
Returns:¶
None
- run_episode(problem)[source]¶
Introduction¶
Executes a single optimization episode for the given problem, managing population initialization, iterative updates, and result logging. Optionally collects and returns full meta-data for analysis.
Args:¶
problem (object): The optimization problem instance to be solved. Must provide necessary interfaces for population initialization and evaluation.
Returns:¶
dict: A dictionary containing:
‘cost’ (list): The cost history or best cost found during the episode.
‘fes’ (int): The number of function evaluations performed.
‘metadata’ (dict, optional): Contains ‘X’ (list of solutions) and ‘Cost’ (list of costs) if
full_meta_datais enabled.
Notes:¶
The method resets and initializes the population at the start of each episode.
Iteratively updates the population until the maximum number of function evaluations is reached.
Logs the best solution and optionally collects detailed meta-data for further analysis.