35 #ifndef OPENMS_MATH_STATISTICS_HISTOGRAM_H
36 #define OPENMS_MATH_STATISTICS_HISTOGRAM_H
63 template <
typename ValueType = UInt,
typename BinSizeType =
double>
96 Histogram(BinSizeType min, BinSizeType max, BinSizeType bin_size) :
114 bins_ = std::vector<ValueType>(1, 0);
141 return *(std::max_element(
bins_.begin(),
bins_.end()));
147 return *(std::min_element(
bins_.begin(),
bins_.end()));
169 if (index >=
bins_.size())
183 if (bin_index >=
bins_.size())
188 return (BinSizeType)(
min_ + ((BinSizeType)bin_index + 0.5) *
bin_size_);
208 Size inc(BinSizeType val, ValueType increment = 1)
211 bins_[bin_index] += increment;
220 void reset(BinSizeType min, BinSizeType max, BinSizeType bin_size)
266 if (&histogram ==
this)
return *
this;
291 for (
typename std::vector<ValueType>::iterator it =
bins_.begin(); it !=
bins_.end(); ++it)
293 *it = (ValueType)(multiplier * log((BinSizeType)(*it + 1.0f)));
314 if (val < min_ || val >
max_)
331 template <
typename ValueType,
typename BinSizeType>
332 std::ostream & operator<<(std::ostream & os, const Histogram<ValueType, BinSizeType> & hist)
334 for (
Size i = 0; i < hist.size(); ++i)
336 os << hist.centerOfBin(i) <<
"\t"<< hist[i] << std::endl;
345 #endif // OPENMS_MATH_STATISTICS_HISTOGRAM_H
Histogram()
default constructor
Definition: Histogram.h:75
Out of range exception.
Definition: Exception.h:320
Histogram(const Histogram &histogram)
copy constructor
Definition: Histogram.h:83
BinSizeType maxBound() const
returns the upper bound
Definition: Histogram.h:133
Histogram & operator=(const Histogram &histogram)
Assignment.
Definition: Histogram.h:264
Size inc(BinSizeType val, ValueType increment=1)
increases the bin corresponding to value val by increment
Definition: Histogram.h:208
std::vector< ValueType >::const_iterator ConstIterator
Non-mutable iterator of the bins.
Definition: Histogram.h:69
void reset(BinSizeType min, BinSizeType max, BinSizeType bin_size)
resets the histogram with the given range and bin size
Definition: Histogram.h:220
Int overflow exception.
Definition: Exception.h:255
ValueType maxValue() const
returns the highest value of all bins
Definition: Histogram.h:139
BinSizeType centerOfBin(Size bin_index) const
returns the center position of the bin with the index bin_index
Definition: Histogram.h:181
BinSizeType bin_size_
Bin size.
Definition: Histogram.h:303
bool operator!=(const Histogram &histogram) const
Inequality operator.
Definition: Histogram.h:258
Size size() const
returns the number of bins
Definition: Histogram.h:157
virtual ~Histogram()
destructor
Definition: Histogram.h:120
Representation of a histogram.
Definition: Histogram.h:64
Histogram(BinSizeType min, BinSizeType max, BinSizeType bin_size)
constructor with min, max and bin size
Definition: Histogram.h:96
ValueType binValue(BinSizeType val) const
returns the value of bin corresponding to the value val
Definition: Histogram.h:196
std::vector< ValueType > bins_
Vector of bins.
Definition: Histogram.h:305
BinSizeType minBound() const
returns the lower bound
Definition: Histogram.h:127
ConstIterator end() const
Non-mutable iterator pointing after the last bin.
Definition: Histogram.h:285
void applyLogTransformation(BinSizeType multiplier)
Transforms the bin values with f(x)=multiplier*log(x+1)
Definition: Histogram.h:289
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:121
ValueType minValue() const
returns the lowest value of all bins
Definition: Histogram.h:145
Size valToBin_(BinSizeType val) const
Returns the bin a given value belongs to.
Definition: Histogram.h:311
bool operator==(const Histogram &histogram) const
Equality operator.
Definition: Histogram.h:249
BinSizeType min_
Lower bound.
Definition: Histogram.h:299
BinSizeType binSize() const
returns the bin size
Definition: Histogram.h:151
ConstIterator begin() const
Non-mutable iterator pointing to the first bin.
Definition: Histogram.h:282
BinSizeType max_
Upper bound.
Definition: Histogram.h:301
ValueType operator[](Size index) const
returns the value of bin index
Definition: Histogram.h:167