pub struct EnumParam<T: Categorical> { /* private fields */ }Expand description
A parameter that selects from the variants of an enum implementing Categorical.
Prefer this over CategoricalParam when the choices map to a Rust enum,
because the returned value is already the correct variant — no string
matching required.
§Examples
use optimizer::Trial;
use optimizer::parameter::{Categorical, EnumParam, Parameter};
#[derive(Clone, Debug)]
enum Optimizer {
Sgd,
Adam,
Rmsprop,
}
impl Categorical for Optimizer {
const N_CHOICES: usize = 3;
fn from_index(index: usize) -> Self {
match index {
0 => Optimizer::Sgd,
1 => Optimizer::Adam,
2 => Optimizer::Rmsprop,
_ => panic!("invalid index"),
}
}
fn to_index(&self) -> usize {
match self {
Optimizer::Sgd => 0,
Optimizer::Adam => 1,
Optimizer::Rmsprop => 2,
}
}
}
let mut trial = Trial::new(0);
let opt = EnumParam::<Optimizer>::new()
.name("optimizer")
.suggest(&mut trial)
.unwrap();Implementations§
Source§impl<T: Categorical> EnumParam<T>
impl<T: Categorical> EnumParam<T>
Trait Implementations§
Source§impl<T: Categorical> Default for EnumParam<T>
impl<T: Categorical> Default for EnumParam<T>
Source§impl<T: Categorical + Debug> Parameter for EnumParam<T>
impl<T: Categorical + Debug> Parameter for EnumParam<T>
Source§fn distribution(&self) -> Distribution
fn distribution(&self) -> Distribution
Return the distribution that this parameter samples from.
Source§fn cast_param_value(&self, param_value: &ParamValue) -> Result<T>
fn cast_param_value(&self, param_value: &ParamValue) -> Result<T>
Convert a raw
ParamValue into the typed value. Read moreAuto Trait Implementations§
impl<T> Freeze for EnumParam<T>
impl<T> RefUnwindSafe for EnumParam<T>where
T: RefUnwindSafe,
impl<T> Send for EnumParam<T>where
T: Send,
impl<T> Sync for EnumParam<T>where
T: Sync,
impl<T> Unpin for EnumParam<T>where
T: Unpin,
impl<T> UnsafeUnpin for EnumParam<T>
impl<T> UnwindSafe for EnumParam<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more