casacore
|
A statistics accumulator
More...
#include <StatAcc.h>
Public Member Functions | |
StatAcc () | |
constructors and destructor. More... | |
StatAcc (const StatAcc &) | |
~StatAcc () | |
void | reset () |
Reset or copy the accumulator attributes. More... | |
void | copy (const StatAcc &) |
StatAcc & | operator= (const StatAcc &) |
Operators for adding and copying accumulators. More... | |
StatAcc | operator+ (const StatAcc &) |
StatAcc & | operator+= (const StatAcc &) |
void | put (const T v) |
Accumulate input value(s) v with weight w. More... | |
void | put (const T v, const Float w) |
void | put (const Array< T > &v) |
void | put (const Array< T > &v, const Array< Float > &w) |
void | put (const Block< T > &v) |
void | put (const Block< T > &v, const Block< Float > &w) |
Double | getWtot () const |
Get statistics results one at a time. More... | |
uInt | getCount () const |
Fallible< Double > | getMin () const |
Fallible< Double > | getMax () const |
Fallible< Double > | getMean () const |
Fallible< Double > | getRms () const |
Fallible< Double > | getVariance () const |
Fallible< Double > | getRmsAbs () const |
void | printSummaryList (std::ostream &, const String &caption) const |
Print summary of accumulated statistics. More... | |
void | printSummaryLine (std::ostream &, const String &caption) const |
void | printSummaryLineHeader (std::ostream &, const String &caption) const |
Private Member Functions | |
void | put1 (const T, const Float) |
Accumulate a single weighted value. More... | |
Private Attributes | |
Double | itsWtot |
Double | itsWsum |
Double | itsWssum |
Double | itsMin |
Double | itsMax |
uInt | itsCount |
A statistics accumulator
StatAcc stands for ‘Statistics Accumulator’.
A statistics accumulator accepts (weighted) input values and calculates simple statistice (min, max, weighted mean, rms etc). The accepted input types are real, i.e. Int, uInt, Float, Double, but not Complex. The reason for this is that the < operator of Complex (needed for min/max) works on the norm in any case, and the sqrt function (needed for rms) yields an ambiguous result.
Restriction to real types also allows the internal arithmetic type to be Double rather than the input type. The latter would give all kinds of complications with weighting, accuracy and overflow if the input type would be Int or uInt.
The (weighted) values are fed to StatAcc via the member function ‘put’. They can be fed individually, or in the form of an Array. The weights are optional (default = 1) and always have type Float.
Asking for a result does not change the internal state. The type of the returned results is always Fallible<Double>. A result is invalid if no input values with non-zero weight have been accumulated yet.
The accumulator can be re-initialised with the function ‘reset’. Accumulators can be added to each other, which is as if their combined values had been accumulated in the same accumulator.
Some functions have been provided to display a summary of the statistics results. One may choose between a one-line format (with an optional associated header line), and a list.
One often needs simple statistics of a series of values, which may occur by themselves or in arrays at various points in a program.
Sincs it is a pain to have to assign accumulation variables, and to write statistics evaluation code (including exceptions), this helper class is provided.
casacore::StatAcc< T >::StatAcc | ( | ) |
constructors and destructor.
casacore::StatAcc< T >::StatAcc | ( | const StatAcc< T > & | ) |
|
inline |
void casacore::StatAcc< T >::copy | ( | const StatAcc< T > & | ) |
uInt casacore::StatAcc< T >::getCount | ( | ) | const |
Fallible<Double> casacore::StatAcc< T >::getMax | ( | ) | const |
Fallible<Double> casacore::StatAcc< T >::getMean | ( | ) | const |
Fallible<Double> casacore::StatAcc< T >::getMin | ( | ) | const |
Fallible<Double> casacore::StatAcc< T >::getRms | ( | ) | const |
Fallible<Double> casacore::StatAcc< T >::getRmsAbs | ( | ) | const |
Fallible<Double> casacore::StatAcc< T >::getVariance | ( | ) | const |
Double casacore::StatAcc< T >::getWtot | ( | ) | const |
Get statistics results one at a time.
Count is the nr of values accumulated. Wtot is the sum of the weights. Rms is defined w.r.t. the mean, and is the square of Variance. RmsAbs is the root-mean-square of the absolute input values.
StatAcc casacore::StatAcc< T >::operator+ | ( | const StatAcc< T > & | ) |
StatAcc& casacore::StatAcc< T >::operator+= | ( | const StatAcc< T > & | ) |
StatAcc& casacore::StatAcc< T >::operator= | ( | const StatAcc< T > & | ) |
Operators for adding and copying accumulators.
void casacore::StatAcc< T >::printSummaryLine | ( | std::ostream & | , |
const String & | caption | ||
) | const |
void casacore::StatAcc< T >::printSummaryLineHeader | ( | std::ostream & | , |
const String & | caption | ||
) | const |
void casacore::StatAcc< T >::printSummaryList | ( | std::ostream & | , |
const String & | caption | ||
) | const |
Print summary of accumulated statistics.
Line is a one-line summary, including the (short) caption. LineHeader gives a one-line explanation of the numbers. List uses a separate line for each result (mean, max etc).
void casacore::StatAcc< T >::put | ( | const Array< T > & | v | ) |
void casacore::StatAcc< T >::put | ( | const Array< T > & | v, |
const Array< Float > & | w | ||
) |
void casacore::StatAcc< T >::put | ( | const Block< T > & | v | ) |
void casacore::StatAcc< T >::put | ( | const Block< T > & | v, |
const Block< Float > & | w | ||
) |
|
inline |
|
inline |
|
private |
Accumulate a single weighted value.
void casacore::StatAcc< T >::reset | ( | ) |
Reset or copy the accumulator attributes.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |