Skip to main content

Sampler

Trait Sampler 

Source
pub trait Sampler: Send + Sync {
    // Required method
    fn sample(
        &self,
        distribution: &Distribution,
        trial_id: u64,
        history: &[CompletedTrial],
    ) -> ParamValue;
}
Expand description

Trait for pluggable parameter sampling strategies.

Samplers are responsible for generating parameter values based on the distribution and historical trial data. The trait requires Send + Sync to support concurrent and async optimization.

§Examples

Implementing a custom sampler:

use optimizer::{Sampler, ParamValue, Distribution, CompletedTrial};

struct MySampler;

impl Sampler for MySampler {
    fn sample(
        &self,
        distribution: &Distribution,
        trial_id: u64,
        history: &[CompletedTrial],
    ) -> ParamValue {
        // Custom sampling logic here
        todo!()
    }
}

Required Methods§

Source

fn sample( &self, distribution: &Distribution, trial_id: u64, history: &[CompletedTrial], ) -> ParamValue

Samples a parameter value from the given distribution.

§Arguments
  • distribution - The parameter distribution to sample from.
  • trial_id - The unique ID of the trial being sampled for.
  • history - Historical completed trials for informed sampling.
§Returns

A ParamValue sampled from the distribution.

Implementors§