Accumulator

Struct Accumulator 

Source
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>

Source

pub fn new() -> Self

Creates a new Accumulator instance.

§Panics

Panics if N_BLOCKS is not a power of 2.

Source

pub fn size(&self) -> u64

Returns the total number of input values added to the accumulator.

Source

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.

Source

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).
Source

pub fn clear(&mut self)

Resets the accumulator, clearing all measurements and restoring initial settings.

Trait Implementations§

Source§

impl<const N_BLOCKS: usize, const INIT_BLOCK_DEPTH: u64> Default for Accumulator<N_BLOCKS, INIT_BLOCK_DEPTH>

Source§

fn default() -> Self

Default implementation for Accumulator<N_BLOCKS, INIT_BLOCK_DEPTH>

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V