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 deviation sigma0. Based on how the generated solutions are ranked (see ranker), 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 of the distribution from which solutions are sampled.

  • 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 of RankerBase, or it may be a full or abbreviated ranker name as described in ribs.emitters.rankers.

  • 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 of EvolutionStrategyBase along with kwargs provided by the es_kwargs argument, or it may be a full or abbreviated optimizer name as described in ribs.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), where lower_bound or upper_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, or ranker 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, objective, measures, ...)

Gives the emitter results from evaluating solutions.

tell_dqd(solution, objective, measures, ...)

Gives the emitter results from evaluating the gradient of the solutions, only used for DQD emitters.

Attributes

archive

The archive which stores solutions generated by this emitter.

batch_size

Number of solutions to return in ask().

itrs

The number of iterations for this emitter, where each iteration is a call to tell().

lower_bounds

(solution_dim,) array with lower bounds of solution space.

restarts

The number of restarts for this emitter.

solution_dim

The dimension of solutions produced by this emitter.

upper_bounds

(solution_dim,) array with upper bounds of solution space.

x0

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, objective, measures, add_info, **fields)[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 (array-like) – (batch_size, solution_dim) array of solutions generated by this emitter’s ask() method.

  • objective (array-like) – 1D array containing the objective function value of each solution.

  • measures (array-like) – (batch_size, measure space dimension) array with the measure space coordinates of each solution.

  • add_info (dict) – Data returned from the archive add() method.

  • fields (keyword arguments) – Additional data for each solution. Each argument should be an array with batch_size as the first dimension.

tell_dqd(solution, objective, measures, jacobian, add_info, **fields)

Gives the emitter results from evaluating the gradient of the solutions, only used for DQD emitters.

Parameters
  • solution (numpy.ndarray) – (batch_size, :attr:`solution_dim`) array of solutions generated by this emitter’s ask() method.

  • objective (numpy.ndarray) – 1-dimensional array containing the objective function value of each solution.

  • measures (numpy.ndarray) – (batch_size, measure space dimension) array with the measure space coordinates of each solution.

  • jacobian (numpy.ndarray) – (batch_size, 1 + measure_dim, solution_dim) array consisting of Jacobian matrices of the solutions obtained from ask_dqd(). Each matrix should consist of the objective gradient of the solution followed by the measure gradients.

  • add_info (dict) – Data returned from the archive add() method.

  • fields (keyword arguments) – Additional data for each solution. Each argument should be an array with batch_size as the first dimension.

property archive

The archive which stores solutions generated by this emitter.

Type

ribs.archives.ArchiveBase

property batch_size

Number of solutions to return in ask().

Type

int

property itrs

The number of iterations for this emitter, where each iteration is a call to tell().

Type

int

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

numpy.ndarray

property restarts

The number of restarts for this emitter.

Type

int

property solution_dim

The dimension of solutions produced by this emitter.

Type

int

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

numpy.ndarray

property x0

Initial solution for the optimizer.

Type

numpy.ndarray