propulate.propagators.cmaes
Module Contents
Classes
Instantiate a |
|
Abstract base class for the adaption of strategy parameters of CMA-ES. |
|
Adaption of strategy parameters of CMA-ES according to the original CMA-ES algorithm. |
|
Adaption of strategy parameters of CMA-ES according to the active CMA-ES algorithm. |
|
Instantiate a CMA-ES propagator. |
- class propulate.propagators.cmaes.CMAParameter(lambd: int, mu: int, problem_dimension: int, weights: numpy.ndarray, mu_eff: float, c_c: float, c_1: float, c_mu: float, limits: Dict, initial_mean: numpy.ndarray, exploration: bool)
Instantiate a
CMAParameterobject.- Parameters:
lambd (int) – The number of individuals considered for each generation.
mu (int) – The number of positive recombination weights.
problem_dimension (int) – The number of dimensions in the search space.
weights (numpy.ndarray) – The recombination weights.
mu_eff (float) – The variance effective selection mass.
c_c (float) – The decay rate for the evolution path for the rank-one update of the covariance matrix.
c_1 (float) – The learning rate for the rank-one update of the covariance matrix update.
c_mu (float) – The learning rate for the rank-mu update of the covariance matrix update.
limits (dict) – The limits of the search space.
initial_mean (np.ndarray) – The initial mean of the distribution.
exploration (bool) – If True decompose covariance matrix for each generation (worse runtime, less exploitation, more
decompose_in_each_generation); else decompose covariance matrix only after a certain number of individuals evaluated (better runtime, more exploitation, lessdecompose_in_each_generation).
- update_mean(new_mean: numpy.ndarray) None
Update mean and old mean property.
- Parameters:
new_mean (numpy.ndarray) – The new mean.
- update_covariance_matrix(new_covariance_matrix: numpy.ndarray) None
Update the covariance matrix.
Computes new values for
b_matrix,d_matrix, andcovariance_inv_sqrt. Decomposition ofcovariance_matrixis O(n^3), hence the possibility of lazy updatingb_matrixandd_matrix.- Parameters:
new_covariance_matrix (numpy.ndarray) – The new covariance matrix.
- _decompose_co_matrix(new_co_matrix: numpy.ndarray) None
Eigen-decomposition of the covariance matrix into eigenvalues (d_matrix) and eigenvectors (columns of b_matrix).
- Parameters:
new_co_matrix (numpy.ndarray) – The new covariance matrix that should be decomposed.
- _limit_condition(limit: float) None
Limit the condition (squared ratio largest / smallest eigenvalue) of the cov. matrix if it exceeds a threshold.
Credits on how to limit the condition: https://github.com/CMA-ES/pycma/blob/development/cma/sampler.py
- Parameters:
limit (float) – The threshold for the condition of the matrix.
- _sort_b_d_matrix() None
Sort columns of
b_matrixandd_matrixaccording to the eigenvalues ind_matrix.
- mahalanobis_norm(dx: numpy.ndarray) numpy.ndarray
Compute the Mahalanobis distance using C^(-1/2) and the difference vector of a point to the distribution’s mean.
- Parameters:
dx (numpy.ndarray) – The difference vector.
- Returns:
The resulting Mahalanobis distance.
- Return type:
numpy.ndarray
- class propulate.propagators.cmaes.CMAAdapter
Abstract base class for the adaption of strategy parameters of CMA-ES.
Strategy class from the viewpoint of the strategy design pattern.
- update_mean()
Abstract method for updating of mean in CMA-ES variants.
- update_step_size()
Update step-size in CMA-ES variants.
- update_covariance_matrix()
Abstract method for the adaptation of the covariance matrix of CMA-ES variants.
- compute_weights()
Abstract method for computing the recombination weights of a CMA-ES variant.
- compute_learning_rates()
Compute the learning rates for the CMA-variants.
- abstract update_mean(par: CMAParameter, arx: numpy.ndarray) None
Abstract method for updating of mean in CMA-ES variants.
- Parameters:
par (CMAParameter) – The parameter object of the CMA-ES propagation.
arx (numpy.ndarray) – The individuals of the distribution.
- Raises:
NotImplementedError – Whenever called (abstract base class method).
- static update_step_size(par: CMAParameter) None
Update step-size in CMA-ES variants. Calculate the current evolution path for the step-size adaption.
- Parameters:
par (CMAParameter) – The parameter object of the CMA-ES propagation.
- abstract update_covariance_matrix(par: CMAParameter, arx: numpy.ndarray) None
Abstract method for the adaptation of the covariance matrix of CMA-ES variants.
- Parameters:
par (CMAParameter) – The parameter object of the CMA-ES propagation.
arx (numpy.ndarray) – The individuals of the distribution.
- Raises:
NotImplementedError – Whenever called (abstract base class method).
- abstract compute_weights(mu: int, lamb: int, problem_dimension: int) Tuple[numpy.ndarray, float, float, float, float]
Abstract method for computing the recombination weights of a CMA-ES variant.
- Parameters:
mu (int) – The number of positive recombination weights.
lamb (int) – The number of individuals considered for each generation.
problem_dimension (int) – The number of dimensions in the search space.
- Returns:
tuple of the weights, mu_eff, c_1, c_c and c_mu
- Return type:
tuple[np.ndarray, float, float, float, float]
- Raises:
NotImplementedError – Whenever called (abstract base class method).
- static compute_learning_rates(mu_eff: float, problem_dimension: int) Tuple[float, float, float]
Compute the learning rates for the CMA-variants.
- Parameters:
mu_eff (float) – The variance effective selection mass.
problem_dimension (int) – The number of dimensions in the search space.
- Returns:
float – The decay rate for evolution path for the rank-one update of the covariance matrix,
c_c.float – The learning rate for the rank-one update of the covariance matrix update,
c_1.float – The learning rate for the rank-mu update of the covariance matrix update,
c_mu.
- class propulate.propagators.cmaes.BasicCMA
Bases:
CMAAdapterAdaption of strategy parameters of CMA-ES according to the original CMA-ES algorithm.
Concrete strategy class from the viewpoint of the strategy design pattern.
Notes
The
BasicCMAclass inherits all methods and attributes from theCMAAdapterclass.See also
CMAAdapterThe parent class.
- compute_weights(mu: int, lamb: int, problem_dimension: int) Tuple[numpy.ndarray, float, float, float, float]
Compute the recombination weights for basic CMA-ES.
- Parameters:
mu (int) – The number of positive recombination weights
lamb (int) – The number of individuals considered for each generation
problem_dimension (int) – The number of dimensions in the search space
- Returns:
numpy.ndarray – The weights.
float – The variance effective selection mass,
mu_eff.float – The learning rate for the rank-one update of the covariance matrix update,
c_1.float – The decay rate for evolution path for the rank-one update of the covariance matrix,
c_c.float – The learning rate for the rank-mu update of the covariance matrix update,
c_mu.
- update_mean(par: CMAParameter, arx: numpy.ndarray) None
Update the mean in basic CMA-ES.
- Parameters:
par (CMAParameter) – The parameter object of the CMA-ES propagation.
arx (numpy.ndarray) – The individuals of the distribution.
- update_covariance_matrix(par: CMAParameter, arx: numpy.ndarray) None
Adapt the covariance matrix of basic CMA-ES.
- Parameters:
par (CMAParameter) – The parameter object of the CMA-ES propagation.
arx (numpy.ndarray) – The individuals of the distribution.
- class propulate.propagators.cmaes.ActiveCMA
Bases:
CMAAdapterAdaption of strategy parameters of CMA-ES according to the active CMA-ES algorithm.
Differently from the original CMA-ES algorithm, active CMA-ES uses negative recombination weights (only for the covariance matrix adaptation) for individuals with relatively low fitness. Concrete strategy class from the viewpoint of the strategy design pattern.
Notes
The
ActiveCMAclass inherits all methods and attributes from theCMAAdapterclass.See also
CMAAdapterThe parent class.
- compute_weights(mu: int, lamb: int, problem_dimension: int) Tuple[numpy.ndarray, float, float, float, float]
Compute the recombination weights for active CMA-ES.
- Parameters:
mu (int) – The number of positive recombination weights.
lamb (int) – The number of individuals considered for each generation.
problem_dimension (int) – The number of dimensions in the search space.
- Returns:
numpy.ndarray – The weights.
float – The variance effective selection mass,
mu_eff.float – The learning rate for the rank-one update of the covariance matrix update,
c_1.float – The decay rate for evolution path for the rank-one update of the covariance matrix,
c_c.float – The learning rate for the rank-mu update of the covariance matrix update,
c_mu.
- update_mean(par: CMAParameter, arx: numpy.ndarray) None
Update the mean in active CMA-ES.
- Parameters:
par (CMAParameter) – The parameter object of the CMA-ES propagation.
arx (numpy.ndarray) – The individuals of the distribution.
- update_covariance_matrix(par: CMAParameter, arx: numpy.ndarray) None
Adapt the covariance matrix of active CMA-ES.
- Parameters:
par (CMAParameter) – The parameter object of the CMA-ES propagation.
arx (numpy.ndarray) – The individuals of the distribution.
- class propulate.propagators.cmaes.CMAPropagator(adapter: CMAAdapter, limits: Dict, decompose_in_each_generation: bool = False, select_worst_all_time: bool = False, pop_size: int | None = None, pool_size: int = 3, rng: random.Random | None = None)
Bases:
propulate.propagators.base.PropagatorInstantiate a CMA-ES propagator.
- Parameters:
adapter (CMAAdapter) – The adaptation strategy of CMA-ES.
limits (Dict[str, float]) – The limits of the search space.
decompose_in_each_generation (bool, optional) – If True, decompose covariance matrix for each generation (worse runtime, less exploitation, more exploration); else decompose covariance matrix only after a certain number of individuals evaluated (better runtime, more exploitation, less exploration). Default is False.
select_worst_all_time (bool, optional) – If True, use the worst individuals for negative recombination weights in active CMA-ES, else use the worst (lambda - mu) individuals of the best lambda individuals. If
BasicCMAis used, the given value is irrelevant regarding functionality. Default is False.pop_size (int, optional) – The number of individuals to be considered in each generation.
pool_size (int, optional) – The size of the pool of individuals pre-selected before selecting the best from this pool. Default is 3.
rng (random.Random, optional) – The separate random number generator for the Propulate optimization.
- __call__(inds: List[propulate.population.Individual]) propulate.population.Individual
Define the skeleton of the CMA-ES algorithm using the template method design pattern.
Sampling individuals and adapting the strategy parameters. Template methods are
update_mean,update_covariance_matrix, andupdate_step_size.- Parameters:
inds (List[propulate.population.Individual]) – Available individuals.
- Returns:
new_ind – The newly sampled individual.
- Return type:
- _transform_individuals_to_matrix(inds: List[propulate.population.Individual]) numpy.ndarray
Take a list of individuals and transform it to a numpy array for easier subsequent computation.
- Parameters:
inds (list[propulate.population.Individual]) – The list of individuals.
- Returns:
arx – Array of shape [problem_dimension, len(inds)].
- Return type:
numpy.ndarray
- _sample_cma() propulate.population.Individual
Sample new individuals according to CMA-ES.
- Returns:
new_ind – The newly sampled individual.
- Return type: