Table of Contents

Class CategoricalDistribution

Namespace
OptunaSharp.Distributions
Assembly
OptunaSharp.dll

A categorical distribution. Port of optuna/distributions.py: CategoricalDistribution.

This object is instantiated by SuggestCategorical(string, IEnumerable<CategoricalChoice>), and passed to samplers in general.

public class CategoricalDistribution : BaseDistribution, IEquatable<BaseDistribution>
Inheritance
CategoricalDistribution
Implements
Inherited Members

Constructors

CategoricalDistribution(params CategoricalChoice[])

Copies a nonempty candidate sequence into a categorical distribution.

public CategoricalDistribution(params CategoricalChoice[] choices)

Parameters

choices CategoricalChoice[]

Nonempty sequence of categorical candidates; order is retained and determines stored indices.

Exceptions

ValueError

No choices are supplied.

ArgumentNullException

The choices sequence is null.

CategoricalDistribution(IEnumerable<CategoricalChoice>)

Copies a nonempty candidate sequence into a categorical distribution.

public CategoricalDistribution(IEnumerable<CategoricalChoice> choices)

Parameters

choices IEnumerable<CategoricalChoice>

Nonempty sequence of categorical candidates; order is retained and determines stored indices.

Exceptions

ValueError

No choices are supplied.

ArgumentNullException

The choices sequence is null.

Properties

Choices

Parameter value candidates (Python: an immutable tuple).

public IReadOnlyList<CategoricalChoice> Choices { get; }

Property Value

IReadOnlyList<CategoricalChoice>

Methods

ChoiceAt(double)

The choice at the internal-repr index, typed.

public CategoricalChoice ChoiceAt(double paramValueInInternalRepr)

Parameters

paramValueInInternalRepr double

Numeric internal representation: a numeric value or a zero-based categorical index.

Returns

CategoricalChoice

The categorical choice at the truncated internal index.

Exceptions

ArgumentOutOfRangeException

The converted index lies outside the choices array.

Equals(BaseDistribution?)

Compares distribution types and their defining attributes.

public override bool Equals(BaseDistribution? other)

Parameters

other BaseDistribution

Value to compare with this instance; null compares unequal.

Returns

bool

True when the distributions have compatible types and equal attributes.

GetHashCode()

Computes a hash from the distribution type and defining attributes.

public override int GetHashCode()

Returns

int

Hash code consistent with distribution equality.

Single()

Tests whether this distribution admits only one candidate.

public override bool Single()

Returns

bool

True when sampling can be replaced by the sole allowed value.

ToExternalRepr(double)

External representation is the choice at the internal-repr index.

public override object? ToExternalRepr(double paramValueInInternalRepr)

Parameters

paramValueInInternalRepr double

Numeric internal representation: a numeric value or a zero-based categorical index.

Returns

object

The underlying value of the categorical choice at the converted index.

Exceptions

ArgumentOutOfRangeException

The converted index lies outside the choices array.

ToInternalRepr(object?)

Converts an external value into the numeric representation used by samplers.

public override double ToInternalRepr(object? paramValueInExternalRepr)

Parameters

paramValueInExternalRepr object

External parameter value to convert to the distribution's numeric representation.

Returns

double

Index of the first matching choice, treating two NaNs as matching in the fallback comparison.

Exceptions

ValueError

The external value does not match any candidate under categorical choice equality.

TypeError

The external value is not a supported categorical scalar.