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

#include <WeightedStatAccumulator.hh>

Public Member Functions

double min () const
 
double max () const
 
double maxWeight () 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
 
double count () const
 
unsigned long ncalls () const
 
unsigned long nfills () const
 
double averageWeight () const
 
double sumOfWeights () const
 
double sumOfSquaredWeights () const
 
void accumulate (double value, double weight)
 
void accumulate (const WeightedStatAccumulator &)
 
void accumulate (const WeightedStatAccumulator &, double weight)
 
template<typename Pair >
WeightedStatAccumulatoroperator+= (const Pair &pair)
 
WeightedStatAccumulatoroperator+= (const WeightedStatAccumulator &r)
 
template<typename ConvertibleToDouble >
WeightedStatAccumulatoroperator*= (const ConvertibleToDouble &r)
 
template<typename ConvertibleToDouble >
WeightedStatAccumulatoroperator/= (const ConvertibleToDouble &r)
 
template<typename ConvToDouble >
WeightedStatAccumulator operator* (const ConvToDouble &r) const
 
template<typename ConvToDouble >
WeightedStatAccumulator operator/ (const ConvToDouble &r) const
 
WeightedStatAccumulator operator+ (const WeightedStatAccumulator &r) const
 
WeightedStatAccumulatorscaleWeights (double r)
 
void reset ()
 
bool operator== (const WeightedStatAccumulator &r) const
 
bool operator!= (const WeightedStatAccumulator &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, WeightedStatAccumulator *acc)
 

Detailed Description

This class calculates minimum value, maximum value, mean, and standard deviation of weighted 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).

It is assumed that the weights are known precisely and that the weights do not depend on the observations (this is important!). Weights can not be negative.

This code updates a running average, so it should work better than a "naive" implementation.

Member Function Documentation

◆ accumulate() [1/3]

void npstat::WeightedStatAccumulator::accumulate ( const WeightedStatAccumulator )

Add the sample from another accumulator

◆ accumulate() [2/3]

void npstat::WeightedStatAccumulator::accumulate ( const WeightedStatAccumulator ,
double  weight 
)

Accumulate a product of a WeightedStatAccumulator times double

◆ accumulate() [3/3]

void npstat::WeightedStatAccumulator::accumulate ( double  value,
double  weight 
)

Main data accumulating function

◆ averageWeight()

double npstat::WeightedStatAccumulator::averageWeight ( ) const

Average weight (fills with 0 weight are ignored)

◆ classId()

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

Method related to "geners" I/O

◆ count()

double npstat::WeightedStatAccumulator::count ( ) const

This method returns the effective number of counts which is (squared sum of weights)/(sum of squared weights)

◆ location()

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

Standard plotting accessor

◆ max()

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

Maximum value in the processed sample

◆ maxWeight()

double npstat::WeightedStatAccumulator::maxWeight ( ) const
inline

Maximum weight among observations processed so far

◆ mean()

double npstat::WeightedStatAccumulator::mean ( ) const

Accumulated sample average

◆ meanUncertainty()

double npstat::WeightedStatAccumulator::meanUncertainty ( ) const

Uncertainty of the population mean

◆ min()

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

Minimum value in the processed sample

◆ ncalls()

unsigned long npstat::WeightedStatAccumulator::ncalls ( ) const
inline

This method returns the total number of times the "accumulate(double, double)" method was called since the last reset (or since the object was created)

◆ nfills()

unsigned long npstat::WeightedStatAccumulator::nfills ( ) const
inline

This method returns the number of times the "accumulate(double, double)" method was called with a positive weight

◆ noThrowMean()

double npstat::WeightedStatAccumulator::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::WeightedStatAccumulator::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::WeightedStatAccumulator::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::WeightedStatAccumulator::operator!= ( const WeightedStatAccumulator r) const
inline

Logical negation of operator==

◆ operator*()

template<typename ConvToDouble >
WeightedStatAccumulator npstat::WeightedStatAccumulator::operator* ( const ConvToDouble &  r) const
inline

Binary multiplication by a double

◆ operator*=()

template<typename ConvertibleToDouble >
WeightedStatAccumulator& npstat::WeightedStatAccumulator::operator*= ( const ConvertibleToDouble &  r)
inline

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

◆ operator+()

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

Binary sum with another accumulator

◆ operator+=() [1/2]

template<typename Pair >
WeightedStatAccumulator& npstat::WeightedStatAccumulator::operator+= ( const Pair &  pair)
inline

In this method, it is assumed that the first element of the pair is the value and the second is the weight

◆ operator+=() [2/2]

WeightedStatAccumulator& npstat::WeightedStatAccumulator::operator+= ( const WeightedStatAccumulator r)
inline

Add the summary from another accumulator

◆ operator/()

template<typename ConvToDouble >
WeightedStatAccumulator npstat::WeightedStatAccumulator::operator/ ( const ConvToDouble &  r) const
inline

Binary division by a double

◆ operator/=()

template<typename ConvertibleToDouble >
WeightedStatAccumulator& npstat::WeightedStatAccumulator::operator/= ( const ConvertibleToDouble &  r)
inline

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

◆ operator==()

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

Comparison for equality

◆ reset()

void npstat::WeightedStatAccumulator::reset ( )

Clear all accumulators

◆ scaleWeights()

WeightedStatAccumulator& npstat::WeightedStatAccumulator::scaleWeights ( double  r)

Scaling of the weights. The effect is the same as if all weights were multiplied by "r" for each "accumulate" call. Note that r can not be negative for this method.

◆ stdev()

double npstat::WeightedStatAccumulator::stdev ( ) const

Estimate of the population standard deviation

◆ sumOfSquaredWeights()

double npstat::WeightedStatAccumulator::sumOfSquaredWeights ( ) const

Sum of squared weights accumulated so far

◆ sumOfWeights()

double npstat::WeightedStatAccumulator::sumOfWeights ( ) const

Sum of weights accumulated so far


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