src.baseline.bbo.de¶
Module Contents¶
Classes¶
API¶
- class src.baseline.bbo.de.DE(config)[source]¶
Bases:
src.environment.optimizer.basic_optimizer.Basic_OptimizerIntroduction¶
Differential Evolution (DE) optimizer implementation based on the DEAP framework.
This class inherits fromBasic_Optimizerand provides an evolutionary algorithm for global optimization, supporting logging and optional metadata collection.Initialization
Introduction¶
Initializes the Differential Evolution (DE) optimizer with the config object from src/config.py.
Args:¶
config (object): config object from src/config.py containing algorithm parameters and metadata options.
The Attributes needed for the DE are the following:
log_interval (int): Interval at which logs are recorded.
n_logpoint (int): Number of log points to record. Needed in run_episode(). Default is 50.
full_meta_data (bool): Flag indicating whether to use full meta data.Default is False.
__FEs (int): Counter for the number of function evaluations. Needed in run_episode(). Default is 0.
NP (int): Set the Population size in the config to 50.
F (float):Set the Differential parameter in the config to 0.5.
Cr(float): Set the Crossover parameter in the config to 0.5.
Attributes:¶
__config (object): Configuration object containing algorithm parameters.
__toolbox (object): DEAP toolbox for evolutionary algorithms.
__creator (object): DEAP creator for defining custom types.
Side Effects:¶
Modifies
configby settingNP,F, andCrattributes.Initializes internal attributes for further use in the class.
- __str__()[source]¶
Returns a string representation of the object.
Returns:¶
str: The string “DE” representing the object.
- run_episode(problem)[source]¶
Introduction¶
Executes a single optimization episode using a Differential Evolution (DE) algorithm on the provided problem instance. The method initializes the population, evaluates individuals, applies mutation and crossover, and tracks the best solution found. Optionally, it collects metadata for each generation.
Args:¶
problem: An object representing the optimization problem. It must have the following attributes:
lb(float or array-like): Lower bound(s) of the search space.ub(float or array-like): Upper bound(s) of the search space.dim(int): Dimensionality of the problem.eval(x)(callable): Function to evaluate a solutionx.optimum(float or None): Known optimum value (optional).
Returns:¶
dict: A dictionary containing:
cost(list of float): Best fitness value found at each logging interval.fes(int): Total number of function evaluations performed.metadata(dict, optional): Ifself.full_meta_datais True, includes:X(list of np.ndarray): Population snapshots at each generation.Cost(list of np.ndarray): Fitness values of the population at each generation.
Raises:¶
AttributeError: If required attributes are missing from the
problemobject.Exception: Propagates exceptions raised during evaluation or population initialization.