ribs.emitters.opt.PyCMAEvolutionStrategy

class ribs.emitters.opt.PyCMAEvolutionStrategy(sigma0: float | floating, solution_dim: int | integer, batch_size: int | None = None, seed: int | integer | None = None, dtype: numpy.typing.DTypeLike = numpy.float64, lower_bounds: float | floating | ndarray | None = None, upper_bounds: float | floating | ndarray | None = None, opts: dict | None = None)[source]

Wrapper around the pycma CMAEvolutionStrategy.

Note

This optimizer requires the pycma package, which can be installed with pip install cma or conda install cma.

Parameters:
sigma0: float | floating

Initial step size.

batch_size: int | None = None

Number of solutions to evaluate at a time. This is passed directly as popsize in opts.

solution_dim: int | integer

Size of the solution space.

seed: int | integer | None = None

Seed for the random number generator.

dtype: numpy.typing.DTypeLike = numpy.float64

Data type of solutions.

lower_bounds: float | floating | ndarray | None = None

scalar or (solution_dim,) array indicating lower bounds of the solution space. Scalars specify the same bound for the entire space, while arrays specify a bound for each dimension. Pass -np.inf in the array or scalar to indicated unbounded space.

upper_bounds: float | floating | ndarray | None = None

Same as above, but for upper bounds (and pass np.inf instead of -np.inf).

opts: dict | None = None

Additional options for pycma. Note that popsize, bounds, randn, and seed are overwritten by us and thus should not be provided in this dict. We also make verbose default to -9, but you can also pass in a custom value here.

Methods

ask([batch_size])

Samples new solutions from the Gaussian distribution.

check_stop(ranking_values)

Checks if the optimization should stop and be reset.

reset(x0)

Resets the optimizer to start at x0.

tell(ranking_indices, ranking_values, ...)

Passes the solutions back to the ES.

Attributes

batch_size

Number of solutions per iteration.

ask(batch_size: int | integer | None = None) ndarray[source]

Samples new solutions from the Gaussian distribution.

Parameters:
batch_size: int | integer | None = None

batch size of the sample. Defaults to self.batch_size.

check_stop(ranking_values: ndarray) bool[source]

Checks if the optimization should stop and be reset.

Parameters:
ranking_values: ndarray

Not used.

Returns:

Output of cma.CMAEvolutionStrategy.stop

reset(x0: ndarray) None[source]

Resets the optimizer to start at x0.

Parameters:
x0: ndarray

Initial mean.

tell(ranking_indices: ndarray, ranking_values: ndarray, num_parents: int | integer) None[source]

Passes the solutions back to the ES.

Parameters:
ranking_indices: ndarray

Integer indices that are used to rank the solutions returned in ask(). Note that these are NOT the ranks of the solutions. Rather, they are indices such that solutions[ranking_indices] will correctly rank the solutions (think of an argsort).

ranking_values: ndarray

Array of values that were used to rank the solutions. Shape can be either (batch_size,) or (batch_size, n_values)``, where batch_size is the number of solutions and n_values is the number of values that the ranker used. Note that we assume a descending sort, i.e., higher values should come first.

num_parents: int | integer

Number of top solutions to select from the ranked solutions.

property batch_size : int | integer

Number of solutions per iteration.

Only valid after a call to reset().