small changes to the histogram interface to allow the use of weighted histograms

This commit is contained in:
Paolo Cignoni 2010-09-21 22:33:37 +00:00
parent 349e9869cf
commit af5e0eb46b
1 changed files with 8 additions and 8 deletions

View File

@ -189,7 +189,7 @@ class Histogram
// public data members // public data members
protected: protected:
std::vector <int> H; //! Counters for bins. std::vector <ScalarType> H; //! Counters for bins.
std::vector <ScalarType> R; //! Range for bins. std::vector <ScalarType> R; //! Range for bins.
ScalarType minv; //! Minimum value. ScalarType minv; //! Minimum value.
ScalarType maxv; //! Maximum value. ScalarType maxv; //! Maximum value.
@ -197,7 +197,7 @@ protected:
/// incrementally updated values /// incrementally updated values
int cnt; //! Number of accumulated samples. ScalarType cnt; //! Number of accumulated samples.
ScalarType avg; //! Average. ScalarType avg; //! Average.
ScalarType rms; //! Root mean square. ScalarType rms; //! Root mean square.
@ -232,7 +232,7 @@ public:
* The statistics related to the histogram data (average, RMS, etc.) are * The statistics related to the histogram data (average, RMS, etc.) are
* also updated. * also updated.
*/ */
void Add(ScalarType v); void Add(ScalarType v, ScalarType increment=ScalarType(1.0));
int MaxCount() const; int MaxCount() const;
int BinNum() const {return n;}; int BinNum() const {return n;};
@ -358,15 +358,15 @@ asking for 4 lower bound will return an iterator pointing to R[3]==4; and wil
*/ */
template <class ScalarType> template <class ScalarType>
void Histogram<ScalarType>::Add(ScalarType v) void Histogram<ScalarType>::Add(ScalarType v, ScalarType increment)
{ {
int pos=BinIndex(v); int pos=BinIndex(v);
if(pos>=0 && pos<=n) if(pos>=0 && pos<=n)
{ {
++H[pos]; H[pos]+=increment;
++cnt; cnt+=increment;
avg+=v; avg+=v*increment;
rms += v*v; rms += (v*v)*increment;
} }
} }