Package org.apache.commons.math.stat

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


      randomData.nextSecureInt(4, 3);
      fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException ex) {
      // ignored
    }
    Frequency freq = new Frequency();
    int value = 0;
    for (int i = 0; i < smallSampleSize; i++) {
      value = randomData.nextSecureInt(0, 3);
      assertTrue("nextInt range", (value >= 0) && (value <= 3));
      freq.addValue(value);
    }
    long[] observed = new long[4];
    for (int i = 0; i < 4; i++) {
      observed[i] = freq.getCount(i);
    }

    /*
     * Use ChiSquare dist with df = 4-1 = 3, alpha = .001 Change to 11.34
     * for alpha = .01
View Full Code Here


      randomData.nextPoisson(0);
      fail("zero mean -- expecting IllegalArgumentException");
    } catch (IllegalArgumentException ex) {
      // ignored
    }
    Frequency f = new Frequency();
    for (int i = 0; i < largeSampleSize; i++) {
      try {
        f.addValue(randomData.nextPoisson(4.0d));
      } catch (Exception ex) {
        fail(ex.getMessage());
      }
    }
    long cumFreq = f.getCount(0) + f.getCount(1) + f.getCount(2)
        + f.getCount(3) + f.getCount(4) + f.getCount(5);
    long sumFreq = f.getSumFreq();
    double cumPct = Double.valueOf(cumFreq).doubleValue()
        / Double.valueOf(sumFreq).doubleValue();
    assertEquals("cum Poisson(4)", cumPct, 0.7851, 0.2);
    try {
      randomData.nextPoisson(-1);
View Full Code Here

      // ignored
    }
    if (hexString.length() != 1) {
      fail("incorrect length for generated string");
    }
    Frequency f = new Frequency();
    for (int i = 0; i < smallSampleSize; i++) {
      hexString = randomData.nextHexString(100);
      if (hexString.length() != 100) {
        fail("incorrect length for generated string");
      }
      for (int j = 0; j < hexString.length(); j++) {
        f.addValue(hexString.substring(j, j + 1));
      }
    }
    double[] expected = new double[16];
    long[] observed = new long[16];
    for (int i = 0; i < 16; i++) {
      expected[i] = (double) smallSampleSize * 100 / 16;
      observed[i] = f.getCount(hex[i]);
    }
    /*
     * Use ChiSquare dist with df = 16-1 = 15, alpha = .001 Change to 30.58
     * for alpha = .01
     */
 
View Full Code Here

      // ignored
    }
    if (hexString.length() != 1) {
      fail("incorrect length for generated string");
    }
    Frequency f = new Frequency();
    for (int i = 0; i < smallSampleSize; i++) {
      hexString = randomData.nextSecureHexString(100);
      if (hexString.length() != 100) {
        fail("incorrect length for generated string");
      }
      for (int j = 0; j < hexString.length(); j++) {
        f.addValue(hexString.substring(j, j + 1));
      }
    }
    double[] expected = new double[16];
    long[] observed = new long[16];
    for (int i = 0; i < 16; i++) {
      expected[i] = (double) smallSampleSize * 100 / 16;
      observed[i] = f.getCount(hex[i]);
    }
    /*
     * Use ChiSquare dist with df = 16-1 = 15, alpha = .001 Change to 30.58
     * for alpha = .01
     */
 
View Full Code Here

            int x = randomData.nextInt(4,3);
            fail("IllegalArgumentException expected");
        } catch (IllegalArgumentException ex) {
            ;
        }
        Frequency freq = new Frequency();
        int value = 0;
        for (int i=0;i<smallSampleSize;i++) {
            value = randomData.nextInt(0,3);
            assertTrue("nextInt range",(value >= 0) && (value <= 3));
            freq.addValue(value)
        }
        long[] observed = new long[4];
        for (int i=0; i<4; i++) {
            observed[i] = freq.getCount(i);
        }
       
        /* Use ChiSquare dist with df = 4-1 = 3, alpha = .001
         * Change to 11.34 for alpha = .01
         */
 
View Full Code Here

            long x = randomData.nextLong(4,3);
            fail("IllegalArgumentException expected");
        } catch (IllegalArgumentException ex) {
            ;
        }
       Frequency freq = new Frequency();
       long value = 0;
        for (int i=0;i<smallSampleSize;i++) {
            value = randomData.nextLong(0,3);
            assertTrue("nextInt range",(value >= 0) && (value <= 3));
            freq.addValue(value)
        }
        long[] observed = new long[4];
        for (int i=0; i<4; i++) {
            observed[i] = freq.getCount(i);
        }
       
        /* Use ChiSquare dist with df = 4-1 = 3, alpha = .001
         * Change to 11.34 for alpha = .01
         */
 
View Full Code Here

            long x = randomData.nextSecureLong(4,3);
            fail("IllegalArgumentException expected");
        } catch (IllegalArgumentException ex) {
            ;
        }
        Frequency freq = new Frequency();
        long value = 0;
        for (int i=0;i<smallSampleSize;i++) {
            value = randomData.nextSecureLong(0,3);
            assertTrue("nextInt range",(value >= 0) && (value <= 3));
            freq.addValue(value)
        }
        long[] observed = new long[4];
        for (int i=0; i<4; i++) {
            observed[i] = freq.getCount(i);
        }
       
        /* Use ChiSquare dist with df = 4-1 = 3, alpha = .001
         * Change to 11.34 for alpha = .01
         */
 
View Full Code Here

            long x = randomData.nextSecureInt(4,3);
            fail("IllegalArgumentException expected");
        } catch (IllegalArgumentException ex) {
            ;
        }
        Frequency freq = new Frequency();
        int value = 0;
        for (int i=0;i<smallSampleSize;i++) {
            value = randomData.nextSecureInt(0,3);
            assertTrue("nextInt range",(value >= 0) && (value <= 3));
            freq.addValue(value)
        }
        long[] observed = new long[4];
        for (int i=0; i<4; i++) {
            observed[i] = freq.getCount(i);
        }
       
        /* Use ChiSquare dist with df = 4-1 = 3, alpha = .001
         * Change to 11.34 for alpha = .01
         */
 
View Full Code Here

            long x = randomData.nextPoisson(0);
            fail("zero mean -- expecting IllegalArgumentException");
        } catch (IllegalArgumentException ex) {
            ;
        }
        Frequency f = new Frequency();
        long v = 0;
        for (int i = 0; i<largeSampleSize; i++) {
            try {
                f.addValue(randomData.nextPoisson(4.0d));
            } catch (Exception ex) {
                fail(ex.getMessage());
            }
        }
        long cumFreq = f.getCount(0) + f.getCount(1) + f.getCount(2) +
                        f.getCount(3) + f.getCount(4) + f.getCount(5);
        long sumFreq = f.getSumFreq();
        double cumPct =
            new Double(cumFreq).doubleValue()/new Double(sumFreq).doubleValue();
        assertEquals("cum Poisson(4)",cumPct,0.7851,0.2);
        try {
            long x = randomData.nextPoisson(-1);
View Full Code Here

            ;
        }
        if (hexString.length() != 1) {
                fail("incorrect length for generated string");
        }     
        Frequency f = new Frequency();
        for (int i = 0; i < smallSampleSize; i++) {
            hexString = randomData.nextHexString(100);
            if (hexString.length() != 100) {
                fail("incorrect length for generated string");
            }
            for (int j = 0; j < hexString.length(); j++) {
                f.addValue(hexString.substring(j,j+1));
            }
        }
        double[] expected = new double[16];
        long[] observed = new long[16];
        for (int i = 0; i < 16; i++) {
            expected[i] = (double)smallSampleSize*100/(double)16;
            observed[i] = f.getCount(hex[i]);
        }
        /* Use ChiSquare dist with df = 16-1 = 15, alpha = .001
         * Change to 30.58 for alpha = .01
         */
        assertTrue("chi-square test -- will fail about 1 in 1000 times",
View Full Code Here

TOP

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

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.