pub struct Accumulator<const N_BLOCKS: usize = 1024, const INIT_BLOCK_DEPTH: u64 = 16> { /* private fields */ }Expand description
A structure for computing statistics using the blocking method.
The blocking method reduces the effects of autocorrelation in Monte Carlo simulations by grouping consecutive measurements into blocks. Each block stores the sum of its values and their squares, enabling the computation of mean, variance, error of the mean, and autocorrelation time.
§Generics
N_BLOCKS: Number of blocks to use (must be a power of 2).INIT_BLOCK_DEPTH: Initial depth of each block (number of measurements per block).
§Methods
add: Adds a measurement to the accumulator.statistics: Computes mean, error, autocorrelation time, and variance.clear: Resets the accumulator to its initial state.
Implementations§
Source§impl<const N_BLOCKS: usize, const INIT_BLOCK_DEPTH: u64> Accumulator<N_BLOCKS, INIT_BLOCK_DEPTH>
impl<const N_BLOCKS: usize, const INIT_BLOCK_DEPTH: u64> Accumulator<N_BLOCKS, INIT_BLOCK_DEPTH>
Sourcepub fn add(&mut self, val: f64)
pub fn add(&mut self, val: f64)
Adds a new measurement to the accumulator.
If the current block is full, it moves to the next block. When all blocks are filled, the block depth is doubled, and the data is consolidated into fewer, larger blocks.
Sourcepub fn statistics(&self) -> Option<(f64, f64, f64, f64)>
pub fn statistics(&self) -> Option<(f64, f64, f64, f64)>
Computes and returns the mean, error of the mean, autocorrelation time, and standard deviation.
Returns None if no measurements have been added.
§Returns
A tuple containing:
mean: The mean of the measurements.mean_error: The error of the mean, accounting for autocorrelation.autocorr_time: The estimated autocorrelation time.std_dev: The square root of the variance (standard deviation).
Trait Implementations§
Auto Trait Implementations§
impl<const N_BLOCKS: usize, const INIT_BLOCK_DEPTH: u64> Freeze for Accumulator<N_BLOCKS, INIT_BLOCK_DEPTH>
impl<const N_BLOCKS: usize, const INIT_BLOCK_DEPTH: u64> RefUnwindSafe for Accumulator<N_BLOCKS, INIT_BLOCK_DEPTH>
impl<const N_BLOCKS: usize, const INIT_BLOCK_DEPTH: u64> Send for Accumulator<N_BLOCKS, INIT_BLOCK_DEPTH>
impl<const N_BLOCKS: usize, const INIT_BLOCK_DEPTH: u64> Sync for Accumulator<N_BLOCKS, INIT_BLOCK_DEPTH>
impl<const N_BLOCKS: usize, const INIT_BLOCK_DEPTH: u64> Unpin for Accumulator<N_BLOCKS, INIT_BLOCK_DEPTH>
impl<const N_BLOCKS: usize, const INIT_BLOCK_DEPTH: u64> UnwindSafe for Accumulator<N_BLOCKS, INIT_BLOCK_DEPTH>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more