Skip to main content

Sampler

Trait Sampler 

Source
pub trait Sampler: Send + Sync {
    // Required methods
    fn sample(
        &mut self,
        space: &SearchSpace,
        trial_index: usize,
    ) -> Result<Option<HashMap<String, Value>>>;
    fn n_trials(&self) -> Option<usize>;

    // Provided methods
    fn prepare(&mut self, _space: &SearchSpace) { ... }
    fn record_result(&mut self, _params: &HashMap<String, Value>, _value: f64) { ... }
}
Expand description

A sampler produces hyperparameter configurations from a search space.

The contract is ask/tell: the runner calls prepare once before the loop, sample to ask for the next configuration, and record_result to tell the sampler each completed trial’s objective value — the feedback that model-based samplers (TPE, future BO backends) require.

Required Methods§

Source

fn sample( &mut self, space: &SearchSpace, trial_index: usize, ) -> Result<Option<HashMap<String, Value>>>

Sample the next set of parameters. Returns None when exhausted.

Source

fn n_trials(&self) -> Option<usize>

Total number of trials this sampler will produce (if known).

Provided Methods§

Source

fn prepare(&mut self, _space: &SearchSpace)

Called once before the trial loop with the resolved search space. Lets samplers precompute state — e.g. GridSampler resolves its dimension grid here so n_trials is correct before the first sample.

Source

fn record_result(&mut self, _params: &HashMap<String, Value>, _value: f64)

Feedback for a completed trial. value is normalized so that higher is always better (the runner negates for Minimize). Default: no-op (stateless samplers ignore feedback).

Implementors§