Trait ChainRunner

Source
pub trait ChainRunner<T>: HasChains<T>{
    // Provided methods
    fn run(
        &mut self,
        n_collect: usize,
        n_discard: usize,
    ) -> Result<Array3<T>, ShapeError> { ... }
    fn run_progress(
        &mut self,
        n_collect: usize,
        n_discard: usize,
    ) -> Result<(Array3<T>, RunStats), Box<dyn Error>> { ... }
}
Expand description

An extension trait for types that own multiple MCMC chains.

ChainRunner<T> extends HasChains<T> by providing default methods to run all chains in parallel. These methods allow you to:

  • Run all chains, collect n_collect samples and discard n_discard initial burn-in samples.
  • Optionally display progress bars for each chain during execution.

Any type that implements HasChains<T> (with appropriate bounds on T) automatically implements ChainRunner<T>.

Provided Methods§

Source

fn run( &mut self, n_collect: usize, n_discard: usize, ) -> Result<Array3<T>, ShapeError>

Runs all chains in parallel, discarding the first discard iterations (burn-in).

§Arguments
  • n_collect - The number of samples to collect and return.
  • n_discard - The number of samples to discard (burn-in).
§Returns

A ndarray::Array3 tensor with the first axis representing the chain, the second one the step and the last one the parameter dimension.

Source

fn run_progress( &mut self, n_collect: usize, n_discard: usize, ) -> Result<(Array3<T>, RunStats), Box<dyn Error>>

Runs all chains in parallel with progress bars, discarding the burn-in.

Each chain is run in parallel with its own progress bar. After execution, the first discard iterations are discarded.

§Arguments
  • n_collect - The number of samples to collect and return.
  • n_discard - The number of samples to discard (burn-in).
§Returns

Returns a tuple containing:

  • A ndarray::Array3 tensor with the first axis representing the chain, the second one the step and the last one the parameter dimension.
  • A RunStats object containing convergence statistics including:
    • Acceptance probability
    • Potential scale reduction factor (R-hat)
    • Effective sample size (ESS)
    • Other convergence diagnostics

Implementors§