Package org.apache.commons.math.stat

Examples of org.apache.commons.math.stat.StorelessDescriptiveStatisticsImpl


        return suite;
    }
   
    /** test stats */
    public void testStats() {
        StorelessDescriptiveStatisticsImpl u = new StorelessDescriptiveStatisticsImpl();
        assertEquals("total count",0,u.getN(),tolerance);
        u.addValue(one);
        u.addValue(twoF);
        u.addValue(twoL);
        u.addValue(three);
        assertEquals("N",n,u.getN(),tolerance);
        assertEquals("sum",sum,u.getSum(),tolerance);
        assertEquals("sumsq",sumSq,u.getSumsq(),tolerance);
        assertEquals("var",var,u.getVariance(),tolerance);
        assertEquals("std",std,u.getStandardDeviation(),tolerance);
        assertEquals("mean",mean,u.getMean(),tolerance);
        assertEquals("min",min,u.getMin(),tolerance);
        assertEquals("max",max,u.getMax(),tolerance);
        u.clear();
        assertEquals("total count",0,u.getN(),tolerance);   
    }    
View Full Code Here


        u.clear();
        assertEquals("total count",0,u.getN(),tolerance);   
    }    
   
    public void testN0andN1Conditions() throws Exception {
      StorelessDescriptiveStatisticsImpl u = new StorelessDescriptiveStatisticsImpl();
        assertTrue("Mean of n = 0 set should be NaN",
            Double.isNaN( u.getMean() ) );
    assertTrue("Standard Deviation of n = 0 set should be NaN",
            Double.isNaN( u.getStandardDeviation() ) );
    assertTrue("Variance of n = 0 set should be NaN",
            Double.isNaN(u.getVariance() ) );
    assertTrue("skew of n = 0 set should be NaN",
      Double.isNaN(u.getSkewness() ) )
    assertTrue("kurtosis of n = 0 set should be NaN",
      Double.isNaN(u.getKurtosis() ) );   
   
 
    /* n=1 */
    u.addValue(one);
    assertTrue("mean should be one (n = 1)",
      u.getMean() == one);
    assertTrue("geometric should be one (n = 1) instead it is " + u.getGeometricMean(),
      u.getGeometricMean() == one);
    assertTrue("Std should be zero (n = 1)",
      u.getStandardDeviation() == 0.0);
    assertTrue("variance should be zero (n = 1)",
      u.getVariance() == 0.0);
    assertTrue("skew should be zero (n = 1)",
      u.getSkewness() == 0.0);
    assertTrue("kurtosis should be zero (n = 1)",
      u.getKurtosis() == 0.0);   
         
    /* n=2 */       
    u.addValue(twoF);
    assertTrue("Std should not be zero (n = 2)",
      u.getStandardDeviation() != 0.0);
    assertTrue("variance should not be zero (n = 2)",
      u.getVariance() != 0.0);
    assertTrue("skew should not be zero (n = 2)",
      u.getSkewness() == 0.0);
    assertTrue("kurtosis should be zero (n = 2)",
      u.getKurtosis() == 0.0);

    /* n=3 */
    u.addValue(twoL);
    assertTrue("skew should not be zero (n = 3)",
      u.getSkewness() != 0.0);
    assertTrue("kurtosis should be zero (n = 3)",
      u.getKurtosis() == 0.0);
       
    /* n=4 */
    u.addValue(three);
    assertTrue("kurtosis should not be zero (n = 4)",
      u.getKurtosis() != 0.0);       
           
    }
View Full Code Here

      u.getKurtosis() != 0.0);       
           
    }

    public void testProductAndGeometricMean() throws Exception {
      StorelessDescriptiveStatisticsImpl u = new StorelessDescriptiveStatisticsImpl(10);
           
        u.addValue( 1.0 );
        u.addValue( 2.0 );
        u.addValue( 3.0 );
        u.addValue( 4.0 );

        assertEquals( "Geometric mean not expected", 2.213364,
            u.getGeometricMean(), 0.00001 );

        // Now test rolling - StorelessDescriptiveStatistics should discount the contribution
        // of a discarded element
        for( int i = 0; i < 10; i++ ) {
            u.addValue( i + 2 );
        }
        // Values should be (2,3,4,5,6,7,8,9,10,11)
       
        assertEquals( "Geometric mean not expected", 5.755931,
            u.getGeometricMean(), 0.00001 );
    }
View Full Code Here

        assertEquals( "Geometric mean not expected", 5.755931,
            u.getGeometricMean(), 0.00001 );
    }
   
    public void testRollingMinMax() {
        StorelessDescriptiveStatisticsImpl u = new StorelessDescriptiveStatisticsImpl(3);
        u.addValue( 1.0 );
        u.addValue( 5.0 );
        u.addValue( 3.0 );
        u.addValue( 4.0 ); // discarding min
        assertEquals( "min not expected", 3.0,
            u.getMin(), Double.MIN_VALUE);
        u.addValue(1.0)// discarding max
        assertEquals( "max not expected", 4.0,
            u.getMax(), Double.MIN_VALUE);
    }
View Full Code Here

        assertEquals( "max not expected", 4.0,
            u.getMax(), Double.MIN_VALUE);
    }
   
    public void testNaNContracts() {
        StorelessDescriptiveStatisticsImpl u = new StorelessDescriptiveStatisticsImpl();
        double nan = Double.NaN;
        assertTrue("mean not NaN",Double.isNaN(u.getMean()));
        assertTrue("min not NaN",Double.isNaN(u.getMin()));
        assertTrue("std dev not NaN",Double.isNaN(u.getStandardDeviation()));
        assertTrue("var not NaN",Double.isNaN(u.getVariance()));
        assertTrue("geom mean not NaN",Double.isNaN(u.getGeometricMean()));
       
        u.addValue(1.0);
       
        assertEquals( "mean not expected", 1.0,
            u.getMean(), Double.MIN_VALUE);
        assertEquals( "variance not expected", 0.0,
            u.getVariance(), Double.MIN_VALUE);
        assertEquals( "geometric mean not expected", 1.0,
            u.getGeometricMean(), Double.MIN_VALUE);
       
        u.addValue(-1.0);
       
        assertTrue("geom mean not NaN",Double.isNaN(u.getGeometricMean()));
       
        u.addValue(0.0);
       
        assertTrue("geom mean not NaN",Double.isNaN(u.getGeometricMean()));
       
        //FiXME: test all other NaN contract specs
    }
View Full Code Here

       
        //FiXME: test all other NaN contract specs
    }

    public void testSkewAndKurtosis() {
        DescriptiveStatistics u = new StorelessDescriptiveStatisticsImpl();
       
        double[] testArray =
        { 12.5, 12, 11.8, 14.2, 14.9, 14.5, 21, 8.2, 10.3, 11.3, 14.1,
          9.9, 12.2, 12, 12.1, 11, 19.8, 11, 10, 8.8, 9, 12.3 };
        for( int i = 0; i < testArray.length; i++) {
            u.addValue( testArray[i]);
        }
       
        assertEquals("mean", 12.40455, u.getMean(), 0.0001);
        assertEquals("variance", 10.00236, u.getVariance(), 0.0001);
        assertEquals("skewness", 1.437424, u.getSkewness(), 0.0001);
        assertEquals("kurtosis", 2.37719, u.getKurtosis(), 0.0001);
    }
View Full Code Here

     * Computes sampleStats (first pass through data file).
     */
    private void computeStats(BufferedReader in) throws IOException {
        String str = null;
        double val = 0.0;
        sampleStats = new StorelessDescriptiveStatisticsImpl();
        while ((str = in.readLine()) != null) {
            val = new Double(str).doubleValue();
            sampleStats.addValue(val);
        }
        in.close();
View Full Code Here

        // Initialize binStats ArrayList
        if (!binStats.isEmpty()) {
            binStats.clear();
        }
        for (int i = 0; i < binCount; i++) {
            DescriptiveStatistics stats = new StorelessDescriptiveStatisticsImpl();
            binStats.add(i,stats);
        }
       
        // Pass the data again, filling data in binStats Array
        String str = null;
        double val = 0.0d;
        while ((str = in.readLine()) != null) {
            val = new Double(str).doubleValue();
           
            // Find bin and add value to binStats for the bin
            boolean found = false;
            int i = 0;
            while (!found) {
                if (i >= binCount) {
                    throw new RuntimeException("bin alignment error");
                }
                if (val <= binUpperBounds[i]) {
                    found = true;
                    DescriptiveStatistics stats = (DescriptiveStatistics)binStats.get(i);
                    stats.addValue(val);
                }
                i++;
            }
        }
        in.close();
View Full Code Here

        double next = 0.0;
        double tolerance = 0.1;
        vs.computeDistribution();
        assertTrue("empirical distribution property",
            vs.getEmpiricalDistribution() != null);
        DescriptiveStatistics stats = new StorelessDescriptiveStatisticsImpl();
        for (int i = 1; i < 1000; i++) {
            next = vs.getNext();
            stats.addValue(next);
        }   
        assertEquals("mean", 5.069831575018909, stats.getMean(), tolerance);
        assertEquals
         ("std dev", 1.0173699343977738, stats.getStandardDeviation(),
            tolerance);
       
        vs.computeDistribution(500);
        stats = new StorelessDescriptiveStatisticsImpl();
        for (int i = 1; i < 1000; i++) {
            next = vs.getNext();
            stats.addValue(next);
        }   
        assertEquals("mean", 5.069831575018909, stats.getMean(), tolerance);
        assertEquals
         ("std dev", 1.0173699343977738, stats.getStandardDeviation(),
            tolerance);
       
    }
View Full Code Here

                   // really just checking to make sure we do not bomb
    }
   
    private void tstGen(double tolerance)throws Exception {
        empiricalDistribution.load(file);  
        DescriptiveStatistics stats = new StorelessDescriptiveStatisticsImpl();
        for (int i = 1; i < 1000; i++) {
            stats.addValue(empiricalDistribution.getNextValue());
        }
        //TODO: replace these with statistical tests -- refactor as necessary
        assertEquals("mean", stats.getMean(),5.069831575018909,tolerance);
        assertEquals
         ("std dev", stats.getStandardDeviation(),1.0173699343977738,tolerance);
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.math.stat.StorelessDescriptiveStatisticsImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.