npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
npstat::SampleAccumulator< Numeric, Precise > Class Template Reference

#include <SampleAccumulator.hh>

Public Types

typedef Numeric value_type
 
typedef Precise precise_type
 

Public Member Functions

unsigned long count () const
 
Numeric min () const
 
Numeric max () const
 
Precise mean () const
 
Precise stdev () const
 
Precise meanUncertainty () const
 
Numeric median () const
 
double cdf (Numeric value) const
 
unsigned long nBelow (Numeric value) const
 
Numeric quantile (double x) const
 
Numeric location () const
 
Numeric rangeDown () const
 
Numeric rangeUp () const
 
Numeric sigmaRange () const
 
Precise noThrowMean (const Precise &valueIfNoData) const
 
Precise noThrowStdev (const Precise &valueIfNoData) const
 
Precise noThrowMeanUncertainty (const Precise &valueIfNoData) const
 
const Numeric * data () const
 
template<typename Numeric2 , typename Precise2 >
Precise cov (const SampleAccumulator< Numeric2, Precise2 > &other) const
 
template<typename Num2 , typename Prec2 >
Precise corr (const SampleAccumulator< Num2, Prec2 > &other) const
 
bool operator== (const SampleAccumulator &r) const
 
bool operator!= (const SampleAccumulator &r) const
 
void accumulate (const Numeric &value)
 
SampleAccumulatoroperator+= (const Numeric &r)
 
void accumulate (const Numeric *values, unsigned long n)
 
void accumulate (const SampleAccumulator &acc)
 
SampleAccumulatoroperator+= (const SampleAccumulator &r)
 
template<typename Num2 >
SampleAccumulatoroperator*= (const Num2 &r)
 
template<typename Num2 >
SampleAccumulatoroperator/= (const Num2 &r)
 
SampleAccumulator operator+ (const SampleAccumulator &r) const
 
template<typename Num2 >
SampleAccumulator operator* (const Num2 &r) const
 
template<typename Num2 >
SampleAccumulator operator/ (const Num2 &r) const
 
void reset ()
 
void reserve (const unsigned long n)
 
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, SampleAccumulator *acc)
 

Detailed Description

template<typename Numeric, typename Precise = typename PreciseType<Numeric>::type>
class npstat::SampleAccumulator< Numeric, Precise >

Accumulator of values (or items) for the purpose of calculating statistical summaries in a numerically stable manner.

Note that calculating quantiles using "median", "cdf", and "quantile" methods makes subsequent calls to the "cov" and "corr" methods impossible (a dynamic fault will be generated). This is because the data is sorted internally for quantile calculations, and subsequent covariance calculation with sorted samples will return a result which is most likely not intended.

Member Function Documentation

◆ accumulate() [1/3]

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
void npstat::SampleAccumulator< Numeric, Precise >::accumulate ( const Numeric &  value)
inline

Accumulate the sample

◆ accumulate() [2/3]

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
void npstat::SampleAccumulator< Numeric, Precise >::accumulate ( const Numeric *  values,
unsigned long  n 
)

Accumulate more than one value at a time

◆ accumulate() [3/3]

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
void npstat::SampleAccumulator< Numeric, Precise >::accumulate ( const SampleAccumulator< Numeric, Precise > &  acc)

Accumulate the sample from another accumulator

◆ cdf()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
double npstat::SampleAccumulator< Numeric, Precise >::cdf ( Numeric  value) const

Empirical cumulative distribuition function

◆ classId()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
gs::ClassId npstat::SampleAccumulator< Numeric, Precise >::classId ( ) const
inline

Method related to "geners" I/O

◆ count()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
unsigned long npstat::SampleAccumulator< Numeric, Precise >::count ( ) const
inline

Number of items in the accumulated sample

◆ cov()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
template<typename Numeric2 , typename Precise2 >
Precise npstat::SampleAccumulator< Numeric, Precise >::cov ( const SampleAccumulator< Numeric2, Precise2 > &  other) const

Covariance and correlation with another accumulator. That other accumulator must have the same number of points stored. Note that "cov" and "corr" methods typically make sense only for the original, unmodified sequences of data values. If the data points have been sorted (which happens internally whenever one of the methods "median", "cdf", "quantile", or "nBelow" is called), covariance and correlation can produce rather unexpected results. To prevent any confusion, this class will throw an exception of type std::runtime_error in case "cov" or "corr" is called after the data in any of the two accumulators has been sorted. Basically, if you plan to calculate covariances between accumulators, do it before calculating any quantiles or cdf values.

◆ data()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
const Numeric* npstat::SampleAccumulator< Numeric, Precise >::data ( ) const
inline

Note that the result returned by this method may be invalidated by a call to any non-const method

◆ location()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
Numeric npstat::SampleAccumulator< Numeric, Precise >::location ( ) const
inline

Standard plotting accessor

◆ max()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
Numeric npstat::SampleAccumulator< Numeric, Precise >::max ( ) const

Maximum value in the accumulated sample

◆ mean()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
Precise npstat::SampleAccumulator< Numeric, Precise >::mean ( ) const

Accumulated sample average

◆ meanUncertainty()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
Precise npstat::SampleAccumulator< Numeric, Precise >::meanUncertainty ( ) const

Uncertainty of the population mean

◆ median()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
Numeric npstat::SampleAccumulator< Numeric, Precise >::median ( ) const

Accumulated sample median

◆ min()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
Numeric npstat::SampleAccumulator< Numeric, Precise >::min ( ) const

Minimum value in the accumulated sample

◆ nBelow()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
unsigned long npstat::SampleAccumulator< Numeric, Precise >::nBelow ( Numeric  value) const

Exact number of points below the given value

◆ noThrowMean()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
Precise npstat::SampleAccumulator< Numeric, Precise >::noThrowMean ( const Precise &  valueIfNoData) const

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

◆ noThrowMeanUncertainty()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
Precise npstat::SampleAccumulator< Numeric, Precise >::noThrowMeanUncertainty ( const Precise &  valueIfNoData) const

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

◆ noThrowStdev()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
Precise npstat::SampleAccumulator< Numeric, Precise >::noThrowStdev ( const Precise &  valueIfNoData) const

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

◆ operator!=()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
bool npstat::SampleAccumulator< Numeric, Precise >::operator!= ( const SampleAccumulator< Numeric, Precise > &  r) const

Logical negation of operator==

◆ operator*=()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
template<typename Num2 >
SampleAccumulator& npstat::SampleAccumulator< Numeric, Precise >::operator*= ( const Num2 &  r)

Multiply every entry by a constant

◆ operator/=()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
template<typename Num2 >
SampleAccumulator& npstat::SampleAccumulator< Numeric, Precise >::operator/= ( const Num2 &  r)

Divide every entry by a constant

◆ operator==()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
bool npstat::SampleAccumulator< Numeric, Precise >::operator== ( const SampleAccumulator< Numeric, Precise > &  r) const

Comparison for equality

◆ quantile()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
Numeric npstat::SampleAccumulator< Numeric, Precise >::quantile ( double  x) const

Empirical quantile function

◆ reserve()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
void npstat::SampleAccumulator< Numeric, Precise >::reserve ( const unsigned long  n)
inline

Reserve memory for data to be accumulated in the future

◆ reset()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
void npstat::SampleAccumulator< Numeric, Precise >::reset ( )
inline

Clear all accumulated data

◆ sigmaRange()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
Numeric npstat::SampleAccumulator< Numeric, Precise >::sigmaRange ( ) const
inline

Robust scale corresponding to the standard deviation for points distributed according to the Gaussian distribution

◆ stdev()

template<typename Numeric , typename Precise = typename PreciseType<Numeric>::type>
Precise npstat::SampleAccumulator< Numeric, Precise >::stdev ( ) const

Estimate of the population standard deviation


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