metaheuristic_designer.strategies package#

Subpackages#

Submodules#

Module contents#

Built-in search strategy implementations.

class NoSearch(initializer, name='No search', **kwargs)[source]#

Bases: SearchStrategy

Debug strategy that does nothing.

The population is never modified. Useful as a baseline or for testing other components in isolation.

Parameters:
initializerInitializer

Population initializer.

namestr, optional

Display name (default "No search").

**kwargs

Forwarded to SearchStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

step(prev_population, objfunc)[source]#

Performs a single iteration of the algorithm on a given population.

Return type:

Population

Parameters:
populationPopulation

Population of solutions in which to perform the operators.

Returns:
Population

Next population after performing all the steps in the iteration.

Parameters:
class SearchStrategy(initializer, operator=None, parent_sel=None, survivor_sel=None, name='some strategy', rng=None, **kwargs)[source]#

Bases: ParametrizableMixin, ABC

Orchestrates one iteration of an optimization loop.

A search strategy holds together an Initializer, an Operator, a ParentSelection, and a SurvivorSelection. Together they define how the population is created, perturbed, and pruned each generation. Subclasses can override any step to implement algorithm-specific logic.

Parameters:
initializerInitializer

Creates the starting population.

operatorOperator, optional

The perturbation operator (mutation, crossover, …). Defaults to NullOperator.

parent_selParentSelection, optional

Selects which individuals are used to generate offspring. Defaults to NullParentSelection.

survivor_selSurvivorSelection, optional

Selects which individuals survive to the next generation. Defaults to NullSurvivorSelection.

namestr, optional

Display name used in reports.

rngRNGLike, optional

Random number generator.

**kwargs

Additional keyword arguments stored as schedulable parameters.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

gather_parameters()[source]#

Collect the current parameters from all sub-components.

Returns:
dict

A flat dictionary with dotted keys like "operator.F", "parent_sel.amount", etc.

reset(objfunc)[source]#
Parameters:

objfunc (ObjectiveFunc)

initialize(objfunc)[source]#

Initializes the optimization search strategy.

Return type:

Population

Parameters:
objfunc: ObjectiveFunc

Objective function to be optimized.

Returns:
population: Population

The initial population to be used in the algorithm.

Parameters:

objfunc (ObjectiveFunc)

update(progress)[source]#

Advances the state of the search by one iteration.

Parameters:
progressfloat

Current progress of the algorithm (0-1).

Parameters:

progress (float)

abstract step(prev_population, objfunc)[source]#

Performs a single iteration of the algorithm on a given population.

Return type:

Population

Parameters:
populationPopulation

Population of solutions in which to perform the operators.

Returns:
Population

Next population after performing all the steps in the iteration.

Parameters:
get_state()[source]#

Gets the current state of the search strategy as a dictionary.

Return type:

dict

Parameters:
show_population: bool, optional

Save the state of the current population.

Returns:
state: dict

The complete state of the search strategy.

extra_step_info()[source]#

Hook called after each generation (intended for subclasses).

extra_report()[source]#

Hook called at the end of the optimization (intended for subclasses).

class SingleSolutionStrategy(initializer, operator=None, survivor_sel=None, name='HillClimb', rng=None, **kwargs)[source]#

Bases: SearchStrategy

No parent selection method exists, we only have one solution at each given time

Parameters:
initializerInitializer

Population initializer (typically creates a single individual).

operatorOperator, optional

Perturbation operator. Defaults to NullOperator.

survivor_selSurvivorSelection, optional

Survivor selection method; defaults to "hill_climb".

namestr, optional

Display name (default "HillClimb").

rngRNGLike, optional

Random number generator.

**kwargs

Forwarded to SearchStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

step(prev_population, objfunc)[source]#

Performs a single iteration of the algorithm on a given population.

Return type:

Population

Parameters:
populationPopulation

Population of solutions in which to perform the operators.

Returns:
Population

Next population after performing all the steps in the iteration.

Parameters:
class ShuffledPopulationStrategy(initializer, operator=None, parent_sel=None, survivor_sel=None, offspring_size=None, shuffle_with_replacement=False, name='Variable Population Evolution', rng=None, **kwargs)[source]#

Bases: SearchStrategy

Population-based strategy with separate parent and offspring sizes.

This is the base for (μ+λ) and (μ,λ) Evolution Strategies, GAs, and similar algorithms. The number of parents selected and the number of offspring generated can be configured independently.

Parameters:
initializerInitializer

Population initializer.

operatorOperator

Perturbation operator.

parent_selParentSelection, optional

Parent selection method.

survivor_selSurvivorSelection, optional

Survivor selection method.

offspring_sizeint or SchedulableParameter, optional

Number of offspring to generate. Defaults to the initializer’s population size.

shuffle_with_replacementbool, optional

If True, shuffle the parent pool with replacement; otherwise without replacement (default False).

namestr, optional

Display name.

rngRNGLike, optional

Random number generator.

**kwargs

Forwarded to SearchStrategy.

Attributes:
initializer
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

step(prev_population, objfunc)[source]#

Performs a single iteration of the algorithm on a given population.

Return type:

Population

Parameters:
populationPopulation

Population of solutions in which to perform the operators.

Returns:
Population

Next population after performing all the steps in the iteration.

Parameters:
class EDAStrategy(initializer, operator, parent_sel=None, survivor_sel=None, name='Static Population Evolution', rng=None, **kwargs)[source]#

Bases: SearchStrategy

Population-based strategy with constant size and no parent selection.

The entire population is perturbed each generation. By default, parent selection is the identity (all individuals are used) and survivor selection is generational (offspring replace parents).

Parameters:
initializerInitializer

Population initializer.

operatorOperator

Perturbation operator.

parent_selParentSelection, optional

Parent selection; defaults to identity (keep all).

survivor_selSurvivorSelection, optional

Survivor selection; defaults to generational replacement.

namestr, optional

Display name (default "Static Population Evolution").

rngRNGLike, optional

Random number generator.

**kwargs

Forwarded to SearchStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

estimate_parameters(population)

Utilizes the samples present in the input population to estimate the parameters used by the operator.

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

abstract estimate_parameters(population)[source]#

Utilizes the samples present in the input population to estimate the parameters used by the operator.

Return type:

Operator

Parameters:
populationPopulation

Data to use for estimating parameters.

Returns:
Operator

Newly configured operator.

Parameters:

population (Population)

step(prev_population, objfunc)[source]#

Performs a single iteration of the algorithm on a given population.

Return type:

Population

Parameters:
populationPopulation

Population of solutions in which to perform the operators.

Returns:
Population

Next population after performing all the steps in the iteration.

Parameters:
class CMA_ES(initializer, survivor_sel=None, name='CMA-ES', offspring_size=None, rng=None, mean=None, sigma=None, cond_tol=100000000.0, sigma_tol=1e-10, **kwargs)[source]#

Bases: EDAStrategy

Covariance Matrix Adaptation Evolution Strategy (CMA-ES).

This is a population-based algorithm that samples new solutions from a multivariate normal distribution whose mean and covariance are adapted each generation based on the best individuals.

Note

The architecture of this class is provisional. It currently overrides initialize() and perturb() directly. Once the distribution-based (EDA) abstraction is in place, CMA-ES will be rewritten to use that common interface.

Parameters:
initializerInitializer

Provides population size and genotype shape, but does not generate the initial solutions.

survivor_selSurvivorSelection, optional

How survivors are selected. Defaults to the strategy’s default (generational).

namestr, optional

Display name (default "CMA-ES").

offspring_sizeint or SchedulableParameter, optional

Number of offspring per generation. If None, the initializer’s population size is used.

rngRNGLike, optional

Random number generator.

meanVectorLike, optional

Initial mean vector. If not given, it is computed from the objective’s bounds (or randomly if no bounds exist).

sigmaVectorLike, optional

Initial step size. If not given, a default is computed.

**kwargs

Forwarded to VariablePopulation.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

estimate_parameters(population)

Update the distribution parameters

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Create the initial population by sampling from the current distribution.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

initialize(objfunc)[source]#

Create the initial population by sampling from the current distribution.

Return type:

Population

Parameters:
objfuncObjectiveFunc

The objective function, used to infer bounds if mean or sigma are not provided.

Returns:
Population

A freshly sampled population with unevaluated fitness.

Parameters:

objfunc (ObjectiveFunc)

estimate_parameters(population)[source]#

Update the distribution parameters

The parents (the best μ individuals from the previous generation) are used to update mean, sigma, covariance, and the evolution paths.

Parameters:
populationPopulation

The selected parents (must be already evaluated).

Returns:
Population

Offspring population of size offspring_size.

class HillClimb(initializer, operator=None, survivor_sel=None, params=None, name='HillClimb', rng=None, **kwargs)[source]#

Bases: SingleSolutionStrategy

Hill Climbing algorithm.

A single solution is perturbed each iteration. If the new solution is better, it replaces the current one. By default, the survivor selection is set to one-to-one competition ("hill_climb" in the survivor registry).

Parameters:
initializerInitializer

Population initializer (typically creates a single individual).

operatorOperator, optional

Perturbation operator. Defaults to NullOperator.

survivor_selSurvivorSelection, optional

Survivor selection method; defaults to "hill_climb".

paramsdict, optional

Additional parameters stored as schedulable values.

namestr, optional

Display name (default "HillClimb").

rngRNGLike, optional

Random number generator.

**kwargs

Forwarded to SearchStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

class LocalSearch(initializer, operator=None, survivor_sel=None, name='LocalSearch', iterations=100, rng=None, **kwargs)[source]#

Bases: PopulationBasedStrategy

Local Search algorithm.

At each iteration the current solution is duplicated iterations times, and every copy is perturbed independently. The best among the original and the perturbed copies survives. By default, the survivor selection is set to "local_search" (one parent vs. many offspring).

Parameters:
initializerInitializer

Population initializer.

operatorOperator, optional

Perturbation operator.

survivor_selSurvivorSelection, optional

Survivor selection; defaults to "local_search".

namestr, optional

Display name (default "LocalSearch").

iterationsint, optional

Number of perturbed copies per iteration (default 100).

rngRNGLike, optional

Random number generator.

**kwargs

Forwarded to SearchStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

class DE(initializer, de_operator_name='DE/best/1', survivor_sel=None, name='DE', rng=None, F=0.8, Cr=0.9, p=0.1, **kwargs)[source]#

Bases: PopulationBasedStrategy

Differential Evolution algorithm.

Uses a DE mutation operator (e.g., "DE/best/1") and one-to-one survivor selection by default. The population size stays constant, and every individual is perturbed each generation.

Parameters:
initializerInitializer

Population initializer.

de_operator_namestr, optional

DE variant (default "DE/best/1").

survivor_selSurvivorSelection, optional

Survivor selection; defaults to one-to-one competition.

namestr, optional

Display name (default "DE").

rngRNGLike, optional

Random number generator.

Ffloat or SchedulableParameter, optional

Scale factor (default 0.8).

Crfloat or SchedulableParameter, optional

Crossover probability (default 0.9).

pfloat or SchedulableParameter, optional

Elite fraction for /pbest/ variants (default 0.1).

**kwargs

Forwarded to StaticPopulation.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

class ES(initializer, mutation_op, crossover_op=None, parent_sel=None, survivor_sel=None, offspring_size=None, name='ES', rng=None, **kwargs)[source]#

Bases: ShuffledPopulationStrategy

Evolution Strategy (μ+λ or μ,λ).

Applies mutation (and optionally crossover) to the selected parents, then selects survivors. By default, no parent selection is performed (all individuals are used).

Parameters:
initializerInitializer

Population initializer.

mutation_opOperator

Mutation operator.

crossover_opOperator, optional

Crossover operator. If None, only mutation is applied.

parent_selParentSelection, optional

Parent selection (default: use the whole population).

survivor_selSurvivorSelection, optional

Survivor selection (default: generational).

offspring_sizeint, optional

Number of offspring per generation.

namestr, optional

Display name (default "ES").

**kwargs

Forwarded to VariablePopulation.

Attributes:
initializer
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

class GA(initializer, mutation_op, crossover_op, parent_sel, survivor_sel, name='GA', mutation_prob=0.1, crossover_prob=0.9, rng=None, **kwargs)[source]#

Bases: PopulationBasedStrategy

Genetic Algorithm.

Combines crossover (applied with probability crossover_prob) and mutation (applied per individual with probability mutation_prob) via a BranchOperator. The population size is constant.

Parameters:
initializerInitializer

Population initializer.

mutation_opOperator

Mutation operator (will be applied probabilistically).

crossover_opOperator

Crossover operator (applied pairwise).

parent_selParentSelection

Parent selection method.

survivor_selSurvivorSelection

Survivor selection method.

namestr, optional

Display name (default "GA").

mutation_probfloat or SchedulableParameter, optional

Individual-level probability of mutation (default 0.1).

crossover_probfloat or SchedulableParameter, optional

Pair-level probability of crossover (default 0.9). If the crossover operator supports it, this value is injected via update_kwargs.

rngRNGLike, optional

Random number generator.

**kwargs

Forwarded to StaticPopulation.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

class RandomSearch(initializer, name='RandomSearch', rng=None, **kwargs)[source]#

Bases: PopulationBasedStrategy

Random search algorithm.

Each iteration replaces the current population with completely new random individuals (via a random.random operator). No perturbation of existing solutions occurs.

Parameters:
initializerInitializer

Population initializer.

namestr, optional

Display name (default "RandomSearch").

**kwargs

Forwarded to HillClimb.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

initializer (Initializer)

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

class SA(initializer, operator, name='SA', iterations=100, temperature_init=100, alpha=0.99, rng=None, **kwargs)[source]#

Bases: SingleSolutionStrategy

Simulated Annealing algorithm.

A single solution is perturbed each iteration. The new solution is accepted if it is better, or probabilistically if it is worse, according to an exponentially decaying temperature schedule.

Parameters:
initializerInitializer

Population initializer (usually creates a single individual).

operatorOperator

Perturbation operator.

namestr, optional

Display name (default "SA").

iterationsint or SchedulableParameter, optional

Number of iterations at constant temperature (default 100).

temperature_initfloat or SchedulableParameter, optional

Starting temperature (default 100).

alphafloat or SchedulableParameter, optional

Cooling factor (default 0.99).

rngRNGLike, optional

Random number generator.

**kwargs

Forwarded to HillClimb.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

temperature
Parameters:

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Displays temperature values and acceptance probability.

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

extra_step_info()[source]#

Displays temperature values and acceptance probability.

class PSO(initializer, lower_bound=-100, upper_bound=100, name='PSO', w=0.7, c1=1.5, c2=1.5, encoding=None, rng=None, **kwargs)[source]#

Bases: PopulationBasedStrategy

Particle Swarm Optimization (PSO).

Each individual (particle) has a position and a velocity. The velocity is updated using personal and global bests, and the position is moved accordingly. This requires a ParameterExtendingEncoding that stores a speed vector; if not supplied, a default PSOEncoding is created.

Parameters:
initializerInitializer

Initializer for the solution part. An ExtendedInitializer is automatically created to handle the velocity parameter.

lower_boundfloat, optional

Lower bound of the search space (default -100).

upper_boundfloat, optional

Upper bound of the search space (default 100).

namestr, optional

Display name (default "PSO").

wfloat, optional

Inertia weight (default 0.7).

c1float, optional

Cognitive acceleration coefficient (default 1.5).

c2float, optional

Social acceleration coefficient (default 1.5).

encodingParameterExtendingEncoding, optional

Encoding that includes a "speed" parameter. If None, a PSOEncoding is used.

rngRNGLike, optional

Random number generator.

**kwargs

Forwarded to StaticPopulationStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Set up the initial population and attach velocity constraints.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

initialize(objfunc)[source]#

Set up the initial population and attach velocity constraints.

Parameters:
objfuncObjectiveFunc

The objective function. Its constraint handler is extended with a BounceBoundConstraint for the velocity so that speeds stay within the feasible range.

.. warning::
There is a known bug: the objective function **does not**
automatically remove the extended constraint handler after
a PSO run finishes. Reusing the same objective function
instance for other algorithms may cause unexpected
behavior. This will be resolved in a future release.
Returns:
Population

The initialized and evaluated population.

Parameters:

objfunc (ObjectiveFunc)

class BernoulliPBIL(initializer, parent_sel=None, survivor_sel=None, name='BernoulliPBIL', offspring_size=None, rng=None, p=None, lr=0.001, noise=0, **kwargs)[source]#

Bases: EDAStrategy

PBIL for binary vectors using a Bernoulli distribution.

The probability vector p is updated each generation with a learning rate and optional Gaussian noise, then a new population is sampled.

Reference: https://doi.org/10.1016/j.swevo.2011.08.003

Parameters:
initializerInitializer

Population initializer.

parent_selParentSelection, optional

Parent selection method.

survivor_selSurvivorSelection, optional

Survivor selection method.

namestr, optional

Display name (default "BernoulliPBIL").

offspring_sizeint or SchedulableParameter, optional

Number of offspring per generation.

rngRNGLike, optional

Random number generator.

parray-like, optional

Initial probability vector. Defaults to uniform over [0,1].

lrfloat, optional

Learning rate for updating p (default 1e-3).

noisefloat, optional

Standard deviation of Gaussian noise added to p (default 0).

**kwargs

Forwarded to EDAStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

estimate_parameters(population)

Utilizes the samples present in the input population to estimate the parameters used by the operator.

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

estimate_parameters(population)[source]#

Utilizes the samples present in the input population to estimate the parameters used by the operator.

Parameters:
populationPopulation

Data to use for estimating parameters.

Returns:
Operator

Newly configured operator.

class BernoulliUMDA(initializer, parent_sel=None, survivor_sel=None, name='BernoulliUMDA', offspring_size=None, rng=None, p=0.5, noise=0, **kwargs)[source]#

Bases: EDAStrategy

UMDA for binary vectors using a Bernoulli distribution.

The probability vector is estimated from the selected parents (no smoothing). Gaussian noise can optionally be added.

Reference: https://doi.org/10.1016/j.swevo.2011.08.003

Parameters:
initializerInitializer

Population initializer.

parent_selParentSelection, optional

Parent selection method.

survivor_selSurvivorSelection, optional

Survivor selection method.

namestr, optional

Display name (default "BernoulliUMDA").

offspring_sizeint or SchedulableParameter, optional

Number of offspring per generation.

rngRNGLike, optional

Random number generator.

pfloat or array-like, optional

Initial probability (default 0.5).

noisefloat, optional

Gaussian noise standard deviation (default 0).

**kwargs

Forwarded to EDAStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

estimate_parameters(population)

Utilizes the samples present in the input population to estimate the parameters used by the operator.

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

estimate_parameters(population)[source]#

Utilizes the samples present in the input population to estimate the parameters used by the operator.

Parameters:
populationPopulation

Data to use for estimating parameters.

Returns:
Operator

Newly configured operator.

class BinomialPBIL(initializer, parent_sel=None, survivor_sel=None, name='BernoulliPBIL', offspring_size=None, rng=None, p=0.5, n=None, lr=0.001, noise=0, **kwargs)[source]#

Bases: EDAStrategy

PBIL for discrete vectors using a Binomial distribution.

Reference: https://doi.org/10.1016/j.swevo.2011.08.003

Parameters:
initializerInitializer

Population initializer.

parent_selParentSelection, optional

Parent selection method.

survivor_selSurvivorSelection, optional

Survivor selection method.

namestr, optional

Display name (default "BinomialPBIL").

offspring_sizeint or SchedulableParameter, optional

Number of offspring per generation.

rngRNGLike, optional

Random number generator.

pfloat or array-like, optional

Initial success probability (default 0.5).

nint or array-like

Number of trials. Must be provided; there is no default.

lrfloat, optional

Learning rate (default 1e-3).

noisefloat, optional

Gaussian noise standard deviation (default 0).

**kwargs

Forwarded to EDAStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

estimate_parameters(population)

Utilizes the samples present in the input population to estimate the parameters used by the operator.

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

estimate_parameters(population)[source]#

Utilizes the samples present in the input population to estimate the parameters used by the operator.

Return type:

Operator

Parameters:
populationPopulation

Data to use for estimating parameters.

Returns:
Operator

Newly configured operator.

Parameters:

population (Population)

class BinomialUMDA(initializer, parent_sel=None, survivor_sel=None, name='BinomialUMDA', offspring_size=None, rng=None, p=0.5, n=None, noise=0, **kwargs)[source]#

Bases: EDAStrategy

UMDA for discrete vectors using a Binomial distribution.

Reference: https://doi.org/10.1016/j.swevo.2011.08.003

Parameters:
initializerInitializer

Population initializer.

parent_selParentSelection, optional

Parent selection method.

survivor_selSurvivorSelection, optional

Survivor selection method.

namestr, optional

Display name (default "BinomialUMDA").

offspring_sizeint or SchedulableParameter, optional

Number of offspring per generation.

rngRNGLike, optional

Random number generator.

pfloat or array-like, optional

Initial success probability (default 0.5).

nint or array-like

Number of trials. Must be provided; there is no default.

noisefloat, optional

Gaussian noise standard deviation (default 0).

**kwargs

Forwarded to EDAStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

estimate_parameters(population)

Utilizes the samples present in the input population to estimate the parameters used by the operator.

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

estimate_parameters(population)[source]#

Utilizes the samples present in the input population to estimate the parameters used by the operator.

Parameters:
populationPopulation

Data to use for estimating parameters.

Returns:
Operator

Newly configured operator.

class CrossEntropyMethod(initializer, name='CrossEntropyMethod', rng=None, elite_amount=None, scale='calculated', **kwargs)[source]#

Bases: EDAStrategy

Cross-Entropy Method for continuous optimization.

At each generation, the best individuals are selected and the mean of a Gaussian distribution is updated to their location, optionally with a scale estimated from the data. New solutions are sampled from this distribution.

Note

This class will be refactored when the EDA interface is finalized. Smoothing (learning rate) for the mean still needs to be added.

Parameters:
initializerInitializer

Population initializer.

namestr, optional

Display name (default "CrossEntropyMethod").

rngRNGLike, optional

Random number generator.

elite_amountint or SchedulableParameter, optional

Number of best individuals used to estimate the distribution.

scaleVectorLike or "calculated", optional

Standard deviation of the Gaussian. If "calculated", it is estimated from the selected individuals.

**kwargs

Forwarded to StaticPopulation.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:
  • initializer (Initializer)

  • name (str)

  • rng (int | Generator | None)

  • elite_amount (int | SchedulableParameter | None)

  • scale (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool] | str)

Methods

estimate_parameters(population)

Utilizes the samples present in the input population to estimate the parameters used by the operator.

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

estimate_parameters(population)[source]#

Utilizes the samples present in the input population to estimate the parameters used by the operator.

Return type:

Population

Parameters:
populationPopulation

Data to use for estimating parameters.

Returns:
Operator

Newly configured operator.

Parameters:

population (Population)

class GaussianPBIL(initializer, parent_sel=None, survivor_sel=None, name='GaussianPBIL', offspring_size=None, rng=None, loc=None, scale=1, lr=0.001, noise=0, **kwargs)[source]#

Bases: EDAStrategy

PBIL for continuous vectors using a Gaussian distribution.

The location vector loc is updated each generation with a learning rate and optional Gaussian noise, then a new population is sampled.

Reference: https://doi.org/10.1016/j.swevo.2011.08.003

Parameters:
initializerInitializer

Population initializer.

parent_selParentSelection, optional

Parent selection method.

survivor_selSurvivorSelection, optional

Survivor selection method.

namestr, optional

Display name (default "GaussianPBIL").

offspring_sizeint or SchedulableParameter, optional

Number of offspring per generation.

rngRNGLike, optional

Random number generator.

locarray-like, optional

Initial mean vector (default None; the operator uses a fallback).

scalefloat or array-like, optional

Standard deviation (default 1).

lrfloat, optional

Learning rate (default 1e-3).

noisefloat, optional

Gaussian noise standard deviation added to loc (default 0).

**kwargs

Forwarded to EDAStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

estimate_parameters(population)

Utilizes the samples present in the input population to estimate the parameters used by the operator.

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

estimate_parameters(population)[source]#

Utilizes the samples present in the input population to estimate the parameters used by the operator.

Parameters:
populationPopulation

Data to use for estimating parameters.

Returns:
Operator

Newly configured operator.

class GaussianUMDA(initializer, parent_sel=None, survivor_sel=None, name='GaussianUMDA', offspring_size=None, rng=None, loc=0, scale=1, noise=0, **kwargs)[source]#

Bases: EDAStrategy

UMDA for continuous vectors using a Gaussian distribution.

The location vector is estimated from the selected parents. Gaussian noise can optionally be added.

Reference: https://doi.org/10.1016/j.swevo.2011.08.003

Parameters:
initializerInitializer

Population initializer.

parent_selParentSelection, optional

Parent selection method.

survivor_selSurvivorSelection, optional

Survivor selection method.

namestr, optional

Display name (default "GaussianUMDA").

offspring_sizeint or SchedulableParameter, optional

Number of offspring per generation.

rngRNGLike, optional

Random number generator.

locfloat or array-like, optional

Initial mean (default 0).

scalefloat or array-like, optional

Standard deviation (default 1).

noisefloat, optional

Gaussian noise standard deviation added to loc (default 0).

**kwargs

Forwarded to EDAStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

estimate_parameters(population)

Utilizes the samples present in the input population to estimate the parameters used by the operator.

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

estimate_parameters(population)[source]#

Utilizes the samples present in the input population to estimate the parameters used by the operator.

Parameters:
populationPopulation

Data to use for estimating parameters.

Returns:
Operator

Newly configured operator.

class BayesianOptimization(initializer, objfunc, parent_sel=None, name='Bayesian Optimization', rng=None, **kwargs)[source]#

Bases: PopulationBasedStrategy

Bayesian Optimization using a Gaussian Process surrogate.

This strategy replaces the usual perturbation operator with a BOOperator, which fits a GP model to the current population and uses an acquisition function to propose new candidates.

Parameters:
initializerInitializer

Population initializer (provides the starting points).

parent_selParentSelection, optional

Parent selection method (default: identity).

namestr, optional

Display name (default "Bayesian Optimization").

**kwargs

Forwarded to BOOperator (e.g., batch_size, max_samples, kernel).

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

class MemeticStrategy(main_strategy, local_search_heuristic, local_search_depth=1, local_search_frequency=1, keep_improved_solutions=True, improvement_selection=None, rng=None)[source]#

Bases: SearchStrategy

Strategy that combines a main search strategy with a local search procedure that improves solutions after they are evolved.

Parameters:
main_strategySearchStrategy

Main search strategy used in the optimization algorithm.

local_search_heuristicSearchStrategy

Local search procedure used to improve solutions after evolution.

local_search_depthint, optional

Number of times to repeat the local search procedure per iteration, by default 1

keep_improved_solutionsstr, optional

Whether to keep the improved solutions for the next iteration (Lamarkian memetic algorithms) or to just update the fitness keeping the original solution values (Baldwinian memetic algorithms), by default True

improvement_selectionParentSelection, optional

Selection method with which to pick the solutions that will be improved with local search, by default None

rngOperator[RNGLike], optional

Random number generator, by default None

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:
  • main_strategy (SearchStrategy)

  • local_search_heuristic (SearchStrategy)

  • local_search_depth (int)

  • local_search_frequency (int)

  • keep_improved_solutions (bool)

  • improvement_selection (ParentSelection)

  • rng (int | Generator | None)

Methods

extra_report()

Hook called at the end of the optimization (intended for subclasses).

extra_step_info()

Hook called after each generation (intended for subclasses).

gather_parameters()

Collect the current parameters from all sub-components.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the search strategy as a dictionary.

initialize(objfunc)

Initializes the optimization search strategy.

step(prev_population, objfunc)

Performs a single iteration of the algorithm on a given population.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Advances the state of the search by one iteration.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

reset

update(progress)[source]#

Advances the state of the search by one iteration.

Parameters:
progressfloat

Current progress of the algorithm (0-1).

Parameters:

progress (float)

step(prev_population, objfunc)[source]#

Performs a single iteration of the algorithm on a given population.

Return type:

Population

Parameters:
populationPopulation

Population of solutions in which to perform the operators.

Returns:
Population

Next population after performing all the steps in the iteration.

Parameters:
get_state()[source]#

Gets the current state of the search strategy as a dictionary.

Return type:

dict

Parameters:
show_population: bool, optional

Save the state of the current population.

Returns:
state: dict

The complete state of the search strategy.