yat  0.10.4pre
Public Member Functions | Related Functions
theplu::yat::statistics::Histogram Class Reference

Histograms provide a convenient way of presenting the distribution of a set of data. More...

#include </scratch/bob/jari/tmp/pristine/yat-0.10.x/yat/statistics/Histogram.h>

List of all members.

Public Member Functions

 Histogram (void)
 Histogram (std::istream &)
 The istream constructor.
 Histogram (const Histogram &)
 Histogram (const double xmin, const double xmax, const size_t n)
int add (const double x, const double weight=1.0)
 Add a data point to the histogram.
const AveragerWeightedaverager_all (void) const
 Average of all events presented to the histogram.
const AveragerWeightedaverager_histogram (void) const
 Average of events fitting within histogram.
size_t nof_bins (void) const
void normalize (bool choice=true)
 Normalizing the histogram.
double observation_value (const size_t k) const
void rescale (double factor)
void reset (void)
double spacing (void) const
double xmax (void) const
double xmin (void) const
double operator[] (size_t k) const
const Histogramoperator= (const Histogram &)
const Histogramoperator+= (const Histogram &rhs)
 Addition operator.

Related Functions

(Note that these are not member functions.)

template<typename ForwardIterator >
void add (Histogram &h, ForwardIterator first, ForwardIterator last)
std::ostream & operator<< (std::ostream &s, const Histogram &)

Detailed Description

Histograms provide a convenient way of presenting the distribution of a set of data.

A histogram consists of a set of bins which count the number of events falling into these bins. Currently only one dimensional histograms with uniformly spaced bins are supported.


Constructor & Destructor Documentation

theplu::yat::statistics::Histogram::Histogram ( void  )

The default constructor.

theplu::yat::statistics::Histogram::Histogram ( std::istream &  )

The istream constructor.

This constructor creates a Histogram from output (possibly) created with operator<<. Note that the output from operator<< does not contain all information required to restore the Histogram. The values of all bins are restored, but the averagers, averager_all(void) and averager_histogram(void), and more specifically the second moment (sum_xx) in the averagers cannot be restored due to lack of information in the output.

Since:
New in yat 0.7
theplu::yat::statistics::Histogram::Histogram ( const Histogram )

The copy constructor.

theplu::yat::statistics::Histogram::Histogram ( const double  xmin,
const double  xmax,
const size_t  n 
)

Construct a histogram object that covers $(xmin,xmax]$ with the bin spacing $(xmax-xmin)/n$.


Member Function Documentation

int theplu::yat::statistics::Histogram::add ( const double  x,
const double  weight = 1.0 
)

Add a data point to the histogram.

Update the histogram by adding weight to the bin whose range contains the observation x. No bins are updated when x lies outside the range of the histogram but the value is added to the overall integral of the histogram.

Returns:
0 if x lies within the range of the histogram, -1 if x is smaller than the lower limit of the histogram, and similarly, 1 is returned if x is greater than or equal to the upper limit.
const AveragerWeighted& theplu::yat::statistics::Histogram::averager_all ( void  ) const

Average of all events presented to the histogram.

Gives access to the AveragerWeighted object that keeps track of average of all events presented to the histogram.

Returns:
A const reference to an AveragerWeighted object.
const AveragerWeighted& theplu::yat::statistics::Histogram::averager_histogram ( void  ) const

Average of events fitting within histogram.

Gives access to the AveragerWeighted object that keeps track of average of events that fits within the histogram lower and upper limits. This function is equivalent to averager().

Returns:
A const reference to an AveragerWeighted object.
size_t theplu::yat::statistics::Histogram::nof_bins ( void  ) const
Returns:
The number of bins in the histogram
void theplu::yat::statistics::Histogram::normalize ( bool  choice = true)

Normalizing the histogram.

There are two ways to normalize the counts.

If choice is true: The normalized count is the count in a bin divided by the total number of observations. In this case the relative counts are normalized to sum to unity ( minus values outside histogram). This is the intuitive case where the height of the histogram bar represents the proportion of the data in each class.

If choice is false: The normalized count is the count in the class divided by the number of observations times the bin width. For this normalization, the area (or integral) under the histogram is equal to unity (minus the missing area corresponding to counts outside histogram). From a probabilistic point of view, this normalization results in a relative histogram that is most akin to the probability density function If you want to overlay a probability density on top of the histogram, use this normalization. Although this normalization is less intuitive (relative frequencies greater than 1 are quite permissible), it is the appropriate normalization if you are using the histogram to model a probability density function.

double theplu::yat::statistics::Histogram::observation_value ( const size_t  k) const
Returns:
The value in the middle of bin k.
Note:
No check is done that k is within the size of the histogram.
const Histogram& theplu::yat::statistics::Histogram::operator+= ( const Histogram rhs)

Addition operator.

Note:
The bins in lhs and rhs must match, i.e., min, max, and nof_bins() must be equal in lhs and rhs.
Since:
New in yat 0.6
const Histogram& theplu::yat::statistics::Histogram::operator= ( const Histogram )

The assignment operator

double theplu::yat::statistics::Histogram::operator[] ( size_t  k) const
Returns:
The count of bin k in the histogram.
void theplu::yat::statistics::Histogram::rescale ( double  factor)

multiply value of each bin with factor

Since:
New in yat 0.6
void theplu::yat::statistics::Histogram::reset ( void  )

Set everyting to default values, here it means that everything is set to zero except the boundary values that are kept.

double theplu::yat::statistics::Histogram::spacing ( void  ) const
Returns:
The width of the bins in the histogram.
double theplu::yat::statistics::Histogram::xmax ( void  ) const
Returns:
The histogram upper boundary.
Note:
The upper boundary value is outside the histogram.
double theplu::yat::statistics::Histogram::xmin ( void  ) const
Returns:
The histogram lower boundary.
Note:
The lower boundary value is inside the histogram.

Friends And Related Function Documentation

template<typename ForwardIterator >
void add ( Histogram h,
ForwardIterator  first,
ForwardIterator  last 
)
related

Add a range [first, last) of values to Histogram.

ForwardIterator should be a Data Iterator

std::ostream & operator<< ( std::ostream &  s,
const Histogram  
)
related

The Histogram output operator


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

Generated on Mon Nov 11 2013 09:41:45 for yat by  doxygen 1.8.1