Class EnumCategorical
- Namespace
- OptunaSharp.Distributions
- Assembly
- OptunaSharp.dll
Bridges CLR enums to the string-only categorical machinery. An enum is convenience sugar over
a CategoricalDistribution whose choices are the member-name strings: the type is
never persisted — it is a stateless lens the caller re-supplies at each boundary
(SuggestCategorical<TEnum> on the way in, GetCategorical<TEnum> on the
way out). Consequences to know: (1) the store cannot enforce that the same enum is used to write
and read a parameter — that consistency lives in your source; (2) renaming a member changes the
emitted string, so trials stored before the rename no longer resolve. This keeps the wire,
storage, and samplers byte-identical to a hand-written string categorical.
public static class EnumCategorical
- Inheritance
-
EnumCategorical
- Inherited Members
Methods
Choices<TEnum>()
The declared members of TEnum as categorical choices (member-name
strings). Use it to build a GridSampler search space or
any other IReadOnlyList<CategoricalChoice> over an enum, since there is no
implicit enum→CategoricalChoice conversion.
public static CategoricalChoice[] Choices<TEnum>() where TEnum : struct, Enum
Returns
- CategoricalChoice[]
A fresh array of the member names as choices, in GetNames<TEnum>() (by-value) order.
Type Parameters
TEnumThe enum whose declared members become the choices.
Resolve<TEnum>(object?)
Resolves a stored categorical parameter value to TEnum — the read
side of the lens. This is where a deferred, caller-supplied type is applied, so it is also
where a mismatch is detected and can fail.
public static TEnum Resolve<TEnum>(object? value) where TEnum : struct, Enum
Parameters
valueobjectThe external parameter value: normally the member-name string, or a boxed
TEnumpassed through unchanged.
Returns
- TEnum
The enum member the stored value names.
Type Parameters
TEnumThe enum the caller asserts this parameter was suggested from.
Exceptions
- ValueError
The string is not a declared member of
TEnum.- TypeError
The value is null, an enum of a different type, or a non-string scalar (e.g. the parameter is not a categorical, or belongs to a different enum).