Class EvolutionStrategySampler
- Namespace
- OptunaSharp.Samplers.EvolutionStrategy
- Assembly
- OptunaSharp.dll
Base class for the Evolution-Strategy samplers. Drives an OptunaSharp.Samplers.EvolutionStrategy.IEvolutionStrategyOptimizer
through the Optuna study protocol the way CmaEsSampler drives Cma: continuous
Float/Int parameters form a relative search space; the population is spread across consecutive
trials; and the optimizer state round-trips through trial system attrs (own JSON, chunked to the
storage string-length limit) so a study resumes across process boundaries and distributed workers.
Categorical parameters, single-valued distributions, and the first nStartupTrials trials
are handled by the independent sampler, exactly as in CmaEsSampler. Dynamic search spaces are
unsupported (the sampler falls back to independent sampling with a warning).
public abstract class EvolutionStrategySampler : BaseSampler
- Inheritance
-
EvolutionStrategySampler
- Derived
- Inherited Members
Constructors
EvolutionStrategySampler(int, BaseSampler?, bool, int?)
Initializes the shared startup, RNG, and search-space state for an ES sampler.
protected EvolutionStrategySampler(int nStartupTrials, BaseSampler? independentSampler, bool warnIndependentSampling, int? seed)
Parameters
nStartupTrialsintIndependent sampling is used until this many trials complete; the ES optimizer starts from its box-center mean once the threshold is reached.
independentSamplerBaseSamplerSampler for parameters outside the relative search space (default RandomSampler).
warnIndependentSamplingboolEmit a warning when a parameter is sampled independently.
seedint?Random seed selecting the optimizer's base noise seed (persisted per study).
Properties
AttrPrefix
The system-attr key prefix distinguishing this sampler's stored state (e.g. "openaies:").
protected abstract string AttrPrefix { get; }
Property Value
SamplerLogger
The logger namespace for this sampler (e.g. "optuna.samplers.openai_es").
protected abstract Logger SamplerLogger { get; }
Property Value
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.
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.
Exceptions
- ValueError
The study has multiple objectives, but this sampler requires a scalar objective.
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.
Exceptions
- ValueError
The study has multiple objectives, but this sampler requires a scalar objective.