OpenMS
Loading...
Searching...
No Matches
Histogram< ValueType, BinSizeType > Class Template Reference

Representation of a histogram. More...

#include <OpenMS/MATH/STATISTICS/Histogram.h>

Collaboration diagram for Histogram< ValueType, BinSizeType >:
[legend]

Public Types

typedef std::vector< ValueType >::const_iterator ConstIterator
 Non-mutable iterator of the bins.
 

Public Member Functions

Assignment and equality operators
bool operator== (const Histogram &histogram) const
 Equality operator.
 
bool operator!= (const Histogram &histogram) const
 Inequality operator.
 
Histogramoperator= (const Histogram &histogram)
 Assignment.
 

Iterators

BinSizeType min_
 Lower bound.
 
BinSizeType max_
 Upper bound.
 
BinSizeType bin_size_
 Bin size.
 
std::vector< ValueType > bins_
 Vector of bins.
 
ConstIterator begin () const
 Non-mutable iterator pointing to the first bin.
 
ConstIterator end () const
 Non-mutable iterator pointing after the last bin.
 
void applyLogTransformation (BinSizeType multiplier)
 Transforms the bin values with f(x)=multiplier*log(x+1)
 
Size valueToBin (BinSizeType val) const
 Returns the bin index a given value belongs to.
 
void initBins_ ()
 initialize the bins
 

Constructors and Destructors

 Histogram ()
 default constructor
 
 Histogram (const Histogram &histogram)
 copy constructor
 
 Histogram (BinSizeType min, BinSizeType max, BinSizeType bin_size)
 constructor with min, max (inclusive) and bin width
 
template<typename DataIterator >
 Histogram (DataIterator begin, DataIterator end, BinSizeType min, BinSizeType max, BinSizeType bin_size)
 constructor with data iterator and min, max, bin_size parameters
 
virtual ~Histogram ()
 destructor
 
BinSizeType minBound () const
 returns the lower bound (inclusive)
 
BinSizeType maxBound () const
 returns the upper bound (inclusive)
 
ValueType maxValue () const
 returns the bin with the highest count
 
ValueType minValue () const
 returns the bin with lowest count
 
BinSizeType binSize () const
 returns the bin size
 
Size size () const
 returns the number of bins
 
ValueType operator[] (Size index) const
 returns the value of bin index
 
BinSizeType centerOfBin (Size bin_index) const
 returns the center position of the bin with the index bin_index
 
BinSizeType rightBorderOfBin (Size bin_index) const
 returns the first value to the right side of the bin with the index bin_index, which is not part of this bin, i.e. open right side of the interval.
 
BinSizeType leftBorderOfBin (Size bin_index) const
 returns the leftmost value of the bin with the index bin_index, which is part of this bin, i.e. closed left side of the interval.
 
ValueType binValue (BinSizeType val) const
 returns the value of bin corresponding to the value val
 
Size inc (BinSizeType val, ValueType increment=1)
 increases the bin corresponding to value val by increment
 
Size incUntil (BinSizeType val, bool inclusive, ValueType increment=1)
 Increment all bins from to lowest(=first) bin up to (and including?) the bin for val by a certain number of counts.
 
Size incFrom (BinSizeType val, bool inclusive, ValueType increment=1)
 Increment all bins from the bin of val to the highest(=last) bin by a certain number of counts.
 
void reset (BinSizeType min, BinSizeType max, BinSizeType bin_size)
 resets the histogram with the given range and bin size
 
template<typename DataIterator >
static void getCumulativeHistogram (DataIterator begin, DataIterator end, bool complement, bool inclusive, Histogram< ValueType, BinSizeType > &histogram)
 

Detailed Description

template<typename ValueType = UInt, typename BinSizeType = double>
class OpenMS::Math::Histogram< ValueType, BinSizeType >

Representation of a histogram.

The first template argument gives the Type of the values that are stored in the bins. The second argument gives the type for the bin size and range.

Member Typedef Documentation

◆ ConstIterator

template<typename ValueType = UInt, typename BinSizeType = double>
typedef std::vector<ValueType>::const_iterator ConstIterator

Non-mutable iterator of the bins.

Constructor & Destructor Documentation

◆ Histogram() [1/4]

template<typename ValueType = UInt, typename BinSizeType = double>
Histogram ( )
inline

default constructor

◆ Histogram() [2/4]

template<typename ValueType = UInt, typename BinSizeType = double>
Histogram ( const Histogram< ValueType, BinSizeType > &  histogram)
inline

copy constructor

◆ Histogram() [3/4]

template<typename ValueType = UInt, typename BinSizeType = double>
Histogram ( BinSizeType  min,
BinSizeType  max,
BinSizeType  bin_size 
)
inline

constructor with min, max (inclusive) and bin width

Exceptions
Exception::OutOfRangeis thrown if bin_size negative or zero

References Histogram< ValueType, BinSizeType >::initBins_().

◆ Histogram() [4/4]

template<typename ValueType = UInt, typename BinSizeType = double>
template<typename DataIterator >
Histogram ( DataIterator  begin,
DataIterator  end,
BinSizeType  min,
BinSizeType  max,
BinSizeType  bin_size 
)
inline

constructor with data iterator and min, max, bin_size parameters

Exceptions
Exception::OutOfRangeis thrown if bin_size negative or zero

References Histogram< ValueType, BinSizeType >::begin(), Histogram< ValueType, BinSizeType >::end(), Histogram< ValueType, BinSizeType >::inc(), and Histogram< ValueType, BinSizeType >::initBins_().

◆ ~Histogram()

template<typename ValueType = UInt, typename BinSizeType = double>
virtual ~Histogram ( )
inlinevirtual

destructor

Member Function Documentation

◆ applyLogTransformation()

template<typename ValueType = UInt, typename BinSizeType = double>
void applyLogTransformation ( BinSizeType  multiplier)
inline

Transforms the bin values with f(x)=multiplier*log(x+1)

References Histogram< ValueType, BinSizeType >::bins_.

◆ begin()

template<typename ValueType = UInt, typename BinSizeType = double>
ConstIterator begin ( ) const
inline

◆ binSize()

template<typename ValueType = UInt, typename BinSizeType = double>
BinSizeType binSize ( ) const
inline

returns the bin size

References Histogram< ValueType, BinSizeType >::bin_size_.

◆ binValue()

template<typename ValueType = UInt, typename BinSizeType = double>
ValueType binValue ( BinSizeType  val) const
inline

returns the value of bin corresponding to the value val

Exceptions
Exception::OutOfRangeis thrown if the value is out of valid range

References Histogram< ValueType, BinSizeType >::bins_, and Histogram< ValueType, BinSizeType >::valueToBin().

◆ centerOfBin()

template<typename ValueType = UInt, typename BinSizeType = double>
BinSizeType centerOfBin ( Size  bin_index) const
inline

returns the center position of the bin with the index bin_index

Exceptions
Exception::IndexOverflowis thrown for invalid indices

References Histogram< ValueType, BinSizeType >::bin_size_, Histogram< ValueType, BinSizeType >::bins_, and Histogram< ValueType, BinSizeType >::min_.

Referenced by OpenMS::Math::operator<<().

◆ end()

template<typename ValueType = UInt, typename BinSizeType = double>
ConstIterator end ( ) const
inline

◆ getCumulativeHistogram()

template<typename ValueType = UInt, typename BinSizeType = double>
template<typename DataIterator >
static void getCumulativeHistogram ( DataIterator  begin,
DataIterator  end,
bool  complement,
bool  inclusive,
Histogram< ValueType, BinSizeType > &  histogram 
)
inlinestatic

◆ inc()

template<typename ValueType = UInt, typename BinSizeType = double>
Size inc ( BinSizeType  val,
ValueType  increment = 1 
)
inline

increases the bin corresponding to value val by increment

Returns
The index of the increased bin.
Exceptions
Exception::OutOfRangeis thrown if the value is out of valid range

References Histogram< ValueType, BinSizeType >::bins_, and Histogram< ValueType, BinSizeType >::valueToBin().

Referenced by Histogram< ValueType, BinSizeType >::Histogram().

◆ incFrom()

template<typename ValueType = UInt, typename BinSizeType = double>
Size incFrom ( BinSizeType  val,
bool  inclusive,
ValueType  increment = 1 
)
inline

Increment all bins from the bin of val to the highest(=last) bin by a certain number of counts.

Parameters
[in]valThe value which determines the lowest bin
[in]inclusiveIs the lowest bin included?
[in]incrementIncrease each bin by this value
Returns
The index of the bin for value

References Histogram< ValueType, BinSizeType >::bins_, and Histogram< ValueType, BinSizeType >::valueToBin().

Referenced by Histogram< ValueType, BinSizeType >::getCumulativeHistogram().

◆ incUntil()

template<typename ValueType = UInt, typename BinSizeType = double>
Size incUntil ( BinSizeType  val,
bool  inclusive,
ValueType  increment = 1 
)
inline

Increment all bins from to lowest(=first) bin up to (and including?) the bin for val by a certain number of counts.

Parameters
[in]valThe value which determines the highest bin
[in]inclusiveIs the highest bin included?
[in]incrementIncrease each bin by this value
Returns
The index of the bin for value

References Histogram< ValueType, BinSizeType >::bins_, and Histogram< ValueType, BinSizeType >::valueToBin().

Referenced by Histogram< ValueType, BinSizeType >::getCumulativeHistogram().

◆ initBins_()

template<typename ValueType = UInt, typename BinSizeType = double>
void initBins_ ( )
inlineprotected

◆ leftBorderOfBin()

template<typename ValueType = UInt, typename BinSizeType = double>
BinSizeType leftBorderOfBin ( Size  bin_index) const
inline

returns the leftmost value of the bin with the index bin_index, which is part of this bin, i.e. closed left side of the interval.

Exceptions
Exception::IndexOverflowis thrown for invalid indices

References Histogram< ValueType, BinSizeType >::bin_size_, Histogram< ValueType, BinSizeType >::bins_, and Histogram< ValueType, BinSizeType >::min_.

◆ maxBound()

template<typename ValueType = UInt, typename BinSizeType = double>
BinSizeType maxBound ( ) const
inline

returns the upper bound (inclusive)

References Histogram< ValueType, BinSizeType >::max_.

Referenced by Histogram< ValueType, BinSizeType >::rightBorderOfBin().

◆ maxValue()

template<typename ValueType = UInt, typename BinSizeType = double>
ValueType maxValue ( ) const
inline

returns the bin with the highest count

References Histogram< ValueType, BinSizeType >::bins_.

◆ minBound()

template<typename ValueType = UInt, typename BinSizeType = double>
BinSizeType minBound ( ) const
inline

returns the lower bound (inclusive)

References Histogram< ValueType, BinSizeType >::min_.

◆ minValue()

template<typename ValueType = UInt, typename BinSizeType = double>
ValueType minValue ( ) const
inline

returns the bin with lowest count

References Histogram< ValueType, BinSizeType >::bins_.

◆ operator!=()

template<typename ValueType = UInt, typename BinSizeType = double>
bool operator!= ( const Histogram< ValueType, BinSizeType > &  histogram) const
inline

Inequality operator.

References Histogram< ValueType, BinSizeType >::operator==().

◆ operator=()

template<typename ValueType = UInt, typename BinSizeType = double>
Histogram & operator= ( const Histogram< ValueType, BinSizeType > &  histogram)
inline

◆ operator==()

template<typename ValueType = UInt, typename BinSizeType = double>
bool operator== ( const Histogram< ValueType, BinSizeType > &  histogram) const
inline

◆ operator[]()

template<typename ValueType = UInt, typename BinSizeType = double>
ValueType operator[] ( Size  index) const
inline

returns the value of bin index

Exceptions
Exception::IndexOverflowis thrown for invalid indices

References Histogram< ValueType, BinSizeType >::bins_.

◆ reset()

template<typename ValueType = UInt, typename BinSizeType = double>
void reset ( BinSizeType  min,
BinSizeType  max,
BinSizeType  bin_size 
)
inline

resets the histogram with the given range and bin size

Exceptions
Exception::OutOfRangeis thrown if bin_size negative or zero

References Histogram< ValueType, BinSizeType >::bin_size_, Histogram< ValueType, BinSizeType >::bins_, Histogram< ValueType, BinSizeType >::max_, and Histogram< ValueType, BinSizeType >::min_.

◆ rightBorderOfBin()

template<typename ValueType = UInt, typename BinSizeType = double>
BinSizeType rightBorderOfBin ( Size  bin_index) const
inline

returns the first value to the right side of the bin with the index bin_index, which is not part of this bin, i.e. open right side of the interval.

Exceptions
Exception::IndexOverflowis thrown for invalid indices

References Histogram< ValueType, BinSizeType >::bin_size_, Histogram< ValueType, BinSizeType >::bins_, Histogram< ValueType, BinSizeType >::maxBound(), and Histogram< ValueType, BinSizeType >::min_.

◆ size()

template<typename ValueType = UInt, typename BinSizeType = double>
Size size ( ) const
inline

returns the number of bins

References Histogram< ValueType, BinSizeType >::bins_.

Referenced by OpenMS::Math::operator<<().

◆ valueToBin()

template<typename ValueType = UInt, typename BinSizeType = double>
Size valueToBin ( BinSizeType  val) const
inline

Member Data Documentation

◆ bin_size_

◆ bins_

◆ max_

◆ min_