casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::HistAcc< T > Class Template Reference

Makes a histogram from input values. More...

#include <HistAcc.h>

Public Member Functions

 HistAcc (const uInt nBuff)
 Constructors and destructor. More...
 
 HistAcc (const uInt nBuff, const T width)
 
 HistAcc (const T low, const T high, const T width)
 
 HistAcc (const HistAcc &)
 
 ~HistAcc ()
 
void copy (const HistAcc &)
 Copy operations. More...
 
HistAccoperator= (const HistAcc &)
 
void put (const T v)
 Accumulate (put) value(s) into the histogram. More...
 
void put (const Array< T > &vv)
 
void put (const Block< T > &vv)
 
void reset ()
 Reset the contents of the bins to zero, but retain the current bin definition. More...
 
void emptyBinsWithLessThan (const uInt nmin)
 Empty all bins whose contents is < nmin (e.g. More...
 
Fallible< T > getPercentile (const Float p)
 The median is the 50-percentile (getPercentile(50)), i.e. More...
 
Fallible< T > getMedian ()
 
Fallible< T > getBinWidth () const
 All bins have the same width. More...
 
const StatAcc< T > & getStatistics ()
 Get the internal Statistics accumulator (see StatAcc,h). More...
 
Fallible< uIntgetHistogram (Block< uInt > &bins, Block< T > &values)
 The return value is the nr of histogram bins, and is invalid if the number is zero. More...
 
uInt getSpurious (uInt &tooSmall, uInt &tooLarge)
 Get the nr of `spurious' values, i.e. More...
 
void printHistogram (ostream &, const String &caption)
 Print histogram. More...
 

Private Member Functions

void put1 (const T)
 Accumulate a single value into the histogram. More...
 
void defineBins (const T low, const T high, const T width)
 Definition of histogram bins with given parameters. More...
 
void initBuffer (const uInt size)
 Internal helper functions for the automatic definition of histogram parameters, using the contents of itsBuffer. More...
 
void putBuffer (const T v)
 
void clearBuffer ()
 
void autoDefineBins ()
 
void init ()
 Other internal helper function(s). More...
 
Fallible< T > getBinValue (const uInt index) const
 

Private Attributes

Block< uIntitsBinContents
 
Block< T > itsBinHighLimit
 
itsUserDefinedBinWidth
 
StatAcc< T > itsStatAcc
 
Bool itsAutoDefineMode
 
Block< T > itsBuffer
 
uInt itsBufferContents
 

Detailed Description

template<class T>
class casacore::HistAcc< T >

Makes a histogram from input values.

Review Status

Test programs:
tHistAcc

Prerequisite

Etymology

HistAcc stands for `Histogram Accumulator'.

Template Type Argument Requirements (T)

Synopsis

Makes a histogram from input values. The histogram bin parameters may be defined, or determined from the first n input values. The input values are fed to HistAcc via the member function `put'. They can be fed individually, or in the form of an Array.

The histogram `bins' can be defined via the constructor in the form of loop variables: low bin, high bin, bin-width. It is also possible to let the bin parameters be determined automatically from the first n (e.g. n=50) input values. If the actual nr of input values is less than n when the histogram is interrogated in some way, the bin parameters will be determined from what is available.

Example

It is usually convenient to let the bins be defined automatically:

Matrix<T> vv(30,100); // an array of input values
vv =... // fill the array
HistAcc<T> h(25); // use the first 25 values to define bins
h.put(vv); // accumulate values into histogram
h.printHistogram(cout,"vv"); // print the histogram of vv
Fallible<Double> median = h1.getMedian(); // return the median

In some cases the bin parameters are pre-defined:

Vector<T> vv(100,0); // a vector (array) of values
vv =... // fill the vector
HistAcc<T> h(-10,20,3); // bins with width 3, between -10 and 20
h.put(vv); // accumulate values into histogram
uInt n = h.getSpurious(l,h);// get the number outside the bins

The internal statistics accumulator can be interrogated explicitly or implicitly:

StatAcc<T> s = h.getStatistics(); // return the internal StatAcc
Fallible<Double> mean = s.getMean(); // get the mean of the input values
Fallible<Double> mean = h.getStatistics().getMean(); // alternative

Motivation

Definition at line 118 of file HistAcc.h.

Constructor & Destructor Documentation

template<class T >
casacore::HistAcc< T >::HistAcc ( const uInt  nBuff)

Constructors and destructor.

If the bin-parameters low, high and width (for lowest and highest bin, and binwidth) are not specified, they will be determined automatically from the first nBuff input values (which are stored in a temporary buffer).

template<class T >
casacore::HistAcc< T >::HistAcc ( const uInt  nBuff,
const T  width 
)
template<class T >
casacore::HistAcc< T >::HistAcc ( const T  low,
const T  high,
const T  width 
)
template<class T >
casacore::HistAcc< T >::HistAcc ( const HistAcc< T > &  )
template<class T >
casacore::HistAcc< T >::~HistAcc ( )
inline

Definition at line 129 of file HistAcc.h.

Member Function Documentation

template<class T >
void casacore::HistAcc< T >::autoDefineBins ( )
private
template<class T >
void casacore::HistAcc< T >::clearBuffer ( )
private
template<class T >
void casacore::HistAcc< T >::copy ( const HistAcc< T > &  )

Copy operations.

template<class T >
void casacore::HistAcc< T >::defineBins ( const T  low,
const T  high,
const T  width 
)
private

Definition of histogram bins with given parameters.

template<class T >
void casacore::HistAcc< T >::emptyBinsWithLessThan ( const uInt  nmin)

Empty all bins whose contents is < nmin (e.g.

nmin=2). This is useful to remove `noise' values from the histogram.

template<class T >
Fallible<T> casacore::HistAcc< T >::getBinValue ( const uInt  index) const
private
template<class T >
Fallible<T> casacore::HistAcc< T >::getBinWidth ( ) const

All bins have the same width.

template<class T >
Fallible<uInt> casacore::HistAcc< T >::getHistogram ( Block< uInt > &  bins,
Block< T > &  values 
)

The return value is the nr of histogram bins, and is invalid if the number is zero.

The given blocks/vectors are resized, and contain the contents and centre values of the bins.

template<class T >
Fallible<T> casacore::HistAcc< T >::getMedian ( )
template<class T >
Fallible<T> casacore::HistAcc< T >::getPercentile ( const Float  p)

The median is the 50-percentile (getPercentile(50)), i.e.

the value which has 50 percent of the input values below it. Calculation takes into account the spurious input values, i.e. values that fell outside the bins.

template<class T >
uInt casacore::HistAcc< T >::getSpurious ( uInt tooSmall,
uInt tooLarge 
)

Get the nr of `spurious' values, i.e.

the ones that fell outside the defined bins.

template<class T >
const StatAcc<T>& casacore::HistAcc< T >::getStatistics ( )

Get the internal Statistics accumulator (see StatAcc,h).

It can be used to obtain statistics of the input values.

template<class T >
void casacore::HistAcc< T >::init ( )
private

Other internal helper function(s).

template<class T >
void casacore::HistAcc< T >::initBuffer ( const uInt  size)
private

Internal helper functions for the automatic definition of histogram parameters, using the contents of itsBuffer.

template<class T >
HistAcc& casacore::HistAcc< T >::operator= ( const HistAcc< T > &  )
template<class T >
void casacore::HistAcc< T >::printHistogram ( ostream &  ,
const String caption 
)

Print histogram.

template<class T >
void casacore::HistAcc< T >::put ( const T  v)
inline

Accumulate (put) value(s) into the histogram.

Definition at line 223 of file HistAcc.h.

template<class T >
void casacore::HistAcc< T >::put ( const Array< T > &  vv)
template<class T >
void casacore::HistAcc< T >::put ( const Block< T > &  vv)
template<class T >
void casacore::HistAcc< T >::put1 ( const T  )
private

Accumulate a single value into the histogram.

template<class T >
void casacore::HistAcc< T >::putBuffer ( const T  v)
private
template<class T >
void casacore::HistAcc< T >::reset ( )

Reset the contents of the bins to zero, but retain the current bin definition.

Member Data Documentation

template<class T >
Bool casacore::HistAcc< T >::itsAutoDefineMode
private

Definition at line 188 of file HistAcc.h.

template<class T >
Block<uInt> casacore::HistAcc< T >::itsBinContents
private

Definition at line 182 of file HistAcc.h.

template<class T >
Block<T> casacore::HistAcc< T >::itsBinHighLimit
private

Definition at line 183 of file HistAcc.h.

template<class T >
Block<T> casacore::HistAcc< T >::itsBuffer
private

Definition at line 189 of file HistAcc.h.

template<class T >
uInt casacore::HistAcc< T >::itsBufferContents
private

Definition at line 190 of file HistAcc.h.

template<class T >
StatAcc<T> casacore::HistAcc< T >::itsStatAcc
private

Definition at line 186 of file HistAcc.h.

template<class T >
T casacore::HistAcc< T >::itsUserDefinedBinWidth
private

Definition at line 184 of file HistAcc.h.


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