Class RveaSampler
- Namespace
- OptunaSharp.Samplers
- Assembly
- OptunaSharp.dll
Multi-objective sampler using the RVEA algorithm (Cheng et al., 2016): a reference-vector-guided evolutionary algorithm for many-objective optimization. It reuses the whole NSGA-II genetic machinery (BaseGASampler, child generation, crossovers, mutations) and swaps the elite-selection strategy for angle-penalized-distance (APD) survival (OptunaSharp.Samplers.Rvea.RveaApdSurvival): each individual is associated with its nearest reference vector, and within every reference vector the survivor is the one whose distance to the ideal point is least after a generation-growing angle penalty — an explicit diversity→convergence shift that suits three-and-more-objective fronts. The reference vectors are periodically re-scaled to the current objective ranges.
Beyond-core. RVEA has no Optuna / OptunaHub counterpart; like SmsEmoaSampler it is validated by convergence and achieved hypervolume, not bit-matched to an upstream. The default operators are RVEA's classic SBXCrossover (η=30) + PolynomialMutation (η=20); mating uses the shared NSGA-II child generation, so only the survival differs from the NSGA-II family.
Generation horizon. The APD penalty grows with (generation / nMaxGenerations)^α
and the reference vectors adapt every ceil(nMaxGenerations · adaptFreq) generations. Optuna is
trial-budget-driven and does not expose a maximum generation to the sampler, so nMaxGenerations
sets that schedule's horizon explicitly (the ratio is clamped to 1 beyond it).
Reference-vector count. The structured Das-Dennis lattice has a fixed size for each
(objectives, partitions) pair, so — unless explicit reference points are supplied — the effective
population size is set to the largest lattice size not exceeding the requested
populationSize.
public class RveaSampler : BaseGASampler
- Inheritance
-
RveaSampler
- Inherited Members
Examples
var study = Optuna.CreateStudy(
directions: new[] { StudyDirection.Minimize, StudyDirection.Minimize, StudyDirection.Minimize },
sampler: new RveaSampler(populationSize: 91, seed: 0));
study.Optimize(t =>
{
double x = t.SuggestFloat("x", 0, 1), y = t.SuggestFloat("y", 0, 1), z = t.SuggestFloat("z", 0, 1);
return new[] { x, y, z };
}, nTrials: 900);
Constructors
RveaSampler(int, BaseMutation?, double?, BaseCrossover?, double, double, int?, double, double, int, double[,]?, int?, Func<Study, OrderedDict<string, BaseDistribution>, List<FrozenTrial>, OrderedDict<string, object?>>?, Action<Study, FrozenTrial, TrialState, IReadOnlyList<double>?>?)
Configures reference-vector survival, progress-dependent angular penalties, and reproduction.
public RveaSampler(int populationSize = 50, BaseMutation? mutation = null, double? mutationProb = null, BaseCrossover? crossover = null, double crossoverProb = 0.9, double swappingProb = 0.5, int? seed = null, double alpha = 2, double adaptFreq = 0.1, int nMaxGenerations = 100, double[,]? referencePoints = null, int? dividingParameter = null, Func<Study, OrderedDict<string, BaseDistribution>, List<FrozenTrial>, OrderedDict<string, object?>>? childGenerationStrategy = null, Action<Study, FrozenTrial, TrialState, IReadOnlyList<double>?>? afterTrialStrategy = null)
Parameters
populationSizeintTarget number of reference vectors / generation size. When reference points are generated (the default), the effective count is the largest Das-Dennis lattice size not exceeding this (see the class remarks).
mutationBaseMutationMutation applied when creating child individuals; defaults to PolynomialMutation (η=20).
mutationProbdouble?Probability of mutating each parameter. If
null,1 / len(parent.params)is used.crossoverBaseCrossoverCrossover applied when creating child individuals; defaults to SBXCrossover (η=30, RVEA's classic operator).
crossoverProbdoubleProbability that a crossover occurs when creating a new individual.
swappingProbdoubleProbability of swapping each parameter of the parents during crossover.
seedint?Seed for random number generator.
alphadoubleThe APD penalty exponent α (default 2.0).
adaptFreqdoubleFraction of
nMaxGenerationsat which the reference vectors are re-scaled to the current objective ranges (default 0.1; 0 disables adaptation).nMaxGenerationsintGeneration horizon for the APD penalty schedule and the adaptation period (default 100).
referencePointsdouble[,]Explicit reference vectors (a 2-D array with
n_objectivescolumns). Whennull(default), Das-Dennis reference vectors are generated.dividingParameterint?Number of Das-Dennis divisions when generating the default reference vectors. When
null(default), it is chosen so the lattice size is closest to (≤)populationSize.childGenerationStrategyFunc<Study, OrderedDict<string, BaseDistribution>, List<FrozenTrial>, OrderedDict<string, object>>Experimental. Overrides child generation.
afterTrialStrategyAction<Study, FrozenTrial, TrialState, IReadOnlyList<double>>Experimental. Overrides the after-trial procedure.
Exceptions
- ValueError
Population size is too small, alpha is negative, adaptation frequency is outside [0, 1], or the maximum generation count is below one.
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.