commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r791931 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/stat/descriptive/AggregateSummaryStatistics.java test/org/apache/commons/math/stat/descriptive/AggregateSummaryStatisticsTest.java
Date Tue, 07 Jul 2009 18:29:08 GMT
Author: psteitz
Date: Tue Jul  7 18:29:08 2009
New Revision: 791931

URL: http://svn.apache.org/viewvc?rev=791931&view=rev
Log:
Made long conversion conistent. Improved test coverage. JIRA: MATH-224.

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AggregateSummaryStatistics.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/AggregateSummaryStatisticsTest.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AggregateSummaryStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AggregateSummaryStatistics.java?rev=791931&r1=791930&r2=791931&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AggregateSummaryStatistics.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/AggregateSummaryStatistics.java
Tue Jul  7 18:29:08 2009
@@ -238,7 +238,7 @@
             }
             sum += current.getSum();
             final double oldN = n;
-            final long curN = current.getN();
+            final double curN = current.getN();
             n += curN;
             final double meanDiff = current.getMean() - mean;
             mean = sum / n;

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/AggregateSummaryStatisticsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/AggregateSummaryStatisticsTest.java?rev=791931&r1=791930&r2=791931&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/AggregateSummaryStatisticsTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/AggregateSummaryStatisticsTest.java
Tue Jul  7 18:29:08 2009
@@ -77,6 +77,15 @@
         assertEquals("Wrong aggregate sum", 42.0, aggregate.getSum());
     }
     
+    /**
+     * Test aggregate function by randomly generating a dataset of 10-100 values
+     * from [-100, 100], dividing it into 2-5 partitions, computing stats for each
+     * partition and comparing the result of aggregate(...) applied to the collection
+     * of per-partition SummaryStatistics with a single SummaryStatistics computed
+     * over the full sample.
+     * 
+     * @throws Exception
+     */
     public void testAggregate() throws Exception {
         
         // Generate a random sample and random partition
@@ -108,6 +117,64 @@
         assertEquals(totalStats.getSummary(), aggregatedStats, 10E-12);
     }
     
+    
+    public void testAggregateDegenerate() throws Exception {
+        double[] totalSample = {1, 2, 3, 4, 5};
+        double[][] subSamples = {{1}, {2}, {3}, {4}, {5}};
+        
+        // Compute combined stats directly
+        SummaryStatistics totalStats = new SummaryStatistics();
+        for (int i = 0; i < totalSample.length; i++) {
+            totalStats.addValue(totalSample[i]);
+        }
+        
+        // Now compute subsample stats individually and aggregate
+        SummaryStatistics[] subSampleStats = new SummaryStatistics[5];
+        for (int i = 0; i < 5; i++) {
+            subSampleStats[i] = new SummaryStatistics();
+        }
+        Collection<SummaryStatistics> aggregate = new ArrayList<SummaryStatistics>();
+        for (int i = 0; i < 5; i++) {
+            for (int j = 0; j < subSamples[i].length; j++) { 
+                subSampleStats[i].addValue(subSamples[i][j]);
+            }
+            aggregate.add(subSampleStats[i]);
+        }
+        
+        // Compare values
+        StatisticalSummaryValues aggregatedStats = AggregateSummaryStatistics.aggregate(aggregate);
+        assertEquals(totalStats.getSummary(), aggregatedStats, 10E-12);
+    }
+    
+    public void testAggregateSpecialValues() throws Exception {
+        double[] totalSample = {Double.POSITIVE_INFINITY, 2, 3, Double.NaN, 5};
+        double[][] subSamples = {{Double.POSITIVE_INFINITY, 2}, {3}, {Double.NaN}, {5}};
+        
+        // Compute combined stats directly
+        SummaryStatistics totalStats = new SummaryStatistics();
+        for (int i = 0; i < totalSample.length; i++) {
+            totalStats.addValue(totalSample[i]);
+        }
+        
+        // Now compute subsample stats individually and aggregate
+        SummaryStatistics[] subSampleStats = new SummaryStatistics[5];
+        for (int i = 0; i < 4; i++) {
+            subSampleStats[i] = new SummaryStatistics();
+        }
+        Collection<SummaryStatistics> aggregate = new ArrayList<SummaryStatistics>();
+        for (int i = 0; i < 4; i++) {
+            for (int j = 0; j < subSamples[i].length; j++) { 
+                subSampleStats[i].addValue(subSamples[i][j]);
+            }
+            aggregate.add(subSampleStats[i]);
+        }
+        
+        // Compare values
+        StatisticalSummaryValues aggregatedStats = AggregateSummaryStatistics.aggregate(aggregate);
+        assertEquals(totalStats.getSummary(), aggregatedStats, 10E-12);
+        
+    }
+    
     /**
      * Verifies that two StatisticalSummaryValues report the same values up
      * to delta, with NaNs, infinities returned in the same spots. For max, min, n, values



Mime
View raw message