saealib.MutationGaussian#
- class saealib.MutationGaussian(prob=1.0, *, sigma, prob_var=None)[ソース]#
ベースクラス:
MutationGaussian mutation operator.
- パラメータ:
prob (float)
sigma (float)
prob_var (float | None)
- prob#
Individual-level mutation probability.
- Type:
float
- sigma#
Standard deviation of the Gaussian perturbation.
- Type:
float
- prob_var#
Per-variable mutation probability. Defaults to
min(0.5, 1/dim)whenNone.- Type:
float or None
メモ
Originates from Rechenberg (1973); the original (German-language) monograph has not been obtained and is credited here by name only. The survey below summarizes Rechenberg's (1+1)-ES with Gaussian mutation and its mutation-strength (standard deviation) parameterization, consistent with this operator.
参照
[41]: Beyer, H.-G., & Schwefel, H.-P. (2002). Evolution strategies -- A comprehensive introduction. Natural Computing, 1, 3-52.
Methods
Initialize Gaussian mutation operator. |
|
Return the real-valued Gaussian mutation contract. |
|
Execute mutation for one candidate. |
|
Execute Gaussian mutation on a batch of candidates at once. |
|
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
- MutationGaussian.__init__(prob=1.0, *, sigma, prob_var=None)[ソース]#
Initialize Gaussian mutation operator.
- パラメータ:
prob (float, optional) -- Individual-level mutation probability, by default 1.0.
sigma (float) -- Standard deviation of the Gaussian perturbation.
prob_var (float or None, optional) -- Per-variable mutation probability.
Noneusesmin(0.5, 1/dim).
- MutationGaussian.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
- MutationGaussian.mutate_batch(candidates_batch, mutate_range, rng=Generator(PCG64) at 0x7FE0F47AB300)[ソース]#
Execute Gaussian mutation on a batch of candidates at once.
This is the primary Gaussian mutation implementation. An individual-level
probgate (one Bernoulli draw per row viarng.random(n) < self.prob) selects which rows are touched at all; a per-dimensionprob_vargate is then drawn only for the selected rows, and only dimensions passing that gate are replaced by addingNormal(0.0, self.sigma)noise. Unlikemutate_batch()andmutate_batch(), the replacement value has no branching formula -- it is simplysub + noise-- so this is the simplest of the threemutate_batchoverrides. Rows that fail the individual-level gate are returned byte-identical to the input; dimensions failing the per-dimension gate on a selected row keep their original value exactly (np.wherecopies rather than recomputes them). If no row passes the individual-level gate (gate.sum() == 0), no further random draws happen at all and the input is returned unchanged, mirroringMutationUniform.mutate_batch's empty-gate skip.- パラメータ:
candidates_batch (np.ndarray) -- Batch of candidate individuals. shape = (n, dim)
mutate_range (tuple) -- Tuple of (lower_bound, upper_bound). Accepted for interface uniformity with the
MutationABC and the othermutate_batchoverrides, but unused. This operator adds unbounded Gaussian noise with no clipping to[lb, ub].rng (np.random.Generator, optional) -- Random number generator, by default np.random.default_rng()
- 戻り値:
Mutated individuals. shape = (n, dim)
- 戻り値の型:
np.ndarray
メモ
For multiple rows, 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. Separate calls interleave each row's individual gate, full per-dimension gate array, and full noise array before moving to the next row. One batched call instead draws all individual gates, then the variable-gate arrays for all gated rows, then the noise arrays for all of them. These phases therefore have a different draw order whenever more than one row is involved. Only the statistical and distributional semantics are guaranteed to match.The output is always
float64(via the internaldtype=floatcast), regardless of the input array's dtype.
- MutationGaussian.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
- MutationGaussian.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.