23#ifndef VCL_MATH_HISTOGRAM_H
24#define VCL_MATH_HISTOGRAM_H
26#include <vclib/types.h>
44template<
typename ScalarType>
47 std::vector<ScalarType> mHist;
48 std::vector<ScalarType> mRanges;
50 ScalarType mMinRange = 0;
51 ScalarType mMaxRange = 1;
53 ScalarType mMin = std::numeric_limits<ScalarType>::max();
54 ScalarType mMax = std::numeric_limits<ScalarType>::lowest();
80 ScalarType
gamma = 1.0) :
84 mHist.resize(
nBins + 2, 0);
86 mRanges.resize(
nBins + 3);
88 mRanges[0] = -std::numeric_limits<ScalarType>::max();
89 mRanges[
nBins + 2] = std::numeric_limits<ScalarType>::max();
91 double delta = (mMaxRange - mMinRange);
94 mRanges[
i + 1] = mMinRange +
delta * ScalarType(
i) /
nBins;
116 mMin = std::numeric_limits<ScalarType>::max();
117 mMax = std::numeric_limits<ScalarType>::lowest();
183 return *(std::max_element(mHist.begin(), mHist.end()));
193 return *(std::max_element(mHist.begin() + 1, mHist.end() - 1));
202 ScalarType binCount(uint
ind)
const {
return mHist[
ind]; }
204 ScalarType binLowerBound(uint ind)
const {
return mRanges[ind]; }
206 ScalarType binUpperBound(uint ind)
const {
return mRanges[ind + 1]; }
208 ScalarType binOfValueCount(ScalarType value)
const
213 ScalarType binOfValueCount(ScalarType value, ScalarType width)
const
215 return rangeCount(value - width / 2.0, value + width / 2.0);
218 ScalarType binOfValueWidth(ScalarType value)
220 uint pos = BinIndex(value);
221 return mRanges[pos + 1] - mRanges[pos];
224 ScalarType rangeCount(ScalarType rangeMin, ScalarType rangeMax)
const
230 for (uint i = firstBin; i <= lastBin; ++i)
244 if (mHist.size() == 0)
250 ScalarType sum = mCnt *
frac;
259 return mRanges[
i + 1];
266 ScalarType
average()
const {
return mSum / mCnt; }
299 auto it = std::lower_bound(mRanges.begin(), mRanges.end(),
elem);
315using Histogramf = Histogram<float>;
316using Histogramd = Histogram<double>;
The Histogram class allows to collect a set of values and then compute some statistics like average,...
Definition histogram.h:46
ScalarType percentile(ScalarType frac) const
Returns the value corresponding to a given percentile of the data.
Definition histogram.h:242
ScalarType numberValues() const
Number of values inserted in the histogram.
Definition histogram.h:162
ScalarType sumValues() const
Total sum of inserted values.
Definition histogram.h:156
ScalarType rootMeanSquare() const
Returns the Root Mean Square of the data.
Definition histogram.h:272
ScalarType minRangeValue() const
Minimum value of the range where the histogram is defined.
Definition histogram.h:144
ScalarType maxBinCountInRange() const
Max number of values among all bins between the minRangeValue and maxRangeValue.
Definition histogram.h:191
ScalarType variance() const
Returns the variance of the data.
Definition histogram.h:278
uint binsNumber() const
Number of intervals in the histogram.
Definition histogram.h:200
ScalarType maxRangeValue() const
Maximum value of the range where the histogram is defined.
Definition histogram.h:150
ScalarType maxBinCount() const
Max number of values among all bins (including the two infinity bounded bins)
Definition histogram.h:181
void addValue(ScalarType value, ScalarType increment=1.0)
Add a new value to the histogram.
Definition histogram.h:126
ScalarType minValue() const
Minimum value that has been added to the histogram.
Definition histogram.h:168
Histogram(ScalarType minRangeValue, ScalarType maxRangeValue, uint nBins, ScalarType gamma=1.0)
Set the histogram values.
Definition histogram.h:76
void clear()
Clears the histogram.
Definition histogram.h:106
ScalarType standardDeviation() const
Returns the standard deviation of the data.
Definition histogram.h:287
ScalarType average() const
Returns the average of the data.
Definition histogram.h:266
uint binIndex(ScalarType elem) const
Returns the index of the bin which contains a given element.
Definition histogram.h:293
ScalarType maxValue() const
Maximum value that has been added to the histogram.
Definition histogram.h:174
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43