Table of Contents

Class IntDistribution

Namespace
OptunaSharp.Distributions
Assembly
OptunaSharp.dll

A distribution on integers. Port of optuna/distributions.py: IntDistribution.

This object is instantiated by SuggestInt(string, long, long, long, bool), and passed to samplers in general.

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

Remarks

When step is not 1, if the range [low, high] is not divisible by step, high will be replaced with the maximum of k * step + low < high, where k is an integer.

Constructors

IntDistribution(long, long, bool, long)

Creates a numeric distribution and normalizes a stepped upper endpoint.

public IntDistribution(long low, long high, bool log = false, long step = 1)

Parameters

low long

Inclusive lower endpoint of the parameter range.

high long

Inclusive upper endpoint; a stepped range may lower it to the last reachable grid point.

log bool

Whether to sample in the logarithmic domain, which requires a strictly positive lower endpoint.

step long

Positive integer grid spacing; logarithmic ranges require one.

Exceptions

ValueError

The lower endpoint exceeds the upper endpoint, logarithmic bounds are nonpositive, or the step is invalid for the selected scale.

Properties

High

Upper endpoint of the range of the distribution. High is included in the range.

public long High { get; }

Property Value

long

Log

If true, this distribution is in log-scaled domain.

public bool Log { get; }

Property Value

bool

Low

Lower endpoint of the range of the distribution. Low is included in the range.

public long Low { get; }

Property Value

long

Step

A discretization step. Must be a positive integer (1 when log is true).

public long Step { get; }

Property Value

long

Methods

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 a boxed long (Python int).

public override object? ToExternalRepr(double paramValueInInternalRepr)

Parameters

paramValueInInternalRepr double

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

Returns

object

The internal value cast to a boxed 64-bit integer.

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

The converted numeric value; range membership is checked separately by Contains.

Exceptions

ValueError

The value cannot be converted to a number, is NaN, or is nonpositive for a logarithmic distribution.