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
lowlongInclusive lower endpoint of the parameter range.
highlongInclusive upper endpoint; a stepped range may lower it to the last reachable grid point.
logboolWhether to sample in the logarithmic domain, which requires a strictly positive lower endpoint.
steplongPositive 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
Log
If true, this distribution is in log-scaled domain.
public bool Log { get; }
Property Value
Low
Lower endpoint of the range of the distribution. Low is included in the range.
public long Low { get; }
Property Value
Step
A discretization step. Must be a positive integer (1 when log is true).
public long Step { get; }
Property Value
Methods
Equals(BaseDistribution?)
Compares distribution types and their defining attributes.
public override bool Equals(BaseDistribution? other)
Parameters
otherBaseDistributionValue 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
paramValueInInternalReprdoubleNumeric 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
paramValueInExternalReprobjectExternal 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.