ModularCMAES¶
-
class
modcma.modularcmaes.ModularCMAES(fitness_func: Callable, *args, parameters=None, **kwargs)¶ Bases:
objectThe main class of the configurable CMA ES continous optimizer.
-
_fitness_func¶ The objective function to be optimized
- Type
callable
-
parameters¶ All the parameters of the CMA ES algorithm are stored in the parameters object. Note if a parameters object is not explicitly passed, all *args and **kwargs passed into the constructor of a ModularCMAES are directly passed into the constructor of a Parameters object.
- Type
See also
Attributes Summary
A list with break conditions based on the parameters of the CMA-ES.
Methods Summary
fitness_func(x)Wrapper function for calling self._fitness_func.
mutate()Apply mutation operation.
Recombination of new individuals.
run()Run the step method until step method retuns a falsy value.
select()Selection of best individuals in the population.
Indicator whether there are any sequential break conditions.
step()The step method runs one iteration of the optimization process.
Attributes Documentation
-
break_conditions¶ A list with break conditions based on the parameters of the CMA-ES.
- Returns
- Return type
[bool, bool]
Methods Documentation
-
fitness_func(x: numpy.ndarray) → float¶ Wrapper function for calling self._fitness_func.
Adds 1 to self.parameters.used_budget for each fitnes function call.
- Parameters
x (np.ndarray) – array on which to call the objective/fitness function
- Returns
- Return type
float
-
mutate() → None¶ Apply mutation operation.
First, a directional vector zi is sampled from a sampler object as defined in the self.parameters object. Then, this zi vector is multiplied with the eigenvalues D, and the dot product is taken with the eigenvectors B of the covariance matrix C in order to create a scaled directional mutation vector yi. By scaling this vector with current population mean m, and the step size sigma, a new individual xi is created. The self.fitness_func is called in order to compute the fitness of the newly created individuals.
If the step size adaptation method is ‘tpa’, two less ‘normal’ individuals are created.
#TODO: make bound correction vectorized and integrate with tpa
-
recombine() → None¶ Recombination of new individuals.
In the CMAES, recombination is not as explicit as in for example a genetic algorithm. In the CMAES, recombination happens though the moving of the mean m, by multiplying the old mean with a weighted combination of the current mu best individuals. TODO: check if this should be moved to parameters
-
run()¶ Run the step method until step method retuns a falsy value.
- Returns
- Return type
-
select() → None¶ Selection of best individuals in the population.
The population is sorted according to their respective fitness values. Normally, the mu best individuals would be selected afterwards. However, because the option of active update is available, (and we could potentially need the mu worst individuals) the lambda best indivduals are selected. In recombination, only the mu best individuals are used to recompute the mean, so implicited selection happens there.
If elistism is selected as an option, the mu best individuals of the old population are added to the pool of indivduals before sorting.
If selection is to be performed pairwise, the only the best individuals of sequential pairs are used, the others are discarded. The intended use for this functionality is with mirrored sampling, in order to counter the bias generated by this sampling method. This method cannot be performed when there is an odd number of individuals in the population.
-
sequential_break_conditions(i: int, f: float) → bool¶ Indicator whether there are any sequential break conditions.
- Parameters
i (int) – The number of individuals already generated this current generation.
f (float) – The fitness of that individual
- Returns
- Return type
bool
-
step() → bool¶ The step method runs one iteration of the optimization process.
The method is called within the self.run loop. There, a while loop runs until this step function returns a Falsy value.
- Returns
Denoting whether to keep running this step function.
- Return type
bool
-