npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
npstat::StatAccumulator Class Reference

#include <StatAccumulator.hh>

Public Member Functions

unsigned long count () const
 
double min () const
 
double max () const
 
long double sum () const
 
long double sumsq () const
 
double mean () const
 
double stdev () const
 
double meanUncertainty () const
 
double location () const
 
double rangeDown () const
 
double rangeUp () const
 
double noThrowMean (double valueIfNoData=0.0) const
 
double noThrowStdev (double valueIfNoData=0.0) const
 
double noThrowMeanUncertainty (double valueIfNoData=0.0) const
 
void accumulate (double value)
 
StatAccumulatoroperator+= (const double r)
 
void accumulate (const StatAccumulator &)
 
StatAccumulatoroperator+= (const StatAccumulator &r)
 
void accumulate (const StatAccumulator &, double w)
 
template<typename Numeric >
void accumulate (const Numeric *values, const unsigned long n)
 
template<typename ConvertibleToLongDouble >
StatAccumulatoroperator*= (const ConvertibleToLongDouble &r)
 
template<typename ConvertibleToLongDouble >
StatAccumulatoroperator/= (const ConvertibleToLongDouble &r)
 
template<typename ConvertibleToLDouble >
StatAccumulator operator* (const ConvertibleToLDouble &r) const
 
template<typename ConvertibleToLDouble >
StatAccumulator operator/ (const ConvertibleToLDouble &r) const
 
StatAccumulator operator+ (const StatAccumulator &r) const
 
void reset ()
 
bool operator== (const StatAccumulator &r) const
 
bool operator!= (const StatAccumulator &r) const
 
gs::ClassId classId () const
 
bool write (std::ostream &of) const
 

Static Public Member Functions

static const char * classname ()
 
static unsigned version ()
 
static void restore (const gs::ClassId &id, std::istream &in, StatAccumulator *acc)
 

Detailed Description

This class calculates minimum value, maximum value, mean, and standard deviation for a set of observations. "mean" and "stdev" functions will cause a runtime exception to be thrown in case "accumulate" function was never called after the object was created (or after it was reset).

This code updates a running average, so it should work better than a "naive" implementation. If you still need to improve the calculation of the standard deviation, use SampleAccumulator class which remembers all input points and performs a two-pass calculation.

Member Function Documentation

◆ accumulate() [1/4]

template<typename Numeric >
void npstat::StatAccumulator::accumulate ( const Numeric *  values,
const unsigned long  n 
)
inline

Accumulate a sample

◆ accumulate() [2/4]

void npstat::StatAccumulator::accumulate ( const StatAccumulator )

Add the sample from another accumulator

◆ accumulate() [3/4]

void npstat::StatAccumulator::accumulate ( const StatAccumulator ,
double  w 
)

Accumulate a product of a StatAccumulator times double

◆ accumulate() [4/4]

void npstat::StatAccumulator::accumulate ( double  value)

Main data accumulating function

◆ classId()

gs::ClassId npstat::StatAccumulator::classId ( ) const
inline

Method related to "geners" I/O

◆ count()

unsigned long npstat::StatAccumulator::count ( ) const
inline

Number of observations processed so far

◆ location()

double npstat::StatAccumulator::location ( ) const
inline

Standard plotting accessor

◆ max()

double npstat::StatAccumulator::max ( ) const
inline

Maximum value in the processed sample

◆ mean()

double npstat::StatAccumulator::mean ( ) const

Accumulated sample average

◆ meanUncertainty()

double npstat::StatAccumulator::meanUncertainty ( ) const

Uncertainty of the population mean

◆ min()

double npstat::StatAccumulator::min ( ) const
inline

Minimum value in the processed sample

◆ noThrowMean()

double npstat::StatAccumulator::noThrowMean ( double  valueIfNoData = 0.0) const

Accumulated sample average. Will not throw an exception if no data is accumulated. Instead, the provided function argument will be returned.

◆ noThrowMeanUncertainty()

double npstat::StatAccumulator::noThrowMeanUncertainty ( double  valueIfNoData = 0.0) const

Uncertainty of the mean. Will not throw an exception if no data is accumulated. Instead, the provided function argument will be returned.

◆ noThrowStdev()

double npstat::StatAccumulator::noThrowStdev ( double  valueIfNoData = 0.0) const

Standard deviation estimate. Will not throw an exception if no data is accumulated. Instead, the provided function argument will be returned.

◆ operator!=()

bool npstat::StatAccumulator::operator!= ( const StatAccumulator r) const
inline

Logical negation of operator==

◆ operator*()

template<typename ConvertibleToLDouble >
StatAccumulator npstat::StatAccumulator::operator* ( const ConvertibleToLDouble &  r) const
inline

Binary multiplication by a double

◆ operator*=()

template<typename ConvertibleToLongDouble >
StatAccumulator& npstat::StatAccumulator::operator*= ( const ConvertibleToLongDouble &  r)
inline

The effect of "operator*=" is the same as if all values were multiplied by "r" for each "accumulate" call

◆ operator+()

StatAccumulator npstat::StatAccumulator::operator+ ( const StatAccumulator r) const
inline

Binary sum with another accumulator

◆ operator/()

template<typename ConvertibleToLDouble >
StatAccumulator npstat::StatAccumulator::operator/ ( const ConvertibleToLDouble &  r) const
inline

Binary division by a double

◆ operator/=()

template<typename ConvertibleToLongDouble >
StatAccumulator& npstat::StatAccumulator::operator/= ( const ConvertibleToLongDouble &  r)
inline

The effect of "operator/=" is the same as if all values were divided by "r" for each "accumulate" call

◆ operator==()

bool npstat::StatAccumulator::operator== ( const StatAccumulator r) const

Comparison for equality

◆ reset()

void npstat::StatAccumulator::reset ( )

Clear all accumulators

◆ stdev()

double npstat::StatAccumulator::stdev ( ) const

Estimate of the population standard deviation

◆ sum()

long double npstat::StatAccumulator::sum ( ) const

Sum of all observations

◆ sumsq()

long double npstat::StatAccumulator::sumsq ( ) const

Accumulated sum of squares


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