All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Nimble::Histogram< T, N > Class Template Reference

Histogram calculation. More...

#include <Nimble/Histogram.hpp>

Public Member Functions

void add (const Histogram &that)
 Add the values from another histogram to this histogram.
 
void clear ()
 Sets all histogram bins to zero.
 
int count () const
 Returns the sum of all bin counts.
 
int getHighValueFixed (int need) const
 Find the bin above which there are required number of samples. More...
 
int getHighValueRelative (float ratio) const
 Find the bin above which there are required number of samples. More...
 
int getLowValueFixed (int need) const
 Find the bin below which there are required number of samples. More...
 
int getLowValueRelative (float ratio) const
 Find the bin below which there are required number of samples. More...
 
int highestNonEmpty () const
 Returns the highest bin that is not empty. More...
 
 Histogram ()
 Constructs an empty histogram object. More...
 
int largestBin () const
 Returns the bin with the largest number of hits.
 
int lowestNonEmpty () const
 Returns the lowest bin that is not empty. More...
 
T & operator[] (int i)
 Returns a reference to a given bin.
 
const T & operator[] (int i) const
 Returns a const reference to a given bin.
 
void put (int index)
 Adds the histogram bin "index" by one.
 
void putSafe (int index)
 Adds the histogram bin "index" by one. More...
 
void putSafest (int index)
 Adds the histogram bin by one. More...
 
size_t size () const
 Returns the number of bins in the histogram. More...
 
sumBins (int bottom, int top) const
 Returns the sum of all bins in the given range.
 

Detailed Description

template<class T, int N>
class Nimble::Histogram< T, N >

Histogram calculation.

This class can be used to calculate histograms of all kinds of values.

Typical use pattern is as follows:

Histogram<unsigned int,256> hist;
hist.clear();
for(...)
hist.put(myFunction());
unsigned median = hist.getLowValueRelative(0.5);
Author
Tommi Ilmonen

Constructor & Destructor Documentation

template<class T , int N>
Nimble::Histogram< T, N >::Histogram ( )
inline

Constructs an empty histogram object.

The histogram is needs to be cleared before use, by calling clear().

Member Function Documentation

template<class T , int N>
int Nimble::Histogram< T, N >::getHighValueFixed ( int  need) const
inline

Find the bin above which there are required number of samples.

Parameters
needrequired sum of bins (0-count()).
Returns
the asked histogram bin, between 0 and N-1.
template<class T , int N>
int Nimble::Histogram< T, N >::getHighValueRelative ( float  ratio) const
inline

Find the bin above which there are required number of samples.

Parameters
ratiorelative ratio for selection (0-1).
Returns
the asked histogram bin, between 0 and N-1.
template<class T , int N>
int Nimble::Histogram< T, N >::getLowValueFixed ( int  need) const
inline

Find the bin below which there are required number of samples.

Parameters
needrequired sum of bins (0-count()).
Returns
the asked histogram bin, between 0 and N-1.
template<class T , int N>
int Nimble::Histogram< T, N >::getLowValueRelative ( float  ratio) const
inline

Find the bin below which there are required number of samples.

Parameters
ratiorelative ratio for selection (0-1).
Returns
the asked histogram bin, between 0 and N-1.
template<class T , int N>
int Nimble::Histogram< T, N >::highestNonEmpty ( ) const
inline

Returns the highest bin that is not empty.

See Also
lowestNonEmpty()
Returns
highest non-empty bin, between 0 and N-1.
template<class T , int N>
int Nimble::Histogram< T, N >::lowestNonEmpty ( ) const
inline

Returns the lowest bin that is not empty.

Returns
lowest non-empty bin, between 0 and N-1.
Histogram<int, 256> hist;
hist.put(134);
hist.put(254);
hist.put(3);
int low = hist.lowestNonEmpty(); // returns 3.
template<class T , int N>
void Nimble::Histogram< T, N >::putSafe ( int  index)
inline

Adds the histogram bin "index" by one.

It is ok to exceed the array towards top - i.e. index exceeds
  the histogram bin count.
Parameters
indexbin index
template<class T , int N>
void Nimble::Histogram< T, N >::putSafest ( int  index)
inline

Adds the histogram bin by one.

It is ok to exceed the array towards any direction.

Parameters
indexbin index
template<class T , int N>
size_t Nimble::Histogram< T, N >::size ( ) const
inline

Returns the number of bins in the histogram.

Returns
number of bins in the histogram