saealib.CrossoverBLXAlpha#
- class saealib.CrossoverBLXAlpha(prob, alpha)[source]#
Bases:
CrossoverBLX-alpha crossover operator.
- Parameters:
prob (float)
alpha (float)
- prob#
Individual-level crossover probability.
- Type:
float
- alpha#
Alpha parameter for BLX-alpha crossover. Controls how far outside the parents’ range offspring can be generated.
- Type:
float
Notes
Originates from Eshelman & Schaffer (1993); the primary paper has not been obtained and is credited here by name only. The interval
[c_min - alpha*I, c_max + alpha*I]formula implemented incrossover_batch()has been verified against Herrera, Lozano & Verdegay (1998), which restates the BLX-alpha definition while surveying real-coded GA operators.References
[40]: Herrera, F., Lozano, M., & Verdegay, J. L. (1998). Tackling real-coded genetic algorithms: Operators and tools for behavioural analysis. Artificial Intelligence Review, 12, 265-319.
Methods
Initialize BLX-alpha crossover operator. |
|
Return the crossover contract. |
|
Execute crossover for one parent group. |
|
Execute BLX-alpha crossover on a batch of parent pairs at once. |
|
Post-crossover lifecycle hook; override to inject custom processing. |
|
Run the post-crossover lifecycle hook for a batch. |
|
Return a copy of this operator with |
Method Details
- CrossoverBLXAlpha.__init__(prob, alpha)[source]#
Initialize BLX-alpha crossover operator.
- Parameters:
prob (float) – Individual-level crossover probability.
alpha (float) – Alpha parameter for BLX-alpha crossover.
- CrossoverBLXAlpha.contract()#
Return the crossover contract.
- Return type:
- CrossoverBLXAlpha.crossover(parent, bounds=None, rng=Generator(PCG64) at 0x7F79179411C0)#
Execute crossover for one parent group.
This method is derived from
crossover_batch()by passing a single-pair batch.Notes
Overriding only this method (not
crossover_batch()) has no effect under GA’s defaultvariation_execution="batch": the batch path callscrossover_batch()directly and never callscrossover(). Such an override only takes effect undervariation_execution="sequential". To customize behavior under both modes, overridecrossover_batch().- Parameters:
parent (np.ndarray) – Parent individuals. shape = (n_parents, dim)
bounds (tuple of (np.ndarray, np.ndarray) or None) – Lower and upper bounds for each variable.
Nonemeans unbounded.rng (np.random.Generator, optional) – Random number generator, by default np.random.default_rng()
- Returns:
Offspring individuals. shape = (n_offspring, dim)
- Return type:
np.ndarray
- CrossoverBLXAlpha.crossover_batch(parents_batch, bounds=None, rng=Generator(PCG64) at 0x7F7917942DC0)[source]#
Execute BLX-alpha crossover on a batch of parent pairs at once.
This is the primary BLX-alpha implementation.
- Parameters:
parents_batch (np.ndarray) – Batch of parent pairs. shape = (n_pair, 2, dim)
bounds (tuple of (np.ndarray, np.ndarray) or None) – Ignored; BLX-alpha is inherently unbounded.
rng (np.random.Generator, optional) – Random number generator, by default np.random.default_rng()
- Returns:
Offspring individuals. shape = (n_pair, 2, dim)
- Return type:
np.ndarray
Notes
For
n_pair > 1, a loop of separate single-paircrossover_batchcalls (equivalently, separatecrossover()calls) does not reproduce the same per-row results as one batched call with the same seededrng. Drawingrng.uniform(size=(n_pair, dim))for the whole batch has a different draw order from loopingrng.uniform(size=dim).
- CrossoverBLXAlpha.post_crossover(offspring, parents, rng, ctx=None)#
Post-crossover lifecycle hook; override to inject custom processing.
- Parameters:
offspring (np.ndarray) – Offspring produced by crossover. shape = (n_children, dim)
parents (np.ndarray) – Parent individuals. shape = (n_parents, dim)
rng (np.random.Generator) – Random number generator.
ctx (ExecutionContext or None, optional) – Current optimization context.
- Returns:
Processed offspring. shape = (n_children, dim)
- Return type:
np.ndarray
- CrossoverBLXAlpha.post_crossover_batch(offspring_batch, parents_batch, rng, ctx=None)#
Run the post-crossover lifecycle hook for a batch.
The default implementation calls
post_crossover()once per parent group, in order. Override this method to provide genuinely vectorized post-processing.- Parameters:
offspring_batch (np.ndarray) – Offspring produced by crossover. shape = (n_pair, n_children, dim)
parents_batch (np.ndarray) – Batch of parent groups. shape = (n_pair, n_parents, dim)
rng (np.random.Generator) – Random number generator.
ctx (ExecutionContext or None, optional) – Current optimization context.
- Returns:
Processed offspring. shape = (n_pair, n_children, dim)
- Return type:
np.ndarray
Notes
with_post()reassigns only the instance’spost_crossover()hook. A subclass override of this method is responsible for composing that hook itself. If the override does not callself.post_crossover, a hook installed withwith_post()will not run in GA batch mode. It still runs in GA sequential mode, which callspost_crossover()directly.