Skip to main content

Sampler

Trait Sampler 

Source
pub trait Sampler: Send {
    // Required method
    fn suggest(
        &mut self,
        study_state: &StudyState,
        trial: &Trial,
        param_name: &str,
        distribution: &Distribution,
    ) -> Value;
}
Expand description

A pluggable search algorithm.

A sampler decides which concrete Value to return for each parameter a trial requests. It receives the whole StudyState (read access to prior trials) so adaptive samplers such as TPE have their history without a separate channel, plus the current partially-built trial, the parameter name, and its distribution.

Implementations must return a Value whose variant matches the distribution (Float for Uniform/LogUniform, Int for IntUniform, Categorical for Categorical).

Send is required so a sampler can be shared across worker threads (behind a lock) under [crate::Study::optimize_parallel].

Required Methods§

Source

fn suggest( &mut self, study_state: &StudyState, trial: &Trial, param_name: &str, distribution: &Distribution, ) -> Value

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§