Module samplers

Source
Expand description

Samplers are containers for sampling data or convergence trajectories; or recording epochs/iterations for later tabulation, plotting or analysis.

ContainerDescription
SampleVeca reservoir sampler for periodic sampling
SampleDequea reservoir sampler with guaranteed front and back minimum samples. Ideal for plots where the initial and final points are important to capture
ProgressBarprints a progress bar
Tabulatedisplays a simple table using println style formatting

§Example

use stepwise::{VectorExt as _, Driver, fixed_iters, Step, samplers::SampleDeque};

// create a container with 10 initial, and 10 final samples,
// and 500 samples evenly taken from the 1,000,000 iterations
// this allows minimal memory use, and fast plotting
let mut sampler = SampleDeque::with_sizes(10, 500, 10);

type Point = (usize, Vec<f64>);  // (iteration number, X-vector)

let (_solved, _step) = fixed_iters(gradient_descent, 1_000_000)
    .on_step(|algo, step| {
        let point: Point = (step.iteration(), algo.x().to_vec());
        sampler.sample(point);
   })
   .solve()
   .unwrap();


// plot_data will have 500 evenly spaced samples, with the first and
// last 10 items guaranteed to be captured
let plot_data : Vec<Point> = sampler.into_unordered_iter().collect();

Structs§

ProgressBar
A progress bar which can display to Stderr or Stdout
SampleDeque
A segmented vector that divides elements into three regions: head, middle, and tail.
SampleVec
Tabulate
A Tabulator or table generator which can display to Stderr or Stdout

Enums§

SamplingOutcome
Indicates the action taken by sampling.

Traits§

Sampler
Sampler trait