commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1208291 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java site/xdoc/changes.xml test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java
Date Wed, 30 Nov 2011 06:24:05 GMT
Author: psteitz
Date: Wed Nov 30 06:24:04 2011
New Revision: 1208291

URL: http://svn.apache.org/viewvc?rev=1208291&view=rev
Log:
Fixed array indexing error in Variance evaluate method for
computing the weighted variance of an array segment.

JIRA: MATH-704
Reported by Leonid Ilyevsky
Patched by Thomas Niedhart


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

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java?rev=1208291&r1=1208290&r2=1208291&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/moment/Variance.java
Wed Nov 30 06:24:04 2011
@@ -517,7 +517,7 @@ public class Variance extends AbstractSt
                 }
 
                 double sumWts = 0;
-                for (int i = 0; i < weights.length; i++) {
+                for (int i = begin; i < begin + length; i++) {
                     sumWts += weights[i];
                 }
 

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=1208291&r1=1208290&r2=1208291&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Wed Nov 30 06:24:04 2011
@@ -52,6 +52,10 @@ 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-704" due-to="Thomas Niedhart">
+        Fixed array indexing error in Variance evaluate method for
+        computing the weighted variance of an array segment.
+      </action>
       <action dev="luc" type="fix" issue="MATH-713" due-to="Thomas Neidhart">
         Fixed case of unconstrained variables that still occur in the objective function
         in simplex solver.
@@ -69,7 +73,7 @@ The <action> type attribute can be add,u
       </action>
       <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
+        geometric mean statistics not to be updated if they have been overridden
         using instances of commons-math supplied implementations.
       </action>
       <action dev="psteitz" type="update" issue="MATH-694">

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java?rev=1208291&r1=1208290&r2=1208291&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/UnivariateStatisticAbstractTest.java
Wed Nov 30 06:24:04 2011
@@ -113,6 +113,35 @@ public abstract class UnivariateStatisti
         System.arraycopy(testArray, testArray.length - 5, arrayEnd, 0, 5);
         Assert.assertEquals(stat.evaluate(arrayEnd), stat.evaluate(testArray, testArray.length
- 5, 5), 0);
     }
+    
+    @Test
+    public void testEvaluateArraySegmentWeighted() {
+        // See if this statistic computes weighted statistics
+        // If not, skip this test
+        UnivariateStatistic statistic = getUnivariateStatistic();
+        if (!(statistic instanceof WeightedEvaluation)) {
+            return;
+        }
+        final WeightedEvaluation stat = (WeightedEvaluation) getUnivariateStatistic();
+        final double[] arrayZero = new double[5];
+        final double[] weightZero = new double[5];
+        System.arraycopy(testArray, 0, arrayZero, 0, 5);
+        System.arraycopy(testWeightsArray, 0, weightZero, 0, 5);
+        Assert.assertEquals(stat.evaluate(arrayZero, weightZero),
+                stat.evaluate(testArray, testWeightsArray, 0, 5), 0);
+        final double[] arrayOne = new double[5];
+        final double[] weightOne = new double[5];
+        System.arraycopy(testArray, 5, arrayOne, 0, 5);
+        System.arraycopy(testWeightsArray, 5, weightOne, 0, 5);
+        Assert.assertEquals(stat.evaluate(arrayOne, weightOne),
+                stat.evaluate(testArray, testWeightsArray, 5, 5), 0);
+        final double[] arrayEnd = new double[5];
+        final double[] weightEnd = new double[5];
+        System.arraycopy(testArray, testArray.length - 5, arrayEnd, 0, 5);
+        System.arraycopy(testWeightsArray, testArray.length - 5, weightEnd, 0, 5);
+        Assert.assertEquals(stat.evaluate(arrayEnd, weightEnd),
+                stat.evaluate(testArray, testWeightsArray, testArray.length - 5, 5), 0);
+    }
 
     @Test
     public void testCopy() throws Exception {



Mime
View raw message