Class AgeMoea2Sampler
- Namespace
- OptunaSharp.Samplers
- Assembly
- OptunaSharp.dll
Multi-objective sampler using AGE-MOEA-2 (Layer 2 of the AGE-MOEA-2 port). The Optuna-idiomatic face of the algorithm — an ask/tell BaseGASampler that reconstructs the population from completed trials exactly like NSGAIISampler, but replaces NSGA-II's rank + crowding-distance elite selection with AGE-MOEA-2's geometry-based environmental selection (AgeMoea2ElitePopulationSelectionStrategy over OptunaSharp.Samplers.AgeMoea.AgeMoea2Survival). Children are generated with SBX + polynomial mutation over Optuna's transformed search space, so the sampler works across Optuna's full parameter space (float / int / categorical). For conditional (branch-defined) parameters use NSGAIIICptSampler (NSGA-III-CPT); this sampler has no such extension.
AGE-MOEA-2 (Panichella, GECCO 2022, doi:10.1145/3512290.3528732) is absent from Optuna core, so
— like LM-CMA and JANUS — this is a beyond-core sampler. Scope of the parity guarantee:
the byte-perfect, pymoo-faithful AGE-MOEA-2 lives in Layer 1
(OptunaSharp.Samplers.AgeMoea.AgeMoea2Optimizer, generation-by-generation bit-exact vs
pymoo.minimize). This Layer-2 sampler is validated behaviorally: it uses Optuna's
operators (a different RNG stream than pymoo's), so it is not pymoo-bit-exact — it brings
AGE-MOEA-2's survival to Optuna's define-by-run workflow. Unconstrained multi-objective.
public class AgeMoea2Sampler : BaseGASampler
- Inheritance
-
AgeMoea2Sampler
- Derived
- Inherited Members
Constructors
AgeMoea2Sampler(int, BaseMutation?, double?, BaseCrossover?, double, double, int?)
Configures AGE-MOEA-2 survival and the genetic operators used to produce each generation.
public AgeMoea2Sampler(int populationSize = 50, BaseMutation? mutation = null, double? mutationProb = null, BaseCrossover? crossover = null, double crossoverProb = 0.9, double swappingProb = 0.5, int? seed = null)
Parameters
populationSizeintNumber of individuals (trials) per generation. Must be >= 2.
mutationBaseMutationMutation applied when creating children. Null selects PolynomialMutation with
eta = 20, AGE-MOEA-2's default mutation.mutationProbdouble?Per-parameter mutation probability.
null⇒1 / len(params).crossoverBaseCrossoverCrossover applied when creating children. Defaults to SBXCrossover (
eta = 15).crossoverProbdoubleProbability that a crossover occurs.
swappingProbdoubleProbability of swapping each parameter during crossover.
seedint?Seed for the random number generator.
Exceptions
- ValueError
Population size is below two or the crossover parent count, or a configured reproduction probability is invalid.
Methods
AfterTrial(Study, FrozenTrial, TrialState, IReadOnlyList<double>?)
Trial post-processing: called after the objective function returns and right before the trial is finished and its state is stored.
public override void AfterTrial(Study study, FrozenTrial trial, TrialState state, IReadOnlyList<double>? values)
Parameters
studyStudyStudy that owns the trial being finished.
trialFrozenTrialTrial snapshot before its terminal state is written to storage.
stateTrialStateTerminal state being recorded: complete, pruned, or failed.
valuesIReadOnlyList<double>Resulting trial values in objective order; non-null for a successful trial.
Exceptions
- Exception
A configured after-trial or constraint callback fails; its exception propagates.
BeforeTrial(Study, FrozenTrial)
Trial pre-processing: called during trial initialization, just before the InferRelativeSearchSpace(Study, FrozenTrial) call.
public override void BeforeTrial(Study study, FrozenTrial trial)
Parameters
studyStudyStudy that owns the newly initialized trial.
trialFrozenTrialNew trial snapshot available before search-space inference.
InferRelativeSearchSpace(Study, FrozenTrial)
Infer the search space that will be used by relative sampling in the target trial.
This method is called right before SampleRelative(Study, FrozenTrial, OrderedDict<string, BaseDistribution>), and the search space returned by this method is passed to it. The parameters not contained in the search space will be sampled by using SampleIndependent(Study, FrozenTrial, string, BaseDistribution).
public override OrderedDict<string, BaseDistribution> InferRelativeSearchSpace(Study study, FrozenTrial trial)
Parameters
studyStudyStudy supplying trial history, directions, and storage.
trialFrozenTrialCurrent trial snapshot; copy it before modifying its contents.
Returns
- OrderedDict<string, BaseDistribution>
Parameter distributions eligible for joint sampling, in sampler-defined order.
ReseedRng()
Reseed sampler's random number generator.
Parallel optimization calls this hook before a worker's sequential trial loop. Concrete samplers refresh their random streams so workers do not deliberately reuse a seeded sequence. OptunaSharp workers share the study's sampler instance; this hook does not clone it or make concurrent sampling reproducible.
public override void ReseedRng()
SampleIndependent(Study, FrozenTrial, string, BaseDistribution)
Sample a parameter for a given distribution.
This method is called only for the parameters not contained in the search space returned by SampleRelative(Study, FrozenTrial, OrderedDict<string, BaseDistribution>). This method is suitable for sampling algorithms that do not use relationship between parameters such as random sampling and TPE.
public override object? SampleIndependent(Study study, FrozenTrial trial, string paramName, BaseDistribution paramDistribution)
Parameters
studyStudyStudy supplying trial history, directions, and storage.
trialFrozenTrialCurrent trial snapshot; copy it before modifying its contents.
paramNamestringName of the parameter being suggested.
paramDistributionBaseDistributionDistribution defining the parameter's domain and scale.
Returns
- object
A value in the distribution's external representation, including null categorical choices.
SampleRelative(Study, FrozenTrial, OrderedDict<string, BaseDistribution>)
Sample parameters in a given search space.
The trial invokes this method lazily when it first needs relative parameters and caches the result for its remaining suggestions. This method is suitable for sampling algorithms that use relationship between parameters such as Gaussian Process and CMA-ES.
public override OrderedDict<string, object?> SampleRelative(Study study, FrozenTrial trial, OrderedDict<string, BaseDistribution> searchSpace)
Parameters
studyStudyStudy supplying trial history, directions, and storage.
trialFrozenTrialCurrent trial snapshot; copy it before modifying its contents.
searchSpaceOrderedDict<string, BaseDistribution>Distributions returned by InferRelativeSearchSpace(Study, FrozenTrial).
Returns
- OrderedDict<string, object>
Jointly sampled external parameter values; omitted parameters use independent sampling.
SelectParent(Study, int)
Select parent trials from the population for the given generation. Called once per generation; the result is cached in the study system attributes.
public override List<FrozenTrial> SelectParent(Study study, int generation)
Parameters
studyStudyStudy supplying trial history, objective directions, and storage.
generationintZero-based generation whose individuals or optimizer state are requested.
Returns
- List<FrozenTrial>
The selected parent trials for the requested generation.