propulate.propagators.base
Module Contents
Classes
Initialize a propagator with given parameters. |
|
Initialize a stochastic propagator that is only applied with a specified probability. |
|
Initialize a conditional propagator. |
|
Initialize a composed propagator. |
|
Initialize an elitist selection propagator. |
|
Initialize an anti-elitist propagator. |
|
Initialize a random-selection propagator. |
|
Initialize a random-initialization propagator. |
|
Initialize Gaussian propagator. |
Functions
|
Check compatibility of two propagators for stacking them together sequentially with |
- propulate.propagators.base._check_compatible(out1: int, in2: int) bool
Check compatibility of two propagators for stacking them together sequentially with
Compose.- Parameters:
out1 (int) – The number of output individuals returned by the first propagator.
in2 (int) – The number of input individuals taken by the second propagator.
- Returns:
True if the input propagators can be stacked: False if not.
- Return type:
bool
- class propulate.propagators.base.Propagator(parents: int = 0, offspring: int = 0, rng: random.Random | None = None)
Initialize a propagator with given parameters.
- Parameters:
parents (int, optional) – The number of input individuals (-1 for any). Default is 0 for abstract base class.
offspring (int, optional) – The number of output individuals to breed. Default is 0 for abstract base class.
rng (random.Random, optional) – The separate random number generator for the Propulate optimization.
- Raises:
ValueError – If the number of offspring to breed is zero.
- abstract __call__(inds: List[propulate.population.Individual]) List[propulate.population.Individual] | propulate.population.Individual
Apply the propagator (not implemented for abstract base class).
- Parameters:
inds (List[propulate.population.Individual]) – The input individuals the propagator is applied to.
- Returns:
The individual(s) bred by applying the propagator. While this abstract base class method actually returns
None, each concrete child class ofPropagatorshould return anIndividualinstance or a list of them.- Return type:
List[propulate.population.Individual] | propulate.population.Individual
- Raises:
NotImplementedError – Whenever called (abstract base class method).
- class propulate.propagators.base.Stochastic(parents: int = 0, offspring: int = 0, probability: float = 1.0, rng: random.Random | None = random.Random())
Bases:
PropagatorInitialize a stochastic propagator that is only applied with a specified probability.
- Parameters:
parents (int, optional) – The number of input individuals (-1 for any). Default is 0.
offspring (int, optional) – The number of output individuals. Default is 0.
probability (float, optional) – The probability of application. Default is 0.0.
rng (random.Random, optional) – The separate random number generator for the Propulate optimization.
- Raises:
ValueError – If the number of offspring to breed is zero.
- class propulate.propagators.base.Conditional(pop_size: int, true_prop: Propagator, false_prop: Propagator, parents: int = -1, offspring: int = -1)
Bases:
PropagatorInitialize a conditional propagator.
- Parameters:
pop_size (int) – The breeding population size.
true_prop (propulate.propagators.Propagator) – The propagator applied if the current population’s size equals at least
pop_size.false_prop (propulate.propagators.Propagator) – The propagator applied if the current population’s size is less than
pop_size.parents (int, optional) – The number of input individuals (-1 for any). Default is -1.
offspring (int) – The number of output individuals to breed. Default is -1.
- __call__(inds: List[propulate.population.Individual]) List[propulate.population.Individual] | propulate.population.Individual
Apply conditional propagator.
- Parameters:
inds (List[propulate.population.Individual]) – The input individuals the propagator is applied to.
- Returns:
The output individuals returned by the conditional propagator.
- Return type:
- class propulate.propagators.base.Compose(propagators: List[Propagator])
Bases:
PropagatorInitialize a composed propagator.
- Parameters:
propagators (List[propulate.propagators.Propagator]) – The propagators to be stacked together sequentially.
- Raises:
ValueError – If the propagators to stack are incompatible in terms of number of input and output individuals.
- __call__(inds: List[propulate.population.Individual]) List[propulate.population.Individual] | propulate.population.Individual
Apply the composed propagator.
- Parameters:
inds (List[propulate.population.Individual]) – The input individuals the propagator is applied to.
- Returns:
The output individuals after application of the propagator.
- Return type:
- class propulate.propagators.base.SelectMin(offspring: int)
Bases:
PropagatorInitialize an elitist selection propagator.
- Parameters:
offspring (int) – The number of offspring (individuals to be selected).
- __call__(inds: List[propulate.population.Individual]) List[propulate.population.Individual]
Apply the elitist-selection propagator.
- Parameters:
inds (List[propulate.population.Individual]) – The input individuals the propagator is applied to.
- Returns:
The selected output individuals after application of the propagator.
- Return type:
- Raises:
ValueError – If more individuals than put in shall be selected.
- class propulate.propagators.base.SelectMax(offspring: int)
Bases:
PropagatorInitialize an anti-elitist propagator.
- Parameters:
offspring (int) – The number of offspring (individuals to be selected).
- __call__(inds: List[propulate.population.Individual]) List[propulate.population.Individual]
Apply the anti-elitist-selection propagator.
- Parameters:
inds (List[propulate.population.Individual]) – The individuals the propagator is applied to.
- Returns:
The selected individuals after application of the propagator.
- Return type:
- Raises:
ValueError – If more individuals than put in shall be selected.
- class propulate.propagators.base.SelectUniform(offspring: int, rng: random.Random | None = None)
Bases:
PropagatorInitialize a random-selection propagator.
- Parameters:
offspring (int) – The number of offspring (individuals to be selected).
rng (random.Random, optional) – The separate random number generator for the Propulate optimization.
- __call__(inds: List[propulate.population.Individual]) List[propulate.population.Individual]
Apply the uniform-selection propagator.
- Parameters:
inds (List[propulate.population.Individual]) – The individuals the propagator is applied to.
- Returns:
The selected individuals after application of the propagator.
- Return type:
- Raises:
ValueError – If more individuals than put in shall be selected.
- class propulate.propagators.base.InitUniform(limits: Mapping[str, Tuple[float, float] | Tuple[int, int] | Tuple[str, Ellipsis]], parents: int = 0, probability: float = 1.0, rng: random.Random | None = random.Random())
Bases:
StochasticInitialize a random-initialization propagator.
- Parameters:
limits (Dict[str, Tuple[float, float]] | Dict[str, Tuple[int, int]] | Dict[str, Tuple[str, ...]]) – The search space, i.e., the limits of (hyper-)parameters to be optimized.
parents (int, optional) – The number of parents. Default is 0.
probability (float, optional) – The probability of application. Default is 1.0.
rng (random.Random, optional) – The separate random number generator for the Propulate optimization.
- __call__(*inds: propulate.population.Individual) propulate.population.Individual
Apply the uniform-initialization propagator.
- Parameters:
inds (propulate.population.Individual) – The individuals the propagator is applied to.
- Returns:
The output individual after application of the propagator.
- Return type:
- Raises:
ValueError – If a parameter’s type is invalid, i.e., not float (continuous), int (ordinal), or str (categorical).
- class propulate.propagators.base.Gaussian(limits: Dict[str, Tuple[float, float]], scale: float, rng: numpy.random.Generator)
Bases:
PropagatorInitialize Gaussian propagator.
- Parameters:
limits (Dict[str, Tuple[float, float]] | Dict[str, Tuple[int, int]] | Dict[str, Tuple[str, ...]]) – The search space, i.e., limits of (hyper-)parameters to be optimized.
scale (float) – The standard deviation of the Gaussian distribution.
rng (random.Random) – The separate random number generator for the Propulate optimization.
- __call__(inds: List[propulate.population.Individual]) propulate.population.Individual
Apply the Gaussian propagator.
- Parameters:
inds (propulate.population.Individual) – The individuals the propagator is applied to.
- Returns:
The output individual after application of the propagator.
- Return type: