Schedule

Trait Schedule 

Source
pub trait Schedule<P>
where P: Params,
{ // Required method fn next_step(&mut self, chain: &[P]) -> ControlFlow<()>; // Provided method fn iterations(&self, _walkers: usize) -> Option<usize> { ... } }
Expand description

Determines how many iterations of the sampler are executed

Enables running the sampler until some condition based on the samples collected so far is fulfilled, for example using the auto-correlation time.

The MinChainLen implementor provides a reasonable default.

It can also be used for progress reporting:

use std::ops::ControlFlow;

use hammer_and_sample::{Params, Schedule};

struct FixedIterationsWithProgress {
    done: usize,
    todo: usize,
}

impl<P> Schedule<P> for FixedIterationsWithProgress
where
    P: Params
{
     fn next_step(&mut self, _chain: &[P]) -> ControlFlow<()> {
        if self.done == self.todo {
            eprintln!("100%");

            ControlFlow::Break(())
        } else {
            self.done += 1;

            if self.done % (self.todo / 100) == 0 {
                eprintln!("{}% ", self.done / (self.todo / 100));
            }

            ControlFlow::Continue(())
        }
    }

    fn iterations(&self, _walkers: usize) -> Option<usize> {
        Some(self.todo)
    }
}

Required Methods§

Source

fn next_step(&mut self, chain: &[P]) -> ControlFlow<()>

The next step in the schedule given the current chain, either continue or break

Provided Methods§

Source

fn iterations(&self, _walkers: usize) -> Option<usize>

If possible, compute a lower bound for the number of iterations given the number of walkers

Implementors§

Source§

impl<P> Schedule<P> for MinChainLen
where P: Params,

Source§

impl<P, S, C> Schedule<P> for WithProgress<S, C>
where P: Params, S: Schedule<P>, C: FnMut(&[P]),