casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Private Member Functions | Private Attributes
casa::StatAcc< T > Class Template Reference

A statistics accumulator. More...

#include <StatAcc.h>

List of all members.

Public Member Functions

 StatAcc ()
 constructors and destructor.
 StatAcc (const StatAcc &)
 ~StatAcc ()
void reset ()
 Reset or copy the accumulator attributes.
void copy (const StatAcc &)
StatAccoperator= (const StatAcc &)
 Operators for adding and copying accumulators.
StatAcc operator+ (const StatAcc &)
StatAccoperator+= (const StatAcc &)
void put (const T v)
 Accumulate input value(s) v with weight w.
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.
uInt getCount () const
Fallible< DoublegetMin () const
Fallible< DoublegetMax () const
Fallible< DoublegetMean () const
Fallible< DoublegetRms () const
Fallible< DoublegetVariance () const
Fallible< DoublegetRmsAbs () const
void printSummaryList (std::ostream &, const String &caption) const
 Print summary of accumulated statistics.
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.

Private Attributes

Double itsWtot
 
     

Double itsWsum
Double itsWssum
Double itsMin
Double itsMax
uInt itsCount

Detailed Description

template<class T>
class casa::StatAcc< T >

A statistics accumulator.

Review Status

Test programs:
tStatAcc

Prerequisite

Etymology

StatAcc stands for `Statistics Accumulator'.

Template Type Argument Requirements (T)

Synopsis

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.

Example

      StatAcc<T> s;               // T is Float, Double, Int etc
      Matrix<T> vv(2,5);          // a matrix (array) of input values
      Matrix<Float> wgt(2,5);     // an associated matrix of weights
      .... fill vv and wgt with values and individual weights ..\.
      s.put(vv,wgt);              // accumulate the weighted values   
      Fallible<Double> min = s.getMin();    // return the minimum value
   
      s.reset();                  // re-initialise
      s.put(vv);                  // if wgt omitted, default = 1.0
      if (s.getRms().isValid() {  // check validity of rms
            ... use it ..\.
      }

Motivation

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.

Definition at line 125 of file StatAcc.h.


Constructor & Destructor Documentation

template<class T>
casa::StatAcc< T >::StatAcc ( )

constructors and destructor.

template<class T>
casa::StatAcc< T >::StatAcc ( const StatAcc< T > &  )
template<class T>
casa::StatAcc< T >::~StatAcc ( ) [inline]

Definition at line 131 of file StatAcc.h.


Member Function Documentation

template<class T>
void casa::StatAcc< T >::copy ( const StatAcc< T > &  )
template<class T>
uInt casa::StatAcc< T >::getCount ( ) const
template<class T>
Fallible<Double> casa::StatAcc< T >::getMax ( ) const
template<class T>
Fallible<Double> casa::StatAcc< T >::getMean ( ) const
template<class T>
Fallible<Double> casa::StatAcc< T >::getMin ( ) const
template<class T>
Fallible<Double> casa::StatAcc< T >::getRms ( ) const
template<class T>
Fallible<Double> casa::StatAcc< T >::getRmsAbs ( ) const
template<class T>
Fallible<Double> casa::StatAcc< T >::getVariance ( ) const
template<class T>
Double casa::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.

template<class T>
StatAcc casa::StatAcc< T >::operator+ ( const StatAcc< T > &  )
template<class T>
StatAcc& casa::StatAcc< T >::operator+= ( const StatAcc< T > &  )
template<class T>
StatAcc& casa::StatAcc< T >::operator= ( const StatAcc< T > &  )

Operators for adding and copying accumulators.

template<class T>
void casa::StatAcc< T >::printSummaryLine ( std::ostream &  ,
const String caption 
) const
template<class T>
void casa::StatAcc< T >::printSummaryLineHeader ( std::ostream &  ,
const String caption 
) const
template<class T>
void casa::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).

template<class T >
void casa::StatAcc< T >::put ( const T  v) [inline]

Accumulate input value(s) v with weight w.

If weight is omitted, the default=1.

Definition at line 205 of file StatAcc.h.

template<class T >
void casa::StatAcc< T >::put ( const T  v,
const Float  w 
) [inline]

Definition at line 210 of file StatAcc.h.

template<class T>
void casa::StatAcc< T >::put ( const Array< T > &  v)
template<class T>
void casa::StatAcc< T >::put ( const Array< T > &  v,
const Array< Float > &  w 
)
template<class T>
void casa::StatAcc< T >::put ( const Block< T > &  v)
template<class T>
void casa::StatAcc< T >::put ( const Block< T > &  v,
const Block< Float > &  w 
)
template<class T>
void casa::StatAcc< T >::put1 ( const T  ,
const Float   
) [private]

Accumulate a single weighted value.

template<class T>
void casa::StatAcc< T >::reset ( )

Reset or copy the accumulator attributes.


Member Data Documentation

template<class T>
uInt casa::StatAcc< T >::itsCount [private]

Definition at line 190 of file StatAcc.h.

template<class T>
Double casa::StatAcc< T >::itsMax [private]

Definition at line 189 of file StatAcc.h.

template<class T>
Double casa::StatAcc< T >::itsMin [private]

Definition at line 188 of file StatAcc.h.

template<class T>
Double casa::StatAcc< T >::itsWssum [private]

Definition at line 187 of file StatAcc.h.

template<class T>
Double casa::StatAcc< T >::itsWsum [private]

Definition at line 186 of file StatAcc.h.

template<class T>
Double casa::StatAcc< T >::itsWtot [private]

     

Definition at line 185 of file StatAcc.h.


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