metaheuristic_designer.strategies.classic package#

Submodules#

Module contents#

Classic population-based strategies (GA, DE, ES, CMA-ES, SA, RandomSearch).

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

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

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

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

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

reset

extra_step_info()[source]#

Displays temperature values and acceptance probability.