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) :
   110       template <
typename DataIterator>
   111       Histogram(DataIterator 
begin, DataIterator 
end, BinSizeType min, BinSizeType max, BinSizeType bin_size) :
   117         for (DataIterator it = begin; it != 
end; ++it)
   119           this->
inc((BinSizeType) *it);
   146         return *(std::max_element(
bins_.begin(), 
bins_.end()));
   152         return *(std::min_element(
bins_.begin(), 
bins_.end()));
   174         if (index >= 
bins_.size())
   188         if (bin_index >= 
bins_.size())
   193         return (BinSizeType)(
min_ + ((BinSizeType)bin_index + 0.5) * 
bin_size_);
   213       Size inc(BinSizeType val, ValueType increment = 1)
   216         this->
bins_[bin_index] += increment;
   221       Size incUntil(BinSizeType val, 
bool inclusive, ValueType increment = 1)
   224         for (
Size i = 0; i < bin_index; ++i)
   226          this->
bins_[i] += increment;
   230           this->
bins_[bin_index] += increment;
   235       Size incFrom(BinSizeType val, 
bool inclusive, ValueType increment = 1)
   238         for (
Size i = bin_index + 1; i < this->
bins_.size(); ++i)
   240           this->
bins_[i] += increment;
   244           this->
bins_[bin_index] += increment;
   249       template< 
typename DataIterator >
   255         for (DataIterator it = begin; it != 
end; ++it)
   263             histogram.
incFrom(*it, inclusive);
   274       void reset(BinSizeType min, BinSizeType max, BinSizeType bin_size)
   320         if (&histogram == 
this) 
return *
this;
   335       inline ConstIterator 
begin()
 const { 
return bins_.begin(); }
   339       inline ConstIterator 
end()
 const { 
return bins_.end(); }
   345         for (
typename std::vector<ValueType>::iterator it = 
bins_.begin(); it != 
bins_.end(); ++it)
   347           *it = (ValueType)(multiplier * log((BinSizeType)(*it + 1.0f)));
   368         if (val < min_ || val > max_)
   374           return Size(bins_.size() - 1);
   378           return (
Size) floor((val - min_) / (max_ - min_) * bins_.size());
   385         if (this->bin_size_ <= 0)
   392           if (this->max_ != this->min_)
   394             this->bins_ = std::vector<ValueType>(
Size(ceil((max_ - min_) / bin_size_)), 0);
   398             this->bins_ = std::vector<ValueType>(1, 0);
   405     template <
typename ValueType, 
typename BinSizeType>
   406     std::ostream & operator<<(std::ostream & os, const Histogram<ValueType, BinSizeType> & hist)
   408       for (
Size i = 0; i < hist.size(); ++i)
   410         os << hist.centerOfBin(i) << 
"\t"<< hist[i] << std::endl;
   419 #endif // OPENMS_MATH_STATISTICS_HISTOGRAM_H 
Histogram()
default constructor 
Definition: Histogram.h:75
 
Out of range exception. 
Definition: Exception.h:320
 
Size size() const
returns the number of bins 
Definition: Histogram.h:162
 
Histogram(const Histogram &histogram)
copy constructor 
Definition: Histogram.h:83
 
BinSizeType minBound() const
returns the lower bound 
Definition: Histogram.h:132
 
Histogram & operator=(const Histogram &histogram)
Assignment. 
Definition: Histogram.h:318
 
Size inc(BinSizeType val, ValueType increment=1)
increases the bin corresponding to value val by increment 
Definition: Histogram.h:213
 
BinSizeType binSize() const
returns the bin size 
Definition: Histogram.h:156
 
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:274
 
Int overflow exception. 
Definition: Exception.h:255
 
ValueType maxValue() const
returns the highest value of all bins 
Definition: Histogram.h:144
 
ValueType operator[](Size index) const
returns the value of bin index 
Definition: Histogram.h:172
 
bool operator!=(const Histogram &histogram) const
Inequality operator. 
Definition: Histogram.h:312
 
Main OpenMS namespace. 
Definition: FeatureDeconvolution.h:47
 
BinSizeType centerOfBin(Size bin_index) const
returns the center position of the bin with the index bin_index 
Definition: Histogram.h:186
 
ValueType minValue() const
returns the lowest value of all bins 
Definition: Histogram.h:150
 
ConstIterator end() const
Non-mutable iterator pointing after the last bin. 
Definition: Histogram.h:339
 
ValueType binValue(BinSizeType val) const
returns the value of bin corresponding to the value val 
Definition: Histogram.h:201
 
BinSizeType bin_size_
Bin size. 
Definition: Histogram.h:357
 
Size incFrom(BinSizeType val, bool inclusive, ValueType increment=1)
Definition: Histogram.h:235
 
virtual ~Histogram()
destructor 
Definition: Histogram.h:125
 
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
 
Size incUntil(BinSizeType val, bool inclusive, ValueType increment=1)
Definition: Histogram.h:221
 
std::vector< ValueType > bins_
Vector of bins. 
Definition: Histogram.h:359
 
static void getCumulativeHistogram(DataIterator begin, DataIterator end, bool complement, bool inclusive, Histogram< ValueType, BinSizeType > &histogram)
Definition: Histogram.h:250
 
bool operator==(const Histogram &histogram) const
Equality operator. 
Definition: Histogram.h:303
 
void applyLogTransformation(BinSizeType multiplier)
Transforms the bin values with f(x)=multiplier*log(x+1) 
Definition: Histogram.h:343
 
size_t Size
Size type e.g. used as variable which can hold result of size() 
Definition: Types.h:128
 
Size valToBin_(BinSizeType val) const
Returns the bin a given value belongs to. 
Definition: Histogram.h:365
 
void initBins_()
initialize the bins 
Definition: Histogram.h:383
 
BinSizeType maxBound() const
returns the upper bound 
Definition: Histogram.h:138
 
ConstIterator begin() const
Non-mutable iterator pointing to the first bin. 
Definition: Histogram.h:336
 
BinSizeType min_
Lower bound. 
Definition: Histogram.h:353
 
BinSizeType max_
Upper bound. 
Definition: Histogram.h:355
 
Histogram(DataIterator begin, DataIterator end, BinSizeType min, BinSizeType max, BinSizeType bin_size)
constructor with data iterator and min, max, bin_size parameters 
Definition: Histogram.h:111