Table of Contents

Class JanusDeSampler

Namespace
OptunaSharp.Samplers
Assembly
OptunaSharp.dll

JANUS-DE: the training-free JANUS Jacobian infill on a Differential Evolution host. JANUS estimates a local Jacobian from the recent evaluation trace and bounded-injects a damped Gauss–Newton exploitation elite into each DE generation, while the DifferentialEvolutionSampler-style DE host keeps full control of selection. Because DE has no Gaussian proposal covariance, this is the paper's JANUS-GN configuration — the exploitation injection only, no CMIX exploration candidates. It is the host-agnostic complement to the CMA-hosted JanusSampler.

Residual coordinates (optional but recommended). If the objective decomposes into components f(x) = mean_i r_i(x), expose the residual vector on each trial via trial.SetUserAttr("component_losses", new double[]{ r1, r2, … }); JANUS then estimates the local Jacobian directly from those residuals. Without it, JANUS falls back to a local linear/quadratic fit on the recent window of scalar objective values (the constructor's pseudoMode option).

Beyond-core, in-memory state. Like JanusSampler, JANUS-DE holds its optimizer (JANUS window + DE population) in memory for the study's duration; it does not resume its infill state across process boundaries. Categorical and single-value distributions are handled by the independent sampler.

public sealed class JanusDeSampler : BaseSampler
Inheritance
JanusDeSampler
Inherited Members

Examples

var study = Optuna.CreateStudy(sampler: new JanusDeSampler(seed: 0, nStartupTrials: 16));
study.Optimize(t =>
{
    double s = 0;
    for (int i = 0; i < 10; i++) { double x = t.SuggestFloat($"x{i}", -5, 5); double r = (x - 0.5) * (x - 0.5); s += r; }
    return s;
}, nTrials: 400);

Constructors

JanusDeSampler(int?, int?, int, BaseSampler?, bool, int, double, double, string, int, int?, double, int?, double, double, string, string?, string, string)

Configures Jacobian-informed candidates injected into a differential-evolution population.

public JanusDeSampler(int? seed = null, int? popsize = null, int nStartupTrials = 1, BaseSampler? independentSampler = null, bool warnIndependentSampling = true, int nJobs = 1, double f = 0.8, double cr = 0.9, string strategy = "rand1bin", int fuseEvery = 4, int? fuseStart = null, double kappa = 1, int? gnWindow = null, double gnLambda = 1, double gnRidge = 1, string pseudoMode = "linear", string? gnPseudoMode = null, string pseudoTarget = "raw", string pcaK = "auto")

Parameters

seed int?

Random seed. When null, a random seed is drawn (from MT19937, never System.Random).

popsize int?

DE population size NP (default max(8, 4 + ⌊3 ln d⌋)).

nStartupTrials int

Independent sampling is used until this many trials finish.

independentSampler BaseSampler

Sampler for parameters outside the relative space (default RandomSampler).

warnIndependentSampling bool

Warn when a parameter is sampled independently.

nJobs int

Number of parallel workers; a separate optimizer is kept per trial.Number % nJobs.

f double

DE differential weight F (default 0.8).

cr double

DE crossover rate CR (default 0.9).

strategy string

DE mutation strategy: rand1bin (default) or best1bin.

fuseEvery int

Generations between Jacobian re-estimation (assembly cadence).

fuseStart int?

Window size before the first Jacobian assembly (null = auto).

kappa double

Bounded-injection clip factor (whitened step ‖z‖ ≤ κ√d, in DE's per-dimension spread metric).

gnWindow int?

Sliding window of recent (x, f) pairs for the Jacobian regression (null = auto).

gnLambda double

Levenberg–Marquardt damping for the Gauss–Newton step.

gnRidge double

Ridge regularization for the residual-gradient regression.

pseudoMode string

Scalar residual-coordinate fit: linear (default), quadratic, diag_quadratic, pca_quadratic, diag_pca_quadratic, or none.

gnPseudoMode string

Override pseudoMode for the GN direction (null = same).

pseudoTarget string

Scalar-value transform for the fit: raw (default), rank, or log.

pcaK string

PCA rank for the pca_quadratic fit (auto or an integer string).

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

study Study

Study that owns the trial being finished.

trial FrozenTrial

Trial snapshot before its terminal state is written to storage.

state TrialState

Terminal state being recorded: complete, pruned, or failed.

values IReadOnlyList<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

study Study

Study that owns the newly initialized trial.

trial FrozenTrial

New 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

study Study

Study supplying trial history, directions, and storage.

trial FrozenTrial

Current 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

study Study

Study supplying trial history, directions, and storage.

trial FrozenTrial

Current trial snapshot; copy it before modifying its contents.

paramName string

Name of the parameter being suggested.

paramDistribution BaseDistribution

Distribution 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

study Study

Study supplying trial history, directions, and storage.

trial FrozenTrial

Current trial snapshot; copy it before modifying its contents.

searchSpace OrderedDict<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.