pub trait Parameter: Debug {
type Value;
// Required methods
fn id(&self) -> ParamId;
fn distribution(&self) -> Distribution;
fn cast_param_value(&self, param_value: &ParamValue) -> Result<Self::Value>;
// Provided methods
fn validate(&self) -> Result<()> { ... }
fn label(&self) -> String { ... }
fn suggest(&self, trial: &mut Trial) -> Result<Self::Value>
where Self: Sized { ... }
}Expand description
Define a parameter type that can be suggested by a Trial.
Implementors specify the distribution to sample from and how to convert
the raw ParamValue back into a typed value. See the five built-in
implementations: FloatParam, IntParam, CategoricalParam,
BoolParam, and EnumParam.
Required Associated Types§
Required Methods§
Sourcefn distribution(&self) -> Distribution
fn distribution(&self) -> Distribution
Return the distribution that this parameter samples from.
Sourcefn cast_param_value(&self, param_value: &ParamValue) -> Result<Self::Value>
fn cast_param_value(&self, param_value: &ParamValue) -> Result<Self::Value>
Convert a raw ParamValue into the typed value.
§Errors
Return an error if the ParamValue variant does not match what this parameter expects.
Provided Methods§
Sourcefn validate(&self) -> Result<()>
fn validate(&self) -> Result<()>
Validate the parameter configuration.
Called before sampling. The default implementation accepts all configurations.
§Errors
Return an error if the parameter configuration is invalid.
Sourcefn label(&self) -> String
fn label(&self) -> String
Return a human-readable label for this parameter.
Defaults to the Debug output of the parameter. Override with
the .name() builder method on concrete types.
Sourcefn suggest(&self, trial: &mut Trial) -> Result<Self::Value>where
Self: Sized,
fn suggest(&self, trial: &mut Trial) -> Result<Self::Value>where
Self: Sized,
Suggest a value for this parameter from the given trial.
This is a convenience method that delegates to Trial::suggest_param.
§Examples
use optimizer::Trial;
use optimizer::parameter::{FloatParam, Parameter};
let mut trial = Trial::new(0);
let param = FloatParam::new(-5.0, 5.0).name("x");
let value: f64 = param.suggest(&mut trial).unwrap();
assert!((-5.0..=5.0).contains(&value));§Errors
Return an error if validation fails, the parameter conflicts with a previously suggested parameter of the same id, or sampling fails.