|
[yoda-svn] r306 - in trunk: . include/YODA srcblackhole at projects.hepforge.org blackhole at projects.hepforge.orgMon Aug 22 10:11:09 BST 2011
Author: buckley Date: Mon Aug 22 10:11:09 2011 New Revision: 306 Log: Remove use of sign(weight) in filling sum(w2) -- I think this was an historical attempt based on a scaling axiom which turned out to be inappropriate. Also adding a LowStatsError throw for attempting to calculate the mean of an unfilled distribution. Modified: trunk/ChangeLog trunk/TODO trunk/include/YODA/Dbn1D.h trunk/src/Dbn1D.cc Modified: trunk/ChangeLog ============================================================================== --- trunk/ChangeLog Mon Aug 22 09:56:10 2011 (r305) +++ trunk/ChangeLog Mon Aug 22 10:11:09 2011 (r306) @@ -1,5 +1,9 @@ 2011-08-22 Andy Buckley <andy at insectnation.org> + * Remove use of sign(weight) in filling sum(w2) -- I think this + was an historical attempt based on a scaling axiom which turned + out to be inappropriate. + * Reworking the Bin1D inheritance and composition design so that all bin types store a single distribution object -- a Dbn1D for histo bins and a Dbn2D for profile bins. Modified: trunk/TODO ============================================================================== --- trunk/TODO Mon Aug 22 09:56:10 2011 (r305) +++ trunk/TODO Mon Aug 22 10:11:09 2011 (r306) @@ -15,8 +15,7 @@ * Rework Axis1D to operate as Axis2D does (MICHAL) -* Throw LowStatsError for errors and profile histo points with no fills -- any - explicit action needed? (AB) +* Template Bin2D and HistoBin2D on DBN type (Dbn2D/3D) cf. Bin1D<DBN> * Rebinning: global rebinning by integer factor(s) (AB for 1D, MICHAL for 2D) Different rebinning factors for X and Y in 2D. Implement for 1D first, Modified: trunk/include/YODA/Dbn1D.h ============================================================================== --- trunk/include/YODA/Dbn1D.h Mon Aug 22 09:56:10 2011 (r305) +++ trunk/include/YODA/Dbn1D.h Mon Aug 22 10:11:09 2011 (r306) @@ -34,7 +34,9 @@ reset(); } + /// @brief Constructor to set a distribution with a pre-filled state. + /// /// Principally designed for internal persistency use. Dbn1D(unsigned int numEntries, double sumW, double sumW2, double sumWX, double sumWX2) { _numFills = numEntries; @@ -57,6 +59,7 @@ /// @todo Be careful about negative weights. void fill(double val, double weight=1.0); + /// Reset the internal counters. void reset() { _numFills = 0; @@ -66,6 +69,7 @@ _sumWX2 = 0; } + /// Rescale as if all fill weights had been different by factor @a scalefactor. void scaleW(double scalefactor) { const double sf = scalefactor; @@ -76,6 +80,7 @@ _sumWX2 *= sf2; } + /// Rescale x: needed if histo bin edges are rescaled. void scaleX(double factor) { _sumWX *= factor; @@ -105,10 +110,7 @@ //@{ /// Weighted mean, \f$ \bar{x} \f$, of distribution. - double mean() const { - // This is ok, even for negative sum(w) - return _sumWX/_sumW; - } + double mean() const; /// Synonym for interface compatibility with Dbn2D double xMean() const { return mean(); } @@ -126,6 +128,7 @@ /// Synonym for interface compatibility with Dbn2D double xStdDev() const { return stdDev(); } + /// Weighted standard error on the mean, \f$ \sim \sigma/\sqrt{N-1} \f$, of distribution. double stdErr() const; /// Synonym for interface compatibility with Dbn2D Modified: trunk/src/Dbn1D.cc ============================================================================== --- trunk/src/Dbn1D.cc Mon Aug 22 09:56:10 2011 (r305) +++ trunk/src/Dbn1D.cc Mon Aug 22 10:11:09 2011 (r306) @@ -4,6 +4,7 @@ // Copyright (C) 2008-2011 The YODA collaboration (see AUTHORS for details) // #include "YODA/Dbn1D.h" +#include "YODA/Utils/MathUtils.h" namespace YODA { @@ -11,22 +12,29 @@ void Dbn1D::fill(double val, double weight) { _numFills += 1; _sumW += weight; - double w2 = weight*weight; - /// @todo Correct? - if (weight < 0) w2 *= -1; - _sumW2 += w2; + //const double w2 = sign(weight) * weight*weight; + _sumW2 += weight*weight; _sumWX += weight*val; _sumWX2 += weight*val*val; } + double Dbn1D::mean() const { + if (isZero(effNumEntries(), 0.0)) { + throw LowStatsError("Requested mean of a distribution with no net fill weights"); + } + // This is ok, even for negative sum(w) + return _sumWX/_sumW; + } + + double Dbn1D::variance() const { // Weighted variance defined as // sig2 = ( sum(wx**2) * sum(w) - sum(wx)**2 ) / ( sum(w)**2 - sum(w**2) ) // see http://en.wikipedia.org/wiki/Weighted_mean - if (effNumEntries() == 0.0) { + if (isZero(effNumEntries(), 0.0)) { throw LowStatsError("Requested width of a distribution with no net fill weights"); - } else if (effNumEntries() <= 1.0) { + } else if (fuzzyLessEquals(effNumEntries(), 1.0)) { throw LowStatsError("Requested width of a distribution with only one effective entry"); } const double num = _sumWX2*_sumW - _sumWX*_sumWX; @@ -64,7 +72,7 @@ Dbn1D& Dbn1D::subtract(const Dbn1D& d) { - _numFills += d._numFills; //< @todo Hmm, what's best?!? + _numFills += d._numFills; //< @todo Hmm, add or subtract?!? _sumW -= d._sumW; _sumW2 -= d._sumW2; _sumWX -= d._sumWX;
More information about the yoda-svn mailing list |