You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2011/11/27 06:20:10 UTC

svn commit: r1206666 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java site/xdoc/changes.xml test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java

Author: psteitz
Date: Sun Nov 27 05:20:09 2011
New Revision: 1206666

URL: http://svn.apache.org/viewvc?rev=1206666&view=rev
Log:
Fixed errors in SummaryStatistics causing overriden statistics not to be updated if the supplied impls are commons-math classes.  JIRA: MATH-691.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java?rev=1206666&r1=1206665&r2=1206666&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java Sun Nov 27 05:20:09 2011
@@ -155,13 +155,13 @@ public class SummaryStatistics implement
         secondMoment.increment(value);
         // If mean, variance or geomean have been overridden,
         // need to increment these
-        if (!(meanImpl instanceof Mean)) {
+        if (meanImpl != mean) {
             meanImpl.increment(value);
         }
-        if (!(varianceImpl instanceof Variance)) {
+        if (varianceImpl != variance) {
             varianceImpl.increment(value);
         }
-        if (!(geoMeanImpl instanceof GeometricMean)) {
+        if (geoMeanImpl != geoMean) {
             geoMeanImpl.increment(value);
         }
         n++;

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1206666&r1=1206665&r2=1206666&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sun Nov 27 05:20:09 2011
@@ -52,6 +52,11 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="psteitz" type="fix" issue="MATH-691">
+        Fixed errors in SummaryStatistics addValue causing variance, mean, or
+        geometric mean statistics not to be updated if they have been overriden
+        using instances of commons-math supplied implementations.
+      </action>
       <action dev="psteitz" type="update" issue="MATH-694">
         Removed First, Third, Fourth moments from the public API.
         These internally used statistics have non-standard definitions.

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java?rev=1206666&r1=1206665&r2=1206666&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java Sun Nov 27 05:20:09 2011
@@ -18,7 +18,10 @@ package org.apache.commons.math.stat.des
 
 
 import org.apache.commons.math.TestUtils;
+
+import org.apache.commons.math.stat.descriptive.moment.GeometricMean;
 import org.apache.commons.math.stat.descriptive.moment.Mean;
+import org.apache.commons.math.stat.descriptive.moment.Variance;
 import org.apache.commons.math.stat.descriptive.summary.Sum;
 import org.apache.commons.math.util.FastMath;
 import org.junit.Assert;
@@ -305,4 +308,41 @@ public class SummaryStatisticsTest {
             // expected
         }
     }
+    
+    
+    /**
+     * JIRA: MATH-691
+     */
+    @Test
+    public void testOverrideVarianceWithMathClass() throws Exception {
+        double[] scores = {1, 2, 3, 4};
+        SummaryStatistics stats = new SummaryStatistics();
+        stats.setVarianceImpl(new Variance(false)); //use "population variance"
+        for(double i : scores) {
+          stats.addValue(i);
+        }
+        Assert.assertEquals((new Variance(false)).evaluate(scores),stats.getVariance(), 0); 
+    }
+    
+    @Test
+    public void testOverrideMeanWithMathClass() throws Exception {
+        double[] scores = {1, 2, 3, 4};
+        SummaryStatistics stats = new SummaryStatistics();
+        stats.setMeanImpl(new Mean()); 
+        for(double i : scores) {
+          stats.addValue(i);
+        }
+        Assert.assertEquals((new Mean()).evaluate(scores),stats.getMean(), 0); 
+    }
+    
+    @Test
+    public void testOverrideGeoMeanWithMathClass() throws Exception {
+        double[] scores = {1, 2, 3, 4};
+        SummaryStatistics stats = new SummaryStatistics();
+        stats.setGeoMeanImpl(new GeometricMean()); 
+        for(double i : scores) {
+          stats.addValue(i);
+        }
+        Assert.assertEquals((new GeometricMean()).evaluate(scores),stats.getGeometricMean(), 0); 
+    }
 }