metaheuristic_designer.strategies package¶
Subpackages¶
- metaheuristic_designer.strategies.EDA package
- metaheuristic_designer.strategies.bayesian_optimization package
- metaheuristic_designer.strategies.classic package
- Submodules
- metaheuristic_designer.strategies.classic.CMA_ES module
- metaheuristic_designer.strategies.classic.DE module
- metaheuristic_designer.strategies.classic.ES module
- metaheuristic_designer.strategies.classic.GA module
- metaheuristic_designer.strategies.classic.SA module
- metaheuristic_designer.strategies.classic.random_search module
- Module contents
- metaheuristic_designer.strategies.swarm package
Submodules¶
metaheuristic_designer.strategies.hill_climb module¶
Hill Climbing strategy (single-solution, greedy local improvement).
- class HillClimb(initializer: Initializer, operator: Operator | None = None, survivor_sel: SurvivorSelection | None = None, params: dict | None = None, name: str = 'HillClimb', random_state: int | Generator | None = None, **kwargs)[source]¶
Bases:
SearchStrategyHill 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:
initializer (Initializer) – Population initializer (typically creates a single individual).
operator (Operator, optional) – Perturbation operator. Defaults to
NullOperator.survivor_sel (SurvivorSelection, optional) – Survivor selection method; defaults to
"hill_climb".params (dict, optional) – Additional parameters stored as schedulable values.
name (str, optional) – Display name (default
"HillClimb").random_state (RNGLike, optional) – Random number generator.
**kwargs – Forwarded to
SearchStrategy.
metaheuristic_designer.strategies.local_search module¶
Local Search strategy (single solution, multiple perturbations per iteration).
- class LocalSearch(initializer: Initializer, operator: Operator | None = None, survivor_sel: SurvivorSelection | None = None, name: str = 'LocalSearch', iterations: int = 100, random_state: int | Generator | None = None, **kwargs)[source]¶
Bases:
SearchStrategyLocal 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:
initializer (Initializer) – Population initializer.
operator (Operator, optional) – Perturbation operator.
survivor_sel (SurvivorSelection, optional) – Survivor selection; defaults to
"local_search".name (str, optional) – Display name (default
"LocalSearch").iterations (int, optional) – Number of perturbed copies per iteration (default 100).
random_state (RNGLike, optional) – Random number generator.
**kwargs – Forwarded to
SearchStrategy.
- perturb(parents: Population, **kwargs) Population[source]¶
Duplicate the parent iterations times, then apply the operator.
- Parameters:
parents (Population) – The current solution(s).
**kwargs – Forwarded to
SearchStrategy.perturb.
- Returns:
The perturbed copies.
- Return type:
metaheuristic_designer.strategies.no_search module¶
No-op strategy that returns the population unchanged (debug / baseline).
- class NoSearch(initializer: Initializer, name: str = 'No search', **kwargs)[source]¶
Bases:
SearchStrategyDebug strategy that does nothing.
The population is never modified. Useful as a baseline or for testing other components in isolation.
- Parameters:
initializer (Initializer) – Population initializer.
name (str, optional) – Display name (default
"No search").**kwargs – Forwarded to
SearchStrategy.
- perturb(parents: Population, **kwargs) Population[source]¶
Return the parents unchanged.
- Parameters:
parents (Population) – The current population.
**kwargs – Unused.
- Returns:
The same population, unmodified.
- Return type:
metaheuristic_designer.strategies.static_population module¶
Strategy where the population size remains constant, no explicit parent selection.
- class StaticPopulation(initializer: Initializer, operator: Operator, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, name: str = 'Static Population Evolution', random_state: int | Generator | None = None, **kwargs)[source]¶
Bases:
SearchStrategyPopulation-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:
initializer (Initializer) – Population initializer.
operator (Operator) – Perturbation operator.
parent_sel (ParentSelection, optional) – Parent selection; defaults to identity (keep all).
survivor_sel (SurvivorSelection, optional) – Survivor selection; defaults to generational replacement.
name (str, optional) – Display name (default
"Static Population Evolution").random_state (RNGLike, optional) – Random number generator.
**kwargs – Forwarded to
SearchStrategy.
metaheuristic_designer.strategies.variable_population module¶
Strategy where offspring size differs from population size (μ+λ / μ,λ style).
- class VariablePopulation(initializer: Initializer, operator: Operator, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, offspring_size: int | SchedulableParameter | None = None, shuffle_with_replacement: bool = False, name: str = 'Variable Population Evolution', random_state: int | Generator | None = None, **kwargs)[source]¶
Bases:
SearchStrategyPopulation-based strategy with separate parent and offspring sizes.
This is the base for (μ+λ) and (μ,λ) Evolution Strategies, GAs with elitism, and similar algorithms. The number of parents selected and the number of offspring generated can be configured independently.
- Parameters:
initializer (Initializer) – Population initializer.
operator (Operator) – Perturbation operator.
parent_sel (ParentSelection, optional) – Parent selection method.
survivor_sel (SurvivorSelection, optional) – Survivor selection method.
offspring_size (int or SchedulableParameter, optional) – Number of offspring to generate. Defaults to the initializer’s population size.
shuffle_with_replacement (bool, optional) – If
True, shuffle the parent pool with replacement; otherwise without replacement (defaultFalse).name (str, optional) – Display name.
random_state (RNGLike, optional) – Random number generator.
**kwargs – Forwarded to
SearchStrategy.
- property initializer: Initializer¶
- select_parents(population: Population) Population[source]¶
Select parents, then optionally shuffle the pool.
- Parameters:
population (Population) – Current population.
- Returns:
The (possibly shuffled) selected parents.
- Return type:
Module contents¶
Built-in search strategy implementations.
- class HillClimb(initializer: Initializer, operator: Operator | None = None, survivor_sel: SurvivorSelection | None = None, params: dict | None = None, name: str = 'HillClimb', random_state: int | Generator | None = None, **kwargs)[source]¶
Bases:
SearchStrategyHill 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:
initializer (Initializer) – Population initializer (typically creates a single individual).
operator (Operator, optional) – Perturbation operator. Defaults to
NullOperator.survivor_sel (SurvivorSelection, optional) – Survivor selection method; defaults to
"hill_climb".params (dict, optional) – Additional parameters stored as schedulable values.
name (str, optional) – Display name (default
"HillClimb").random_state (RNGLike, optional) – Random number generator.
**kwargs – Forwarded to
SearchStrategy.
- class LocalSearch(initializer: Initializer, operator: Operator | None = None, survivor_sel: SurvivorSelection | None = None, name: str = 'LocalSearch', iterations: int = 100, random_state: int | Generator | None = None, **kwargs)[source]¶
Bases:
SearchStrategyLocal 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:
initializer (Initializer) – Population initializer.
operator (Operator, optional) – Perturbation operator.
survivor_sel (SurvivorSelection, optional) – Survivor selection; defaults to
"local_search".name (str, optional) – Display name (default
"LocalSearch").iterations (int, optional) – Number of perturbed copies per iteration (default 100).
random_state (RNGLike, optional) – Random number generator.
**kwargs – Forwarded to
SearchStrategy.
- perturb(parents: Population, **kwargs) Population[source]¶
Duplicate the parent iterations times, then apply the operator.
- Parameters:
parents (Population) – The current solution(s).
**kwargs – Forwarded to
SearchStrategy.perturb.
- Returns:
The perturbed copies.
- Return type:
- class NoSearch(initializer: Initializer, name: str = 'No search', **kwargs)[source]¶
Bases:
SearchStrategyDebug strategy that does nothing.
The population is never modified. Useful as a baseline or for testing other components in isolation.
- Parameters:
initializer (Initializer) – Population initializer.
name (str, optional) – Display name (default
"No search").**kwargs – Forwarded to
SearchStrategy.
- perturb(parents: Population, **kwargs) Population[source]¶
Return the parents unchanged.
- Parameters:
parents (Population) – The current population.
**kwargs – Unused.
- Returns:
The same population, unmodified.
- Return type:
- class SearchStrategy(initializer: Initializer, operator: Operator | None = None, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, name: str = 'some strategy', random_state: int | Generator | None = None, **kwargs)[source]¶
Bases:
ParametrizableMixinOrchestrates one iteration of an optimisation loop.
A search strategy holds together an
Initializer, anOperator, aParentSelection, and aSurvivorSelection. Together they define how the population is created, perturbed, and pruned each generation. Subclasses can override any step to implement algorithm-specific logic.- Parameters:
initializer (Initializer) – Creates the starting population.
operator (Operator, optional) – The perturbation operator (mutation, crossover, …). Defaults to
NullOperator.parent_sel (ParentSelection, optional) – Selects which individuals are used to generate offspring. Defaults to
NullParentSelection.survivor_sel (SurvivorSelection, optional) – Selects which individuals survive to the next generation. Defaults to
NullSurvivorSelection.name (str, optional) – Display name used in reports.
random_state (RNGLike, optional) – Random number generator.
**kwargs – Additional keyword arguments stored as schedulable parameters.
- property population_size: int¶
Gets the amount of individuals in the population.
- gather_parameters()[source]¶
Collect the current parameters from all sub-components.
- Returns:
A flat dictionary with dotted keys like
"operator.F","parent_sel.amount", etc.- Return type:
dict
- best_solution() Tuple[Any, float][source]¶
Returns the best solution found by the search strategy and its fitness.
- Returns:
best_solution – A pair of the best individual with its fitness.
- Return type:
Tuple[Any, float]
- initialize(objfunc: ObjectiveFunc) Population[source]¶
Initializes the optimization search strategy.
- Parameters:
objfunc (ObjectiveFunc) – Objective function to be optimized.
- Returns:
population – The initial population to be used in the algoritm.
- Return type:
- evaluate_population(population: Population, parallel: bool = False, threads: int = 8) Population[source]¶
Calculates the fitness of the individuals on the population.
- Parameters:
population (Population)
parallel (bool, optional) – Whether to evaluate the individuals in the population in parallel.
threads (int, optional) – Number of processes to use at once if calculating the fitness in parallel.
- Returns:
population – The population with the fitness values recorded.
- Return type:
- select_parents(population: Population, amount: int | None = None) Population[source]¶
Selects the individuals that will be perturbed in this generation to generate the offspring.
- Parameters:
population (Population) – The current population of the search strategy.
- Returns:
parents – A pair of the list of individuals considered as parents and their position in the original population.
- Return type:
- perturb(parents: Population, **kwargs) Population[source]¶
Applies operators to the population to get the next generation of individuals.
- Parameters:
parents (Population) – The current parents that will be used in the search strategy.
- Returns:
offspring – The list of individuals modified by the operators of the search strategy.
- Return type:
- repair_population(population: Population) Population[source]¶
Repairs the individuals in the population to make them fulfill the problem’s restrictions.
- Parameters:
population (Population) – The population to be repaired
- Returns:
repaired_population – The population of repaired individuals
- Return type:
- select_individuals(population: Population, offspring: Population, **kwargs) Population[source]¶
Selects the individuals that will pass to the next generation.
- Parameters:
population (Population) – The current population of the search strategy.
offspring (Population) – The list of individuals modified by the operators of the search strategy.
- Returns:
offspring – The list of individuals selected for the next generation.
- Return type:
- step(progress: float)[source]¶
Update internal parameters and forward progress to sub-components.
- Parameters:
progress (float) – Current progress of the algorithm (0-1).
- class StaticPopulation(initializer: Initializer, operator: Operator, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, name: str = 'Static Population Evolution', random_state: int | Generator | None = None, **kwargs)[source]¶
Bases:
SearchStrategyPopulation-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:
initializer (Initializer) – Population initializer.
operator (Operator) – Perturbation operator.
parent_sel (ParentSelection, optional) – Parent selection; defaults to identity (keep all).
survivor_sel (SurvivorSelection, optional) – Survivor selection; defaults to generational replacement.
name (str, optional) – Display name (default
"Static Population Evolution").random_state (RNGLike, optional) – Random number generator.
**kwargs – Forwarded to
SearchStrategy.
- class VariablePopulation(initializer: Initializer, operator: Operator, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, offspring_size: int | SchedulableParameter | None = None, shuffle_with_replacement: bool = False, name: str = 'Variable Population Evolution', random_state: int | Generator | None = None, **kwargs)[source]¶
Bases:
SearchStrategyPopulation-based strategy with separate parent and offspring sizes.
This is the base for (μ+λ) and (μ,λ) Evolution Strategies, GAs with elitism, and similar algorithms. The number of parents selected and the number of offspring generated can be configured independently.
- Parameters:
initializer (Initializer) – Population initializer.
operator (Operator) – Perturbation operator.
parent_sel (ParentSelection, optional) – Parent selection method.
survivor_sel (SurvivorSelection, optional) – Survivor selection method.
offspring_size (int or SchedulableParameter, optional) – Number of offspring to generate. Defaults to the initializer’s population size.
shuffle_with_replacement (bool, optional) – If
True, shuffle the parent pool with replacement; otherwise without replacement (defaultFalse).name (str, optional) – Display name.
random_state (RNGLike, optional) – Random number generator.
**kwargs – Forwarded to
SearchStrategy.
- property initializer: Initializer¶
- select_parents(population: Population) Population[source]¶
Select parents, then optionally shuffle the pool.
- Parameters:
population (Population) – Current population.
- Returns:
The (possibly shuffled) selected parents.
- Return type:
- class CMA_ES(initializer: Initializer, survivor_sel: SurvivorSelection | None = None, name: str = 'CMA-ES', offspring_size: int | SchedulableParameter | None = None, random_state=None, mean: ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool] | None = None, sigma: ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool] | None = None, **kwargs)[source]¶
Bases:
SearchStrategyCovariance 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()andperturb()directly. Once the distribution-based (EDA) abstraction is in place, CMA-ES will be rewritten to use that common interface.- Parameters:
initializer (Initializer) – Provides population size and genotype shape, but does not generate the initial solutions.
survivor_sel (SurvivorSelection, optional) – How survivors are selected. Defaults to the strategy’s default (generational).
name (str, optional) – Display name (default
"CMA-ES").offspring_size (int or SchedulableParameter, optional) – Number of offspring per generation. If
None, the initializer’s population size is used.random_state (RNGLike, optional) – Random number generator.
mean (VectorLike, optional) – Initial mean vector. If not given, it is computed from the objective’s bounds (or randomly if no bounds exist).
sigma (VectorLike, optional) – Initial step size. If not given, a default is computed.
**kwargs – Forwarded to
VariablePopulation.
- initialize(objfunc: ObjectiveFunc) Population[source]¶
Create the initial population by sampling from the current distribution.
- Parameters:
objfunc (ObjectiveFunc) – The objective function, used to infer bounds if mean or sigma are not provided.
- Returns:
A freshly sampled population with unevaluated fitness.
- Return type:
- perturb(parents: Population, **kwargs) Population[source]¶
Update the distribution parameters and generate offspring.
The parents (the best μ individuals from the previous generation) are used to update mean, sigma, covariance, and the evolution paths. A new offspring population is then sampled from the updated distribution.
- Parameters:
parents (Population) – The selected parents (must be already evaluated).
**kwargs – Forwarded to the parent’s
perturb().
- Returns:
Offspring population of size offspring_size.
- Return type:
- class DE(initializer: Initializer, de_operator_name: str = 'DE/best/1', survivor_sel: SurvivorSelection | None = None, name: str = 'DE', random_state: int | Generator | None = None, F: float | SchedulableParameter = 0.8, Cr: float | SchedulableParameter = 0.9, p: float | SchedulableParameter = 0.1, **kwargs)[source]¶
Bases:
StaticPopulationDifferential 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:
initializer (Initializer) – Population initializer.
de_operator_name (str, optional) – DE variant (default
"DE/best/1").survivor_sel (SurvivorSelection, optional) – Survivor selection; defaults to one-to-one competition.
name (str, optional) – Display name (default
"DE").random_state (RNGLike, optional) – Random number generator.
F (float or SchedulableParameter, optional) – Scale factor (default 0.8).
Cr (float or SchedulableParameter, optional) – Crossover probability (default 0.9).
p (float or SchedulableParameter, optional) – Elite fraction for
/pbest/variants (default 0.1).**kwargs – Forwarded to
StaticPopulation.
- class ES(initializer: Initializer, mutation_op: Operator, crossover_op: Operator | None = None, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, offspring_size: int | None = None, name: str = 'ES', **kwargs)[source]¶
Bases:
VariablePopulationEvolution 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:
initializer (Initializer) – Population initializer.
mutation_op (Operator) – Mutation operator.
crossover_op (Operator, optional) – Crossover operator. If
None, only mutation is applied.parent_sel (ParentSelection, optional) – Parent selection (default: use the whole population).
survivor_sel (SurvivorSelection, optional) – Survivor selection (default: generational).
offspring_size (int, optional) – Number of offspring per generation.
name (str, optional) – Display name (default
"ES").**kwargs – Forwarded to
VariablePopulation.
- class GA(initializer: Initializer, mutation_op: Operator, crossover_op: Operator, parent_sel: ParentSelection, survivor_sel: SurvivorSelection, name: str = 'GA', mutation_prob: float | SchedulableParameter = 0.1, crossover_prob: float | SchedulableParameter = 0.9, random_state: int | Generator | None = None, **kwargs)[source]¶
Bases:
StaticPopulationGenetic 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:
initializer (Initializer) – Population initializer.
mutation_op (Operator) – Mutation operator (will be applied probabilistically).
crossover_op (Operator) – Crossover operator (applied pairwise).
parent_sel (ParentSelection) – Parent selection method.
survivor_sel (SurvivorSelection) – Survivor selection method.
name (str, optional) – Display name (default
"GA").mutation_prob (float or SchedulableParameter, optional) – Individual-level probability of mutation (default 0.1).
crossover_prob (float or SchedulableParameter, optional) – Pair-level probability of crossover (default 0.9). If the crossover operator supports it, this value is injected via
update_kwargs.random_state (RNGLike, optional) – Random number generator.
**kwargs – Forwarded to
StaticPopulation.
- class RandomSearch(initializer, name='RandomSearch', **kwargs)[source]¶
Bases:
HillClimbRandom search algorithm.
Each iteration replaces the current population with completely new random individuals (via a
random.randomoperator). No perturbation of existing solutions occurs.- Parameters:
initializer (Initializer) – Population initializer.
name (str, optional) – Display name (default
"RandomSearch").**kwargs – Forwarded to
HillClimb.
- class SA(initializer: Initializer, operator: Operator, name: str = 'SA', iterations: int | SchedulableParameter = 100, temperature_init: float | SchedulableParameter = 100, alpha: float | SchedulableParameter = 0.99, random_state: int | Generator | None = None, **kwargs)[source]¶
Bases:
HillClimbSimulated 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.
Warning
The current handling of the annealing schedule is tightly coupled to the strategy. The survivor selection should be refactored to manage its own temperature and acceptance logic independently.
- Parameters:
initializer (Initializer) – Population initializer (usually creates a single individual).
operator (Operator) – Perturbation operator.
name (str, optional) – Display name (default
"SA").iterations (int or SchedulableParameter, optional) – Number of iterations at constant temperature (default 100).
temperature_init (float or SchedulableParameter, optional) – Starting temperature (default 100).
alpha (float or SchedulableParameter, optional) – Cooling factor (default 0.99).
random_state (RNGLike, optional) – Random number generator.
**kwargs – Forwarded to
HillClimb.
- class PSO(initializer: Initializer, lower_bound: float = -100, upper_bound: float = 100, name: str = 'PSO', w=0.7, c1=1.5, c2=1.5, encoding: ParameterExtendingEncoding | None = None, random_state: int | Generator | None = None, **kwargs)[source]¶
Bases:
StaticPopulationParticle 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
ParameterExtendingEncodingthat stores a speed vector; if not supplied, a defaultPSOEncodingis created.- Parameters:
initializer (Initializer) – Initializer for the solution part. An
ExtendedInitializeris automatically created to handle the velocity parameter.lower_bound (float, optional) – Lower bound of the search space (default -100).
upper_bound (float, optional) – Upper bound of the search space (default 100).
name (str, optional) – Display name (default
"PSO").w (float, optional) – Inertia weight (default 0.7).
c1 (float, optional) – Cognitive acceleration coefficient (default 1.5).
c2 (float, optional) – Social acceleration coefficient (default 1.5).
encoding (ParameterExtendingEncoding, optional) – Encoding that includes a
"speed"parameter. IfNone, aPSOEncodingis used.random_state (RNGLike, optional) – Random number generator.
**kwargs – Forwarded to
StaticPopulation.
- initialize(objfunc: ObjectiveFunc)[source]¶
Set up the initial population and attach velocity constraints.
- Parameters:
objfunc (ObjectiveFunc) – The objective function. Its constraint handler is extended with a
BounceBoundConstraintfor the velocity so that speeds stay within the feasible range.warning:: (..)
bug (There is a known)
after (automatically remove the extended constraint handler)
function (a PSO run finishes. Reusing the same objective)
unexpected (instance for other algorithms may cause)
release. (behaviour. This will be resolved in a future)
- Returns:
The initialised and evaluated population.
- Return type:
- class BernoulliPBIL(initializer: Initializer, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, name: str = 'BernoulliPBIL', offspring_size: int | SchedulableParameter | None = None, random_state=None, p=None, lr=0.001, noise=0, **kwargs)[source]¶
Bases:
VariablePopulationPBIL 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:
initializer (Initializer) – Population initializer.
parent_sel (ParentSelection, optional) – Parent selection method.
survivor_sel (SurvivorSelection, optional) – Survivor selection method.
name (str, optional) – Display name (default
"BernoulliPBIL").offspring_size (int or SchedulableParameter, optional) – Number of offspring per generation.
random_state (RNGLike, optional) – Random number generator.
p (array-like, optional) – Initial probability vector. Defaults to uniform over [0,1].
lr (float, optional) – Learning rate for updating p (default 1e-3).
noise (float, optional) – Standard deviation of Gaussian noise added to p (default 0).
**kwargs – Forwarded to
VariablePopulation.
- perturb(parents, **kwargs)[source]¶
Applies operators to the population to get the next generation of individuals.
- Parameters:
parents (Population) – The current parents that will be used in the search strategy.
- Returns:
offspring – The list of individuals modified by the operators of the search strategy.
- Return type:
- class BernoulliUMDA(initializer: Initializer, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, name: str = 'BernoulliUMDA', offspring_size: int | SchedulableParameter | None = None, random_state=None, p: number | float | int | SchedulableParameter = 0.5, noise: number | float | int | SchedulableParameter = 0, **kwargs)[source]¶
Bases:
VariablePopulationUMDA 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:
initializer (Initializer) – Population initializer.
parent_sel (ParentSelection, optional) – Parent selection method.
survivor_sel (SurvivorSelection, optional) – Survivor selection method.
name (str, optional) – Display name (default
"BernoulliUMDA").offspring_size (int or SchedulableParameter, optional) – Number of offspring per generation.
random_state (RNGLike, optional) – Random number generator.
p (float or array-like, optional) – Initial probability (default 0.5).
noise (float, optional) – Gaussian noise standard deviation (default 0).
**kwargs – Forwarded to
VariablePopulation.
- perturb(parents, **kwargs)[source]¶
Applies operators to the population to get the next generation of individuals.
- Parameters:
parents (Population) – The current parents that will be used in the search strategy.
- Returns:
offspring – The list of individuals modified by the operators of the search strategy.
- Return type:
- class BinomialPBIL(initializer: Initializer, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, name: str = 'BernoulliPBIL', offspring_size: int | SchedulableParameter | None = None, random_state=None, p=0.5, n=None, lr=0.001, noise=0, **kwargs)[source]¶
Bases:
VariablePopulationPBIL for discrete vectors using a Binomial distribution.
Reference: https://doi.org/10.1016/j.swevo.2011.08.003
- Parameters:
initializer (Initializer) – Population initializer.
parent_sel (ParentSelection, optional) – Parent selection method.
survivor_sel (SurvivorSelection, optional) – Survivor selection method.
name (str, optional) – Display name (default
"BinomialPBIL").offspring_size (int or SchedulableParameter, optional) – Number of offspring per generation.
random_state (RNGLike, optional) – Random number generator.
p (float or array-like, optional) – Initial success probability (default 0.5).
n (int or array-like) – Number of trials. Must be provided; there is no default.
lr (float, optional) – Learning rate (default 1e-3).
noise (float, optional) – Gaussian noise standard deviation (default 0).
**kwargs – Forwarded to
VariablePopulation.
- perturb(parents, **kwargs)[source]¶
Applies operators to the population to get the next generation of individuals.
- Parameters:
parents (Population) – The current parents that will be used in the search strategy.
- Returns:
offspring – The list of individuals modified by the operators of the search strategy.
- Return type:
- class BinomialUMDA(initializer: Initializer, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, name: str = 'BinomialUMDA', offspring_size: int | SchedulableParameter | None = None, random_state: int | Generator | None = None, p: number | float | int | SchedulableParameter = 0.5, n: number | float | int | SchedulableParameter | None = None, noise=0, **kwargs)[source]¶
Bases:
VariablePopulationUMDA for discrete vectors using a Binomial distribution.
Reference: https://doi.org/10.1016/j.swevo.2011.08.003
- Parameters:
initializer (Initializer) – Population initializer.
parent_sel (ParentSelection, optional) – Parent selection method.
survivor_sel (SurvivorSelection, optional) – Survivor selection method.
name (str, optional) – Display name (default
"BinomialUMDA").offspring_size (int or SchedulableParameter, optional) – Number of offspring per generation.
random_state (RNGLike, optional) – Random number generator.
p (float or array-like, optional) – Initial success probability (default 0.5).
n (int or array-like) – Number of trials. Must be provided; there is no default.
noise (float, optional) – Gaussian noise standard deviation (default 0).
**kwargs – Forwarded to
VariablePopulation.
- perturb(parents, **kwargs)[source]¶
Applies operators to the population to get the next generation of individuals.
- Parameters:
parents (Population) – The current parents that will be used in the search strategy.
- Returns:
offspring – The list of individuals modified by the operators of the search strategy.
- Return type:
- class CrossEntropyMethod(initializer: Initializer, name: str = 'CrossEntropyMethod', random_state: int | Generator | None = None, elite_amount: int | SchedulableParameter | None = None, scale: ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool] | str = 'calculated', **kwargs)[source]¶
Bases:
StaticPopulationCross-Entropy Method for continuous optimisation.
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 finalised. Smoothing (learning rate) for the mean still needs to be added.
- Parameters:
initializer (Initializer) – Population initializer.
name (str, optional) – Display name (default
"CrossEntropyMethod").random_state (RNGLike, optional) – Random number generator.
elite_amount (int or SchedulableParameter, optional) – Number of best individuals used to estimate the distribution.
scale (VectorLike or
"calculated", optional) – Standard deviation of the Gaussian. If"calculated", it is estimated from the selected individuals.**kwargs – Forwarded to
StaticPopulation.
- class GaussianPBIL(initializer: Initializer, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, name: str = 'GaussianPBIL', offspring_size: int | SchedulableParameter | None = None, random_state=None, loc=None, scale=1, lr=0.001, noise=0, **kwargs)[source]¶
Bases:
VariablePopulationPBIL 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:
initializer (Initializer) – Population initializer.
parent_sel (ParentSelection, optional) – Parent selection method.
survivor_sel (SurvivorSelection, optional) – Survivor selection method.
name (str, optional) – Display name (default
"GaussianPBIL").offspring_size (int or SchedulableParameter, optional) – Number of offspring per generation.
random_state (RNGLike, optional) – Random number generator.
loc (array-like, optional) – Initial mean vector (default
None; the operator uses a fallback).scale (float or array-like, optional) – Standard deviation (default 1).
lr (float, optional) – Learning rate (default 1e-3).
noise (float, optional) – Gaussian noise standard deviation added to loc (default 0).
**kwargs – Forwarded to
VariablePopulation.
- perturb(parents, **kwargs)[source]¶
Applies operators to the population to get the next generation of individuals.
- Parameters:
parents (Population) – The current parents that will be used in the search strategy.
- Returns:
offspring – The list of individuals modified by the operators of the search strategy.
- Return type:
- class GaussianUMDA(initializer: Initializer, parent_sel: ParentSelection | None = None, survivor_sel: SurvivorSelection | None = None, name: str = 'GaussianUMDA', offspring_size: int | SchedulableParameter | None = None, random_state=None, loc: number | float | int | ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool] | SchedulableParameter = 0, scale: number | float | int | ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool] | SchedulableParameter = 1, noise: number | float | int | SchedulableParameter = 0, **kwargs)[source]¶
Bases:
VariablePopulationUMDA 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:
initializer (Initializer) – Population initializer.
parent_sel (ParentSelection, optional) – Parent selection method.
survivor_sel (SurvivorSelection, optional) – Survivor selection method.
name (str, optional) – Display name (default
"GaussianUMDA").offspring_size (int or SchedulableParameter, optional) – Number of offspring per generation.
random_state (RNGLike, optional) – Random number generator.
loc (float or array-like, optional) – Initial mean (default 0).
scale (float or array-like, optional) – Standard deviation (default 1).
noise (float, optional) – Gaussian noise standard deviation added to loc (default 0).
**kwargs – Forwarded to
VariablePopulation.
- perturb(parents, **kwargs)[source]¶
Applies operators to the population to get the next generation of individuals.
- Parameters:
parents (Population) – The current parents that will be used in the search strategy.
- Returns:
offspring – The list of individuals modified by the operators of the search strategy.
- Return type:
- class BayesianOptimization(initializer: Initializer, parent_sel: ParentSelection | None = None, name: str = 'Bayesian Optimization', **kwargs)[source]¶
Bases:
SearchStrategyBayesian 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:
initializer (Initializer) – Population initializer (provides the starting points).
parent_sel (ParentSelection, optional) – Parent selection method (default: identity).
name (str, optional) – Display name (default
"Bayesian Optimization").**kwargs – Forwarded to
BOOperator(e.g.,batch_size,max_samples,kernel).