Class Distribution
- Namespace
- OptunaSharp.Distributions
- Assembly
- OptunaSharp.dll
Module-level functions of optuna/distributions.py: JSON round-trip
(distribution_to_json / json_to_distribution) and
check_distribution_compatibility. The storage layer depends on the JSON forms.
public static class Distribution
- Inheritance
-
Distribution
- Inherited Members
Methods
CheckDistributionCompatibility(BaseDistribution, BaseDistribution)
A function to check compatibility of two distributions
(Python check_distribution_compatibility).
It checks whether distOld and distNew are the
same kind of distributions. If distOld is
CategoricalDistribution, it further checks choices are the same
between both. Note that this method is not supposed to be called by library users.
public static void CheckDistributionCompatibility(BaseDistribution distOld, BaseDistribution distNew)
Parameters
distOldBaseDistributionA distribution previously recorded in storage.
distNewBaseDistributionA distribution newly added to storage.
Exceptions
- ValueError
Distribution types or log scales differ, or categorical choices changed.
FromJson(string)
Deserialize a distribution in JSON format (Python json_to_distribution).
public static BaseDistribution FromJson(string jsonStr)
Parameters
jsonStrstringA JSON-serialized distribution.
Returns
- BaseDistribution
A deserialized distribution.
Exceptions
- ValueError
The distribution format, class name, bounds, step, or choices are invalid.
- InvalidCastException
A JSON field has an incompatible runtime type.
- KeyNotFoundException
A required distribution field is absent.
- FormatException
A numeric field cannot be converted.
- OverflowException
A numeric field exceeds the supported conversion range.
- TypeError
A categorical choice is not a supported scalar.
ToJson(BaseDistribution)
Serialize a distribution to JSON format (Python distribution_to_json).
public static string ToJson(BaseDistribution dist)
Parameters
distBaseDistributionA distribution to be serialized.
Returns
- string
A JSON string of a given distribution, byte-identical to Python's output.