From 6c1fdb30664ba666264bd9c965e56fee312cee03 Mon Sep 17 00:00:00 2001 From: ponchio Date: Tue, 7 Jun 2005 09:37:33 +0000 Subject: [PATCH] Added fabs() to variance, which can sometime be negative in case of rounding errors (and sqrt chokes on it). --- vcg/math/histogram.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vcg/math/histogram.h b/vcg/math/histogram.h index 8a6d9b65..f3339d0a 100644 --- a/vcg/math/histogram.h +++ b/vcg/math/histogram.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.5 2005/06/07 07:44:08 cignoni +Added Percentile and removed small bug in Add + Revision 1.4 2005/04/04 10:48:35 cignoni Added missing functions Avg, rms etc, now fully (almost) functional @@ -68,7 +71,7 @@ public: ScalarType Percentile(ScalarType frac) const; ScalarType Avg() { return avg/cnt; } ScalarType RMS() { return sqrt(rms/double(cnt));} - ScalarType Variance() { return rms/cnt-Avg()*Avg(); } + ScalarType Variance() { return fabs(rms/cnt-Avg()*Avg()); } ScalarType StandardDeviation() { return sqrt(Variance()); } void FileWrite(const std::string &filename); @@ -149,8 +152,10 @@ ScalarType Histogram::Percentile(ScalarType frac) const assert(frac>=0 && frac<=1); ScalarType sum=0,partsum=0; int isum=0,ipartsum=0; - for(int i=0;i