metaheuristic_designer.parent_selection_base module#
Base class for the Parent Selection module.
- class ParentSelection(name=None, amount=None, rng=None, **kwargs)[source]#
Bases:
ParametrizableMixin,ABCAbstract base for all parent selection methods.
A parent selection chooses which individuals from the current population will be used to generate offspring. Subclasses must implement
select(), which returns a newPopulationcontaining only the selected individuals.- Parameters:
- namestr, optional
Display name for this selection method.
- amountint, optional
Default number of individuals to select. Can be overridden at call time.
- rngRNGLike, optional
Random number generator.
- **kwargs
Additional keyword arguments stored as schedulable parameters.
- Attributes:
paramsAccess parameter values by attribute-style lookup.
- Parameters:
name (Optional[str])
amount (Optional[int])
rng (Optional[RNGLike])
Methods
__call__(population[, amount])Shorthand for
select().Return the current parameter dictionary (thin wrapper around
get_params()).get_params()Return a copy of the current parameter dictionary.
Return a dictionary with the selection method's configuration.
select(population[, amount])Takes a population with its offspring and returns the individuals that survive to produce the next generation.
store_kwargs([progress])Store keyword arguments and evaluate them at the given progress.
update(progress)Re-evaluate all stored parameters at the current progress.
update_kwargs([progress])Add or replace parameters and immediately evaluate them.
- gather_params()[source]#
Return the current parameter dictionary (thin wrapper around
get_params()).- Return type:
dict
- abstract select(population, amount=None)[source]#
Takes a population with its offspring and returns the individuals that survive to produce the next generation.
- Return type:
- Parameters:
- population: Population
Population of individuals that will be selected.
- offspring: Population
Newly generated individuals to be selected.
- Returns:
- selected: Population
List of selected individuals.
- Parameters:
population (Population)
amount (int | None)
- class NullParentSelection(name='Nothing', **kwargs)[source]#
Bases:
ParentSelectionNull parent selection, returns the whole population unchanged.
This is the identity element: no individuals are filtered out. Useful when the algorithm does not require a parent selection step (e.g., random search or certain evolution strategies).
- Parameters:
- namestr, optional
Display name. Default
"Nothing".- **kwargs
Keyword arguments forwarded to
ParentSelection.
- Attributes:
paramsAccess parameter values by attribute-style lookup.
- Parameters:
name (Optional[str])
Methods
__call__(population[, amount])Shorthand for
select().gather_params()Return the current parameter dictionary (thin wrapper around
get_params()).get_params()Return a copy of the current parameter dictionary.
get_state()Return a dictionary with the selection method's configuration.
select(population[, amount])Takes a population with its offspring and returns the individuals that survive to produce the next generation.
store_kwargs([progress])Store keyword arguments and evaluate them at the given progress.
update(progress)Re-evaluate all stored parameters at the current progress.
update_kwargs([progress])Add or replace parameters and immediately evaluate them.
- select(population, amount=None)[source]#
Takes a population with its offspring and returns the individuals that survive to produce the next generation.
- Return type:
- Parameters:
- population: Population
Population of individuals that will be selected.
- offspring: Population
Newly generated individuals to be selected.
- Returns:
- selected: Population
List of selected individuals.
- Parameters:
population (Population)
amount (int | None)
- class ParentSelectionFromLambda(selection_fn, name=None, amount=None, rng=None, **kwargs)[source]#
Bases:
ParentSelectionParent selection that wraps a user-supplied function.
The function receives the population, the number of individuals to select, a random state, and any stored keyword arguments, and must return an array of selected indices.
- Parameters:
- selection_fncallable
A function
(population, amount, rng, **kwargs) -> indices.- namestr, optional
Display name (defaults to the function’s
__name__).- amountint, optional
Default number of individuals to select.
- rngRNGLike, optional
Random number generator.
- **kwargs
Keyword arguments forwarded to
ParentSelection.
- Attributes:
paramsAccess parameter values by attribute-style lookup.
- Parameters:
selection_fn (Callable)
name (Optional[str])
amount (Optional[int])
rng (Optional[RNGLike])
Methods
__call__(population[, amount])Shorthand for
select().gather_params()Return the current parameter dictionary (thin wrapper around
get_params()).get_params()Return a copy of the current parameter dictionary.
get_state()Return a dictionary with the selection method's configuration.
select(population[, amount])Takes a population with its offspring and returns the individuals that survive to produce the next generation.
store_kwargs([progress])Store keyword arguments and evaluate them at the given progress.
update(progress)Re-evaluate all stored parameters at the current progress.
update_kwargs([progress])Add or replace parameters and immediately evaluate them.
- select(population, amount=None)[source]#
Takes a population with its offspring and returns the individuals that survive to produce the next generation.
- Return type:
- Parameters:
- population: Population
Population of individuals that will be selected.
- offspring: Population
Newly generated individuals to be selected.
- Returns:
- selected: Population
List of selected individuals.
- Parameters:
population (Population)
amount (int | None)