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§
Provided Methods§
Sourcefn iterations(&self, _walkers: usize) -> Option<usize>
fn iterations(&self, _walkers: usize) -> Option<usize>
If possible, compute a lower bound for the number of iterations given the number of walkers