saealib.PymooMutation#
- class saealib.PymooMutation(operator, *, prob=1.0)[ソース]#
ベースクラス:
MutationAdapter wrapping a pymoo mutation operator as a saealib
Mutation.Lets researchers who already have a pymoo
Mutation(e.g.PM()) reuse it unchanged inside saealib'sGA.- パラメータ:
operator (pymoo.core.mutation.Mutation) -- An already-constructed pymoo mutation operator instance.
prob (float, optional) -- Individual-level mutation probability. Unlike
PymooCrossover, this class applies the gate itself insidemutate_batch(). Defaults to 1.0.
メモ
prob_var(pymoo's per-variable mutation probability) is deliberately not mirrored from the wrapped operator: pymoo stores it as apymoo.core.variable.RealorNone, and the wrapped operator's_do()resolves its own per-variable rate internally regardless of what saealib'sprob_varattribute says.self.prob_varstaysNonehere so that any saealib code reading it (e.g. mixed-variable routing inGA) falls back to its own default rather than seeing a foreign, potentially non-floatvalue.mutate_batch()calls the wrapped operator's_do()at most once, on the gated subset, and forwardsrngvia pymoo'srandom_stateparameter for reproducibility. The inheritedmutate()derives a single-row call from that batch implementation. A minimal cached pymooProblemshim is synthesized the same way.
Methods
Return the mutation contract; mutate_range is required for every mutation. |
|
Execute mutation for one candidate. |
|
Execute mutation on a batch of candidates via a single pymoo call. |
|
Post-mutation lifecycle hook; override to inject custom processing. |
|
Run the post-mutation lifecycle hook for a batch. |
|
Return a copy of this operator with |
Method Details
- PymooMutation.__init__(operator, *, prob=1.0)[ソース]#
- パラメータ:
operator (_PymooMutationLike)
prob (float)
- 戻り値の型:
None
- PymooMutation.contract()#
Return the mutation contract; mutate_range is required for every mutation.
- 戻り値の型:
- PymooMutation.mutate(p, mutate_range, rng=Generator(PCG64) at 0x7FE0F47AA6C0)#
Execute mutation for one candidate.
This method is derived from
mutate_batch()by passing a single-row batch.メモ
Overriding only this method (not
mutate_batch()) has no effect under GA's defaultvariation_execution="batch": the batch path callsmutate_batch()directly and never callsmutate(). Such an override only takes effect undervariation_execution="sequential". To customize behavior under both modes, overridemutate_batch().- パラメータ:
p (np.ndarray) -- Parent individual. shape = (dim,)
mutate_range (tuple) -- Tuple of (lower_bound, upper_bound) for mutation.
rng (np.random.Generator, optional) -- Random number generator, by default np.random.default_rng()
- 戻り値:
Mutated individual. shape = (dim,). The result is always
float64becausemutate_batch()casts its input internally; the result does not preserve the input's dtype.- 戻り値の型:
np.ndarray
- PymooMutation.mutate_batch(candidates_batch, mutate_range, rng=Generator(PCG64) at 0x7FE0F45F8660)[ソース]#
Execute mutation on a batch of candidates via a single pymoo call.
Unlike
Crossover.crossover_batch, this method owns its ownprobgate: it draws one gate value per row (rng.random(n) < self.prob, mirroringmutate()'s per-callrng.random() >= self.probcheck) and only mutates the gated rows; ungated rows are returned unchanged. The wrapped operator's_do()is called at most once, on only the gated subset. If no row is gated (gate.sum() == 0),_do()is not called at all, avoiding a zero-length-batch call into the wrapped pymoo operator.- パラメータ:
candidates_batch (np.ndarray) -- Batch of candidate individuals. shape = (n, dim)
mutate_range (tuple) -- Tuple of (lower_bound, upper_bound) for mutation.
rng (np.random.Generator, optional) -- Forwarded to the wrapped operator as
random_state.
- 戻り値:
Mutated individuals. shape = (n, dim)
- 戻り値の型:
np.ndarray
メモ
For more than one gated row, a loop of separate single-row
mutate_batchcalls (equivalently, separatemutate()calls) does not reproduce the same per-row results as one batched call with the same seededrng. Pymoo operators such as PM draw each random phase across the whole gated batch, whereas single-row calls interleave phases per row.
- PymooMutation.post_mutation(offspring, mutate_range, rng, ctx=None)#
Post-mutation lifecycle hook; override to inject custom processing.
- パラメータ:
offspring (np.ndarray) -- Individual after mutation. shape = (dim,)
mutate_range (tuple) -- Tuple of (lower_bound, upper_bound) used for mutation.
rng (np.random.Generator) -- Random number generator.
ctx (ExecutionContext or None, optional) -- Current optimization context.
- 戻り値:
Processed individual. shape = (dim,)
- 戻り値の型:
np.ndarray
- PymooMutation.post_mutation_batch(offspring_batch, mutate_range, rng, ctx=None)#
Run the post-mutation lifecycle hook for a batch.
The default implementation calls
post_mutation()once per individual, in order. Override this method to provide genuinely vectorized post-processing.- パラメータ:
offspring_batch (np.ndarray) -- Offspring produced by mutation. shape = (n, dim)
mutate_range (tuple) -- Tuple of (lower_bound, upper_bound) used for mutation.
rng (np.random.Generator) -- Random number generator.
ctx (ExecutionContext or None, optional) -- Current optimization context.
- 戻り値:
Processed offspring. shape = (n, dim)
- 戻り値の型:
np.ndarray
メモ
with_post()reassigns only the instance'spost_mutation()hook. A subclass override of this method is responsible for composing that hook itself. If the override does not callself.post_mutation, a hook installed withwith_post()will not run in GA batch mode. It still runs in GA sequential mode, which callspost_mutation()directly.