Strategies¶
deap_er.strategies
¶
StrategyMultiObjective(population, sigma, **kwargs)
¶
Multi-objective Covariance Matrix Adaptation evolution strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
population
|
list[Individual]
|
Initial parent population. |
required |
sigma
|
float
|
Initial step size for every parent. |
required |
**kwargs
|
Any
|
Optional strategy parameters. See the table below. |
{}
|
.. dropdown:: Table of Kwargs :margin: 0 5 0 0
- offsprings - (int)
- The number of children to produce at each generation.
- Default:
1
- survivors - (int)
- The number of parents to keep for the next generation.
- Default:
len(population)
- ss_dmp - (float)
- Damping of the step-size.
- Default:
1.0 + len(population[0]) / 2.0
- th_cum - (float)
- Time horizon of the cumulative contribution.
- Default:
2.0 / (len(population[0]) + 2.0)
- tgt_sr - (float)
- Target success rate.
- Default:
1.0 / 5.5
- thresh_sr - (float)
- Threshold success rate.
- Default:
0.44
- ss_learn_rate - (float)
- Learning rate of the step-size.
- Default:
tgt_sr / (2.0 + tgt_sr)
- cm_learn_rate - (float)
- Learning rate of the covariance matrix.
- Default:
2.0 / (len(population[0]) ** 2 + 6.0)
- low, up - (float or sequence)
- Optional box bounds on generated individuals.
- bound_mode - (str)
clip(default) orresample. Both are constraint-handling approximations; the update treats the repaired point as the sample.
- resample_limit - (int)
- Failed redraws before clipping one sample. Default:
100
- Failed redraws before clipping one sample. Default:
See the class docstring.
Source code in deap_er/private/strategies/cma_multi_objective.py
compute_params(**kwargs)
¶
Recompute strategy parameters from kwargs.
Called from the constructor. Call again if offsprings or
survivors changes during evolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Optional strategy parameters. See the class docstring. Parameters given to earlier calls stay pinned unless overridden here. |
{}
|
Source code in deap_er/private/strategies/cma_multi_objective.py
reset_state(parents, sigma, **kwargs)
¶
Reset mutable CMA state for a restart.
Hyperparameters and bounds from earlier calls are kept.
Source code in deap_er/private/strategies/cma_multi_objective.py
update(population)
¶
Select new parents and update each parent's CMA parameters.
Offspring are merged with the current parents, then reduced to
survivors by non-dominated sorting of candidates with
valid fitness. Step-size and covariance are updated per
successful parent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
population
|
list[Individual]
|
Evaluated individuals from |
required |
Source code in deap_er/private/strategies/cma_multi_objective.py
generate(ind_init)
¶
Sample offsprings individuals from the current parents.
When offsprings equals the parent count and that many
parents exist, each parent produces one child. Otherwise
parents are drawn from the first non-dominated front, or from
every parent if any parent fitness is invalid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind_init
|
Callable[..., Individual]
|
Callable that turns a sampled vector into an individual. |
required |
Returns:
| Type | Description |
|---|---|
list[Individual]
|
Newly sampled individuals. |
Source code in deap_er/private/strategies/cma_multi_objective.py
StrategyOnePlusLambda(parent, sigma, **kwargs)
¶
One-plus-lambda Covariance Matrix Adaptation evolution strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
Individual
|
Starting individual. Must have a fitness attribute. |
required |
sigma
|
float
|
Initial standard deviation of the distribution. |
required |
**kwargs
|
Any
|
Optional strategy parameters. See the table below. |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
.. dropdown:: Table of Kwargs :margin: 0 5 0 0
- offsprings - (int)
- The number of children to produce at each generation.
- Default:
1
- ss_dmp - (float)
- Damping of the step-size.
- Default:
1.0 + len(parent) / (2.0 * offsprings)
- th_cum - (float)
- Time horizon of the cumulative contribution.
- Default:
2.0 / (len(parent) + 2.0)
- tgt_sr - (float)
- Target success rate.
- Default:
1.0 / (5 + sqrt(offsprings) / 2.0)
- thresh_sr - (float)
- Threshold success rate.
- Default:
0.44
- ss_learn_rate - (float)
- Learning rate of the step-size.
- Default:
tgt_sr * offsprings / (2.0 + tgt_sr * offsprings)
- cm_learn_rate - (float)
- Learning rate of the covariance matrix.
- Default:
2.0 / (len(parent) ** 2 + 6.0)
- low, up - (float or sequence)
- Optional box bounds on generated individuals.
- bound_mode - (str)
clip(default) orresample. Both are constraint-handling approximations; the update treats the repaired point as the sample.
- resample_limit - (int)
- Failed redraws before clipping one sample. Default:
100
- Failed redraws before clipping one sample. Default:
See the class docstring.
Source code in deap_er/private/strategies/cma_one_plus_lambda.py
compute_params(**kwargs)
¶
Recompute strategy parameters from kwargs.
Called from the constructor. Call again if offsprings
changes during evolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Optional strategy parameters. See the class docstring. Parameters given to earlier calls stay pinned unless overridden here. |
{}
|
Source code in deap_er/private/strategies/cma_one_plus_lambda.py
reset_state(parent, sigma, **kwargs)
¶
Reset mutable CMA state for a restart.
Hyperparameters and bounds from earlier calls are kept.
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in deap_er/private/strategies/cma_one_plus_lambda.py
generate(ind_init)
¶
Sample offsprings individuals around the current parent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind_init
|
Callable[..., Individual]
|
Callable that turns a sampled vector into an individual. |
required |
Returns:
| Type | Description |
|---|---|
list[Individual]
|
Newly sampled individuals. |
Source code in deap_er/private/strategies/cma_one_plus_lambda.py
update(population)
¶
Update parent, step-size, and covariance from population.
The parent is replaced when a better offspring exists. Success
rate drives the step-size; a successful replacement also
updates the covariance. An unevaluated parent (no fitness
values, as after reset_state / a restart) adopts the best
offspring without counting a fake success or adapting
sigma or the covariance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
population
|
list[Individual]
|
Evaluated individuals from |
required |
Source code in deap_er/private/strategies/cma_one_plus_lambda.py
StrategySeparable(centroid, sigma, **kwargs)
¶
Bases: CmaCore
Separable CMA-ES with a diagonal covariance (Ros and Hansen, 2008).
Learns one variance per gene. Memory and the generate/update step
are O(n). There is no learned correlation. Default
rank_one and rank_mu are the Strategy defaults scaled
by (n + 2) / 3. Step-size uses the same cumulative step-size
adaptation as Strategy. Box bounds and the rest of the
keyword surface match Strategy, except cm_init is a
length-n variance vector (default ones), not an n-by-n
matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
centroid
|
Iterable[float]
|
Starting point of the search distribution. |
required |
sigma
|
float
|
Initial standard deviation of the distribution. |
required |
**kwargs
|
Any
|
Optional strategy parameters. Shared names follow
|
{}
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ValueError
|
If |
See the class docstring.
Source code in deap_er/private/strategies/cma_separable.py
compute_params(**kwargs)
¶
Recompute λ, rates, and the diagonal cm_init vector.
Hyperparameters from earlier calls stay pinned, as in
Strategy.compute_params.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Same names as |
{}
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ValueError
|
If |
Source code in deap_er/private/strategies/cma_separable.py
reset_state(centroid, sigma, **kwargs)
¶
Reset mutable CMA state for a restart.
Hyperparameters and bounds from earlier calls are kept.
Source code in deap_er/private/strategies/cma_separable.py
generate(ind_init)
¶
Draw lamb axis-aligned samples and apply box bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind_init
|
Callable[..., Individual]
|
Builds an individual from a length- |
required |
Returns:
| Type | Description |
|---|---|
list[Individual]
|
The sampled population. |
Source code in deap_er/private/strategies/cma_separable.py
update(population)
¶
Update centroid, step-size, and diagonal covariance.
Individuals are ranked by fitness. The best survivors
members drive the update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
population
|
list[Individual]
|
Evaluated individuals from |
required |
Raises:
| Type | Description |
|---|---|
FloatingPointError
|
If the update gives a non-finite state,
as |
Source code in deap_er/private/strategies/cma_separable.py
Strategy(centroid, sigma, **kwargs)
¶
Bases: CmaCore
Standard Covariance Matrix Adaptation evolution strategy.
Hansen's chiN and diag(D) are stored as chi_n and
diag_d. chi_n is the expected norm of an
N-dimensional standard normal vector. diag_d is the
diagonal of D, the square-root eigenvalues of the covariance
C.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
centroid
|
Iterable[float]
|
Starting point of the search distribution. |
required |
sigma
|
float
|
Initial standard deviation of the distribution. |
required |
**kwargs
|
Any
|
Optional strategy parameters. See the table below. |
{}
|
.. dropdown:: Table of Kwargs :margin: 0 5 0 0
- offsprings - (int)
- The number of children to produce at each generation.
- Default:
int(4 + 3 * log(len(centroid)))
- survivors - (int)
- The number of children to keep as parents for the next
generation. Must be between 1 and
offsprings. - Default:
int(offsprings / 2)
- The number of children to keep as parents for the next
generation. Must be between 1 and
- weights - (str)
- Recombination weights. One of
superlinear,linear, orequal. - Default:
'superlinear'
- Recombination weights. One of
- cm_init - (numpy.ndarray)
- The initial covariance matrix of the distribution.
- Default:
numpy.identity(len(centroid))
- cm_cum - (float)
- Cumulation constant of the covariance matrix.
- Default:
4 / (len(centroid) + 4)
- ss_cum - (float)
- Cumulation constant of the step-size.
- Default:
(mueff + 2) / (len(centroid) + mueff + 3)
- ss_dmp - (float)
- Damping of the step-size.
- Default:
1 + 2 * max(0, sqrt((mueff - 1) / (len(centroid) + 1)) - 1) + ss_cum
- rank_one - (float)
- Learning rate for rank-one update.
- Default:
2 / ((len(centroid) + 1.3) ** 2 + mueff)
- rank_mu - (float)
- Learning rate for rank-mu update.
- Default:
2 * (mueff - 2 + 1 / mueff) / ((len(centroid) + 2) ** 2 + mueff)
- low, up - (float or sequence)
- Optional box bounds on generated individuals.
- bound_mode - (str)
clip(default) orresample. Both are constraint-handling approximations.clipevaluates the clipped point, but the update learns from the unclipped draw and clips the new centroid into the box.
- resample_limit - (int)
- Failed redraws before clipping one sample. Default:
100
- Failed redraws before clipping one sample. Default:
See the class docstring.
Source code in deap_er/private/strategies/cma_standard.py
compute_params(**kwargs)
¶
Recompute strategy parameters from kwargs.
Called from the constructor. Call again if offsprings
changes during evolution. Hyperparameters given to earlier
calls stay pinned unless kwargs overrides them; the rest
are re-derived from the new offsprings. A pinned
survivors larger than the new offsprings is capped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Optional strategy parameters. See the class docstring. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
FloatingPointError
|
If |
Source code in deap_er/private/strategies/cma_standard.py
reset_state(centroid, sigma, **kwargs)
¶
Reset mutable CMA state for a restart.
The centroid, step size, paths, and covariance are reset.
Hyperparameters and bounds from earlier calls are kept; see
compute_params.
Source code in deap_er/private/strategies/cma_standard.py
generate(ind_init)
¶
Sample offsprings individuals from the current distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ind_init
|
Callable[..., Individual]
|
Callable that turns a sampled vector into an individual. |
required |
Returns:
| Type | Description |
|---|---|
list[Individual]
|
Newly sampled individuals. |
Source code in deap_er/private/strategies/cma_standard.py
update(population)
¶
Update centroid, step-size, and covariance from population.
Individuals are ranked by fitness. The best survivors
members drive the update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
population
|
list[Individual]
|
Evaluated individuals from |
required |
Raises:
| Type | Description |
|---|---|
FloatingPointError
|
If the update gives a non-finite state,
which happens once |
Source code in deap_er/private/strategies/cma_standard.py
RestartStrategy(strategy, *, mode='bipop', budget, target_f=None, sigma_large=2.0, lambda_factor=2.0, max_large_restarts=9, max_restarts=None, stagnation_window=20, tol_fun=1e-12, condition_limit=100000000000000.0, restart_centroid='random', stagnation_key=None)
¶
Wrap a standard, separable, (1+λ), or MO CMA strategy with IPOP or BIPOP restarts.
See constructor keyword arguments for configuration. target_f is
expressed in raw objective space for single-objective runs. The first
run uses sigma_large as its initial step size. A run whose step
size collapses (the inner update raises FloatingPointError) ends
and restarts.
stagnation_key must return a higher-is-better scalar. It is required
for multi-objective fitness because there is no default scalarization.
See the class docstring.
Source code in deap_er/private/strategies/restart.py
mode
property
¶
Restart scheme, ipop or bipop.
sigma_large
property
¶
First-run and large-regime step size.
lambda_factor
property
¶
Population growth factor per large restart.
max_large_restarts
property
¶
Cap on the large-restart exponent.
evals_used
property
¶
Total function evaluations consumed so far.
restart_count
property
¶
Number of restarts completed.
regime
property
¶
Active restart regime, or None before the first restart.
best_fitness
property
¶
Best raw objective seen across all runs for single-objective runs.
Independent of stagnation_key, which only drives stagnation.
remaining_budget()
¶
generate(ind_init)
¶
Sample offspring from the inner strategy within the eval budget.
Source code in deap_er/private/strategies/restart.py
update(population)
¶
Update the inner strategy and check per-run termination.
Source code in deap_er/private/strategies/restart.py
should_restart()
¶
Return whether the current run ended and a restart is due.
Source code in deap_er/private/strategies/restart.py
restart()
¶
Finish the current run and launch the next restart.