CMA-ES

class CMAOptimizer(_opt_id=None, _signal_pipe=None, _results_queue=None, _pause_flag=None, _is_log_detailed=False, _workers=1, _backend='threads', sigma0=0.05, sampler='full', verbose=True, keep_files=None, force_injects=None, injection_interval=None, **cmasettings)[source]

Bases: scm.glompo.optimizers.baseoptimizer.BaseOptimizer

Wrapper around a CMA-ES python implementation. Note that this class is also stand-alone, this means it can be used independently of the GloMPO framework. It is also built in such a way that it minimize() can be called multiple times on different functions.

Parameters

_opt_id, _signal_pipe, _results_queue, _pause_flag, _is_log_detailed, _workers, _backend

See BaseOptimizer.

sigma0

Initial standard deviation of the multivariate normal distribution from which trials are drawn. One value for all parameters which means that all parameters must be scaled accordingly.

sampler

Allows the use of 'GaussVDSampler' and 'GaussVkDSampler' settings.

verbose

If True, print status messages during the optimization, else no output will be printed.

keep_files

Directory in which to save files containing extra optimizer convergence information.

force_injects

If True, injections of parameter vectors into the solver will be exact, guaranteeing that the solution will be in the next iteration’s population. If False, the injection will result in a direction relative nudge towards the vector. Forcing the injecting can limit global exploration but non-forced injections may have little effect.

injection_interval

If None, injections are ignored by the optimizer. If an int is provided then injection are only accepted if at least injection_interval iterations have passed since the last injection.

**cmasettings

CMA-ES package-specific settings. See cma.s.pprint(cma.CMAOptions()) for a list of available options. Most useful keys are: 'timeout', 'tolstagnation', 'popsize'. Additionally, the following options are supported through this class:

  • 'minsigma': Termination if sigma < minsigma

  • 'maxsigma': Limit sigma to min(sigma,maxsigma)

  • 'storeC': If True, creates a file called cma_C.npy in keep_files with the covariance matrix at every iteration. keep_files must also be provided and sampler must be the default ('full').

Notes

  1. Although not the default, by adjusting the injection settings above, the optimizer will inject the saved incumbent solution into the solver influencing the points sampled by the following iteration. The incumbent begins at x0 and is updated by the inject method called by the GloMPO manager.

  2. If 'popsize' is not provided during optimizer initialisation, it will be set to the number of BaseOptimizer.workers if this is larger than 1, else it will be set to the default: 4 + int(3 * log(d)).

References

Hansen, N. (2021). CMA-ES, Covariance Matrix Adaptation Evolution Strategy for non-linear numerical optimization in Python. PyPI. https://pypi.org/project/cma/

classmethod checkpoint_load(path, **kwargs)[source]

Recreates an optimizer from a saved snapshot.

Parameters

path

Path to checkpoint file from which to build from. It must be a file produced by the corresponding checkpoint_save() method.

**kwargs

See __init__.

Notes

This is a basic implementation which should suit most optimizers; may need to be overwritten.

checkpoint_save(path, force=None, block=None)[source]

Save current state, suitable for restarting.

Parameters

path

Path to file into which the object will be dumped. Typically supplied by the manager.

force

Set of variable names which will be forced into the dumped file. Convenient shortcut for overwriting if fails for a particular optimizer because a certain variable is filtered out of the data dump.

block

Set of variable names which are typically caught in the construction of the checkpoint but should be excluded. Useful for excluding some properties.

Notes

  1. Only the absolutely critical aspects of the state of the optimizer need to be saved. The manager will resupply multiprocessing parameters when the optimizer is reconstructed.

  2. This method will almost never be called directly by the user. Rather it will be called (via signals) by the manager.

  3. This is a basic implementation which should suit most optimizers; may need to be overwritten. Typically it is sufficient to call the super method and use the force and block parameters to get a working implementation.

minimize(function, x0, bounds)[source]

Begin CMA-ES minimization loop.

Parameters

function bounds callbacks

See BaseOptimizer.minimize()

x0

See BaseOptimizer.minimize(). Force injected into the solver to guarantee it is evaluated.

Returns

MinimizeResult

Location, function value and other optimization information about the lowest value found by the optimizer.