ribs.emitters.GeneticAlgorithmEmitter¶
- class ribs.emitters.GeneticAlgorithmEmitter(archive, *, x0=None, initial_solutions=None, bounds=None, batch_size=64, operator_kwargs=None, operator=None)[source]¶
Emits solutions by using operator provided.
If the archive is empty and
self._initial_solutions
is set, a call toask()
will returnself._initial_solutions
. Ifself._initial_solutions
is not set, we operate on self.x0.- Parameters
archive (ribs.archives.ArchiveBase) – An archive to use when creating and inserting solutions. For instance, this can be
ribs.archives.GridArchive
.x0 (numpy.ndarray) – Initial solution.
operator (str) – Internal Operator Class used to Mutate Solutions in ask method.
operator_kwargs (dict) – Additional arguments to pass to the operator. See
ribs.emitters.operators
for the arguments allowed by each operator.initial_solutions (array-like) – An (n, solution_dim) array of solutions to be used when the archive is empty. If this argument is None, then solutions will be sampled from a Gaussian distribution centered at
x0
with standard deviationsigma
.bounds (None or array-like) – Bounds of the solution space. Solutions are clipped to 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.
- Raises
ValueError – There is an error in x0 or initial_solutions.
ValueError – There is an error in the bounds configuration.
Methods
ask
()Creates solutions with operator provided.
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
The archive which stores solutions generated by this emitter.
Number of solutions to return in
ask()
.The initial solutions which are returned when the archive is empty (if x0 is not set).
(solution_dim,)
array with lower bounds of solution space.The dimension of solutions produced by this emitter.
(solution_dim,)
array with upper bounds of solution space.Initial Solution (if initial_solutions is not set).
- ask()[source]¶
Creates solutions with operator provided.
If the archive is empty and
self._initial_solutions
is set, we returnself._initial_solutions
. Ifself._initial_solutions
is not set and the archive is still empty, we operate on the initial solution (x0) provided. Otherwise, we sample parents from the archive to be used as input to the operator- Returns
If the archive is not empty,
(batch_size, solution_dim)
array – containsbatch_size
new solutions to evaluate. If the archive is empty, we returnself._initial_solutions
, which might not havebatch_size
solutions.- Return type
- 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)¶
Gives the emitter results from evaluating solutions.
This base class implementation (in
EmitterBase
) needs to be overriden.- Parameters
solution (numpy.ndarray) – Array of solutions generated by this emitter’s
ask()
method.objective (numpy.ndarray) – 1D array containing the objective function value of each solution.
measures (numpy.ndarray) –
(n, <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’sask()
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 fromask_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.
- property initial_solutions¶
The initial solutions which are returned when the archive is empty (if x0 is not set).
- 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 (if initial_solutions is not set).
- Type