Class FloatDistribution
- Namespace
- OptunaSharp.Distributions
- Assembly
- OptunaSharp.dll
A distribution on floats. Port of optuna/distributions.py: FloatDistribution.
This object is instantiated by SuggestFloat(string, double, double, double?, bool), and passed to samplers in general.
public class FloatDistribution : BaseDistribution, IEquatable<BaseDistribution>
- Inheritance
-
FloatDistribution
- Implements
- Derived
- Inherited Members
Remarks
When step is not null, 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.
Tiny magnitudes round differently from Optuna (a kept difference). Optuna does this arithmetic with
Python's Decimal (28 significant digits, unbounded exponent); OptunaSharp uses .NET
decimal, which keeps 28 digits after the point and reads anything below 1e-28 as zero.
The owner chose on 2026-11-12 to keep it (QA-3 / QA-62 of the parity QA journals). Ordinary ranges are
unaffected; three kinds of input differ:
- a bound or step whose shortest repr needs more than 28 decimal places (a 17-digit value below about
1e-11) can leavehighone ULP from Optuna's, and BruteForce's grid one point longer (FloatDistribution(4.1271208719049127e-14, 4.085121318968367e-13, step: 1e-15):4.082712087190491e-13, Optuna4.0827120871904913e-13); - a bound below
1e-28counts as zero, so(5e-324, 0.30000000000000004, step: 1.0)ends at0.0, below itslow(Optuna:5e-324); - a range whose step count needs more than 28 digits (
(0, 1e20, step: 1e-09)) is accepted, where Optuna raisesdecimal.InvalidOperation; a NaN or infinite bound or step throws FormatException, where Optuna giveshigh=nanorInvalidOperation.
Constructors
FloatDistribution(double, double, bool, double?)
Creates a numeric distribution and normalizes a stepped upper endpoint.
public FloatDistribution(double low, double high, bool log = false, double? step = null)
Parameters
lowdoubleInclusive lower endpoint of the parameter range.
highdoubleInclusive 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.
stepdouble?Positive float grid spacing, or null for a continuous range; logarithmic ranges require null.
Exceptions
- ValueError
The lower endpoint exceeds the upper endpoint, logarithmic bounds are nonpositive, or the step is invalid for the selected scale.
- FormatException
A stepped bound or step is NaN or infinite and cannot be parsed as a decimal.
- DivideByZeroException
A positive step rounds to zero in decimal arithmetic while aligning the upper endpoint.
Properties
High
Upper endpoint of the range of the distribution. High is included in the range.
public double 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 double Low { get; }
Property Value
Step
A discretization step. null when the distribution is continuous.
public double? 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.
Exceptions
- FormatException
A stepped bound or step is NaN or infinite and cannot be parsed as a decimal.
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.