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
nuses combinationn % 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
impl GridSampler
Sourcepub fn new() -> GridSampler
pub fn new() -> GridSampler
A grid sampler with no parameters registered yet.
Sourcepub fn add_grid(self, name: &str, values: Vec<Value>) -> GridSampler
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.
Sourcepub fn add_float_grid(self, name: &str, values: &[f64]) -> GridSampler
pub fn add_float_grid(self, name: &str, values: &[f64]) -> GridSampler
Register a float-valued grid.
Sourcepub fn add_int_grid(self, name: &str, values: &[i64]) -> GridSampler
pub fn add_int_grid(self, name: &str, values: &[i64]) -> GridSampler
Register an integer-valued grid.
Sourcepub fn add_categorical_grid(self, name: &str, values: &[&str]) -> GridSampler
pub fn add_categorical_grid(self, name: &str, values: &[&str]) -> GridSampler
Register a categorical grid.