ribs.emitters.EvolutionStrategyEmitter¶
- class ribs.emitters.EvolutionStrategyEmitter(archive, *, x0, sigma0, ranker='2imp', es='cma_es', es_kwargs=None, selection_rule='filter', restart_rule='no_improvement', bounds=None, batch_size=None, seed=None)[source]¶
Adapts a distribution of solutions with an ES.
This emitter originates in Fontaine 2020. The multivariate Gaussian solution distribution begins at
x0
with standard deviationsigma0
. Based on how the generated solutions are ranked (seeranker
), the ES then adapts the mean and covariance of the distribution.- Parameters
archive (ribs.archives.ArchiveBase) – An archive to use when creating and inserting solutions. For instance, this can be
ribs.archives.GridArchive
.x0 (np.ndarray) – Initial solution. Must be 1-dimensional.
sigma0 (float) – Initial step size / standard deviation.
ranker (Callable or str) – The ranker is a
RankerBase
object that orders the solutions after they have been evaluated in the environment. This parameter may be a callable (e.g. a class or a lambda function) that takes in no parameters and returns an instance ofRankerBase
, or it may be a full or abbreviated ranker name as described inribs.emitters.rankers.get_ranker()
.es (Callable or str) – The evolution strategy is an
EvolutionStrategyBase
object that is used to adapt the distribution from which new solutions are sampled. This parameter may be a callable (e.g. a class or a lambda function) that takes in the parameters ofEvolutionStrategyBase
along with kwargs provided by thees_kwargs
argument, or it may be a full or abbreviated optimizer name as described inribs.emitters.opt
.es_kwargs (dict) – Additional arguments to pass to the evolution strategy optimizer. See the evolution-strategy-based optimizers in
ribs.emitters.opt
for the arguments allowed by each optimizer.selection_rule ("mu" or "filter") – Method for selecting parents for the evolution strategy. With “mu” selection, the first half of the solutions will be selected as parents, while in “filter”, any solutions that were added to the archive will be selected.
restart_rule (int, "no_improvement", and "basic") – Method to use when checking for restarts. If given an integer, then the emitter will restart after this many iterations, where each iteration is a call to
tell()
. With “basic”, only the default CMA-ES convergence rules will be used, while with “no_improvement”, the emitter will restart when none of the proposed solutions were added to the archive.bounds (None or array-like) – Bounds of the solution space. As suggested in Biedrzycki 2020, solutions are resampled until they fall within these bounds. Pass None to indicate there are no bounds. Alternatively, pass an array-like to specify the bounds for each dim. Each element in this array-like can be None to indicate no bound, or a tuple of
(lower_bound, upper_bound)
, wherelower_bound
orupper_bound
may be None to indicate no bound.batch_size (int) – Number of solutions to return in
ask()
. If not passed in, a batch size will be automatically calculated using the default CMA-ES rules.seed (int) – Value to seed the random number generator. Set to None to avoid a fixed seed.
- Raises
ValueError – There is an error in x0 or initial_solutions.
ValueError – There is an error in the bounds configuration.
ValueError – If
restart_rule
,selection_rule
, orranker
is invalid.
Methods
ask
()Samples new solutions from a multivariate Gaussian.
ask_dqd
()Generates a
(batch_size, solution_dim)
array of solutions for which gradient information must be computed.tell
(solution_batch, objective_batch, ...[, ...])Gives the emitter results from evaluating solutions.
tell_dqd
(solution_batch, objective_batch, ...)Gives the emitter results from evaluating the gradient of the solutions, only used for DQD emitters.
Attributes
The archive which stores solutions generated by this emitter.
Number of solutions to return in
ask()
.The number of iterations for this emitter, where each iteration is a call to
tell()
.(solution_dim,)
array with lower bounds of solution space.The number of restarts for this emitter.
The dimension of solutions produced by this emitter.
(solution_dim,)
array with upper bounds of solution space.Initial solution for the optimizer.
- ask()[source]¶
Samples new solutions from a multivariate Gaussian.
The multivariate Gaussian is parameterized by the evolution strategy optimizer
self._opt
.- Returns
(batch_size,
solution_dim
) array – a batch of new solutions to evaluate.
- ask_dqd()¶
Generates a
(batch_size, solution_dim)
array of solutions for which gradient information must be computed.This method only needs to be implemented by emitters used in DQD. The method returns an empty array by default.
- tell(solution_batch, objective_batch, measures_batch, status_batch, value_batch, metadata_batch=None)[source]¶
Gives the emitter results from evaluating solutions.
The solutions are ranked based on the rank() function defined by self._ranker. Then, the ranked solutions are passed to CMA-ES for adaptation.
This function also checks for restart condition and restarts CMA-ES when needed.
- Parameters
solution_batch (array-like) – (batch_size,
solution_dim
) array of solutions generated by this emitter’sask()
method.objective_batch (array-like) – 1D array containing the objective function value of each solution.
measures_batch (array-like) – (batch_size, measure space dimension) array with the measure space coordinates of each solution.
status_batch (array-like) – 1D array of
ribs.archive.AddStatus
returned by a series of calls to archive’sadd()
method.value_batch (array-like) – 1D array of floats returned by a series of calls to archive’s
add()
method. For what these floats represent, refer toribs.archives.add()
.metadata_batch (array-like) – 1D object array containing a metadata object for each solution.
- tell_dqd(solution_batch, objective_batch, measures_batch, jacobian_batch, status_batch, value_batch, metadata_batch=None)¶
Gives the emitter results from evaluating the gradient of the solutions, only used for DQD emitters.
- Parameters
solution_batch (numpy.ndarray) –
(batch_size, :attr:`solution_dim`)
array of solutions generated by this emitter’sask()
method.objective_batch (numpy.ndarray) – 1-dimensional array containing the objective function value of each solution.
measures_batch (numpy.ndarray) –
(batch_size, measure space dimension)
array with the measure space coordinates of each solution.jacobian_batch (numpy.ndarray) –
(batch_size, 1 + measure_dim, solution_dim)
array consisting of Jacobian matrices of the solutions obtained fromask_dqd()
. Each matrix should consist of the objective gradient of the solution followed by the measure gradients.status_batch (numpy.ndarray) – 1d array of
ribs.archive.addstatus
returned by a series of calls to archive’sadd()
method.value_batch (numpy.ndarray) – 1d array of floats returned by a series of calls to archive’s
add()
method. for what these floats represent, refer toribs.archives.add()
.metadata_batch (numpy.ndarray) – 1d object array containing a metadata object for each solution.
- property archive¶
The archive which stores solutions generated by this emitter.
- property itrs¶
The number of iterations for this emitter, where each iteration is a call to
tell()
.- Type
- property lower_bounds¶
(solution_dim,)
array with lower bounds of solution space.For instance,
[-1, -1, -1]
indicates that every dimension of the solution space has a lower bound of -1.- Type
- property upper_bounds¶
(solution_dim,)
array with upper bounds of solution space.For instance,
[1, 1, 1]
indicates that every dimension of the solution space has an upper bound of 1.- Type
- property x0¶
Initial solution for the optimizer.
- Type