Skip to main content

GridSampler

Struct GridSampler 

Source
pub struct GridSampler { /* private fields */ }
Expand description

Exhaustive search over a caller-provided discrete grid.

Unlike crate::RandomSampler, which can sample continuous distributions directly, GridSampler only makes sense for parameters with a finite, pre-specified set of values — you must register each parameter’s grid up front with GridSampler::add_grid (or the typed helpers). The trials are enumerated as a mixed-radix odometer over the registered grids: trial n maps deterministically to one point in the Cartesian product, in the order the grids were added.

Notes / limitations:

  • Because this is define-by-run, a given trial may not request every registered parameter (conditional spaces). Enumeration still ranges over the full product; unused coordinates simply don’t get read that trial.
  • If more trials are run than there are grid points, the odometer wraps (trial n uses combination n % total).
  • A parameter that is suggested but was never registered has no grid to draw from, so it falls back to a random draw (seeded, for reproducibility) and is documented as such rather than silently returning a constant.

Implementations§

Source§

impl GridSampler

Source

pub fn new() -> GridSampler

A grid sampler with no parameters registered yet.

Source

pub fn add_grid(self, name: &str, values: Vec<Value>) -> GridSampler

Register a parameter’s grid of explicit values. Order of registration defines the odometer axis order.

Source

pub fn add_float_grid(self, name: &str, values: &[f64]) -> GridSampler

Register a float-valued grid.

Source

pub fn add_int_grid(self, name: &str, values: &[i64]) -> GridSampler

Register an integer-valued grid.

Source

pub fn add_categorical_grid(self, name: &str, values: &[&str]) -> GridSampler

Register a categorical grid.

Source

pub fn grid_size(&self) -> usize

Total number of grid points (the product of all registered grid sizes). Running this many trials covers the whole grid exactly once.

Trait Implementations§

Source§

impl Default for GridSampler

Source§

fn default() -> GridSampler

Returns the “default value” for a type. Read more
Source§

impl Sampler for GridSampler

Source§

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.