numerics
Loading...
Searching...
No Matches
num::RunningStats Struct Reference

#include <stats.hpp>

Public Member Functions

void update (real x)
 Incorporate one new sample.
 
real variance () const
 Unbiased sample variance (n-1 denominator). Returns 0 for n < 2.
 
real std_dev () const
 
real stderr_mean () const
 Standard error of the mean (uncorrelated samples).
 
void reset ()
 

Public Attributes

real mean = 0.0
 
real M2 = 0.0
 
idx count = 0
 

Detailed Description

Online mean and variance via Welford's algorithm. One-pass, numerically stable, O(1) memory.

Definition at line 18 of file stats.hpp.

Member Function Documentation

◆ reset()

void num::RunningStats::reset ( )
inline

Definition at line 44 of file stats.hpp.

References count, M2, and mean.

Referenced by main().

◆ std_dev()

real num::RunningStats::std_dev ( ) const
inline

Definition at line 37 of file stats.hpp.

References variance().

Referenced by main(), and stderr_mean().

◆ stderr_mean()

real num::RunningStats::stderr_mean ( ) const
inline

Standard error of the mean (uncorrelated samples).

Definition at line 40 of file stats.hpp.

References count, and std_dev().

◆ update()

void num::RunningStats::update ( real  x)
inline

Incorporate one new sample.

Definition at line 24 of file stats.hpp.

References count, num::ipow(), M2, and mean.

Referenced by main().

◆ variance()

real num::RunningStats::variance ( ) const
inline

Unbiased sample variance (n-1 denominator). Returns 0 for n < 2.

Definition at line 33 of file stats.hpp.

References count, and M2.

Referenced by std_dev().

Member Data Documentation

◆ count

idx num::RunningStats::count = 0

Definition at line 21 of file stats.hpp.

Referenced by main(), reset(), stderr_mean(), update(), and variance().

◆ M2

real num::RunningStats::M2 = 0.0

Definition at line 20 of file stats.hpp.

Referenced by reset(), update(), and variance().

◆ mean

real num::RunningStats::mean = 0.0

Definition at line 19 of file stats.hpp.

Referenced by main(), reset(), and update().


The documentation for this struct was generated from the following file: