Package org.apache.commons.math.stat.descriptive

Examples of org.apache.commons.math.stat.descriptive.DescriptiveStatistics


        minimizer.setRelativeAccuracy(1e-10);
        minimizer.setAbsoluteAccuracy(1e-11);

        final DescriptiveStatistics[] stat = new DescriptiveStatistics[3];
        for (int i = 0; i < stat.length; i++) {
            stat[i] = new DescriptiveStatistics();
        }

        final double min = -0.75;
        final double max = 0.25;
        final int nSamples = 200;
View Full Code Here


     * Test DescriptiveStatistics - implementations that store full array of
     * values and execute multi-pass algorithms
     */
    public void testDescriptiveStatistics() throws Exception {

        DescriptiveStatistics u = new DescriptiveStatistics();
       
        loadStats("data/PiDigits.txt", u);
        assertEquals("PiDigits: std", std, u.getStandardDeviation(), 1E-14);
        assertEquals("PiDigits: mean", mean, u.getMean(), 1E-14);
       
        loadStats("data/Mavro.txt", u);
        assertEquals("Mavro: std", std, u.getStandardDeviation(), 1E-14);
        assertEquals("Mavro: mean", mean, u.getMean(), 1E-14);       
       
        loadStats("data/Michelso.txt", u);
        assertEquals("Michelso: std", std, u.getStandardDeviation(), 1E-14);
        assertEquals("Michelso: mean", mean, u.getMean(), 1E-14);  

        loadStats("data/NumAcc1.txt", u);
        assertEquals("NumAcc1: std", std, u.getStandardDeviation(), 1E-14);
        assertEquals("NumAcc1: mean", mean, u.getMean(), 1E-14);
       
        loadStats("data/NumAcc2.txt", u);
        assertEquals("NumAcc2: std", std, u.getStandardDeviation(), 1E-14);
        assertEquals("NumAcc2: mean", mean, u.getMean(), 1E-14);
    }
View Full Code Here

     * @param file
     * @param statistical summary
     */
    private void loadStats(String resource, Object u) throws Exception {
       
        DescriptiveStatistics d = null;
        SummaryStatistics s = null;
        if (u instanceof DescriptiveStatistics) {
            d = (DescriptiveStatistics) u;
        } else {
            s = (SummaryStatistics) u;
        }
        u.getClass().getDeclaredMethod(
                "clear", new Class[]{}).invoke(u, new Object[]{});
        mean = Double.NaN;
        std = Double.NaN;
       
        BufferedReader in =
            new BufferedReader(
                    new InputStreamReader(
                            CertifiedDataTest.class.getResourceAsStream(resource)));
       
        String line = null;
       
        for (int j = 0; j < 60; j++) {
            line = in.readLine();
            if (j == 40) {
                mean =
                    Double.parseDouble(
                            line.substring(line.lastIndexOf(":") + 1).trim());
            }
            if (j == 41) {
                std =
                    Double.parseDouble(
                            line.substring(line.lastIndexOf(":") + 1).trim());
            }
        }
       
        line = in.readLine();
       
        while (line != null) {
            if (d != null) {
                d.addValue(Double.parseDouble(line.trim()));
            else {
                s.addValue(Double.parseDouble(line.trim()));
            }
            line = in.readLine();
        }
View Full Code Here

   
    private Map<String, Double> certifiedValues;

    @Override
    protected void setUp() throws Exception {
        descriptives = new DescriptiveStatistics();
        summaries = new SummaryStatistics();
        certifiedValues = new HashMap<String, Double>();
       
        loadData();
    }
View Full Code Here

   * Return the statistics on a vector of strings v, in order min, max, mean and stdDev
   */
  public static Vector<String> calculateStatistics(Vector<String> v)
  {
    System.out.println("  Calculator: calculating statistics");
    DescriptiveStatistics statVect = new DescriptiveStatistics(v.size());
    String nullString = "-";
    for (int i = 0, len = v.size(); (i < len); i++)
    {
      String str = v.get(i);
      if(str == null)
      {
        v.set(i, nullString);
        continue;
      }
      try
      {
        double d = Double.parseDouble(v.get(i));
        statVect.addValue(d);
      }
      catch (NumberFormatException e)
      {
        continue;
      }
    }
    Double min = statVect.getMin();
    Double max = statVect.getMax();
    Double mean = statVect.getMean();
    Double variance = statVect.getVariance();
    Double stdDev = Math.sqrt(variance);
    v.add(0, "-----");
    v.add(0, "" + stdDev.toString());
    v.add(0, "" + mean.toString());
    v.add(0, "" + max.toString());
View Full Code Here

   * Return the statistics on a vector of strings v, in order min, max, mean and stdDev
   */
  public static Vector<Double> calculateDoubleStatistics(Vector<Double> v)
  {
    // System.out.println("  Calculator: calculating statistics");
    DescriptiveStatistics statVect = new DescriptiveStatistics(4);
    for (int i = 0, len = v.size(); (i < len); i++)
    {
      double d = v.get(i);
      try
      {
        statVect.addValue(d);
      }
      catch (NumberFormatException e)
      {
        continue;
      }
    }
   
    Double min = statVect.getMin();
    Double max = statVect.getMax();
    Double mean = statVect.getMean();
    Double variance = statVect.getVariance();
    Double stdDev = Math.sqrt(variance);
   
    Vector<Double> result = new Vector<Double>(0);
    result.add(0, min);
    result.add(0, max);
View Full Code Here

    }


    public static void testDistribution(HashMethod hm, int hashesPerRound, int m, int k, int rounds,
                                        List<List<byte[]>> hashData, StringBuilder chi, StringBuilder pvalue) {
        DescriptiveStatistics pValues = new DescriptiveStatistics();
        DescriptiveStatistics xs = new DescriptiveStatistics();

        HashFunction hf = hm.getHashFunction();
        int hashRounds = hashesPerRound / k;

        for (int i = 0; i < rounds; i++) {
            List<byte[]> data = hashData.get(i);

            long[] observed = new long[m];
            for (int j = 0; j < hashRounds; j++) {
                int[] hashes = hf.hash(data.get(j), m, k);
                for (int h : hashes) {
                    observed[h]++;
                }
            }
            //MemoryBFTest.plotHistogram(observed, hm.toString());

            double[] expected = new double[m];
            for (int j = 0; j < m; j++) {
                expected[j] = hashesPerRound * 1.0 / m;
            }

            ChiSquareTestImpl cs = new ChiSquareTestImpl();
            try {
                pValues.addValue(cs.chiSquareTest(expected, observed));
                xs.addValue(cs.chiSquare(expected, observed));
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

        String result = "HashMethod : " + hm + ", " + " hashes = " + hashesPerRound + ", size = " + m + ", hashes = "
                + k + ", rounds = " + rounds;
        //System.out.println(result);

        chi.append(stringify(xs.getValues()));
        pvalue.append("(*" + result + "*)");
        pvalue.append(stringify(pValues.getValues()));
    }
View Full Code Here

    System.out.println(speedVar + " = { " + mathematica + "};");
    System.out.println("showSpeed[" + speedVar + ", \"Speed (ms)\\expectedElements" + config + "\"]");
  }

  public static String testSpeed(HashMethod hm, List<List<byte[]>> hashData, int hashesPerRound, int m, int k, int rounds) {
    DescriptiveStatistics speed = new DescriptiveStatistics();

        HashFunction hf = hm.getHashFunction();
        int hashRounds = hashesPerRound / k;

    Random r = new Random();
    for (int i = 0; i < rounds; i++) {
      List<byte[]> data = hashData.get(i);

      long start_hash = System.nanoTime();
      for (int i1 = 0; i1 < hashRounds; i1++) {
        int[] hashes = hf.hash(data.get(i1), m, k);
      }
      long end_hash = System.nanoTime();

      speed.addValue((1.0 * end_hash - start_hash) / 1000000);
    }

    System.out.println("HashMethod : " + hm + ", " + " hashes = " + hashesPerRound + ", size = " + m + ", hashes = "
        + k + ", rounds = " + rounds);
    //System.out.println(speed);

    return Arrays.toString(speed.getValues()).replace("[", "{").replace("]", "}");
  }
View Full Code Here

    // discretization.
    times.remove(0);
    times.remove(times.size() - 1);
   
    for(Long time : times) {
      DescriptiveStatistics stats = new DescriptiveStatistics();
      List<Long> list = bucketedRunTimes.get(time);
      for (Long l : list) {
        stats.addValue(l);
        runTimes.addValue(l);
      }
      bucketStats.put(time, stats);
     
      List<Long> waitList = bucketedWaitTimes.get(time);
      for (Long l : waitList) {
        waitTimes.addValue(l);
      }
    }
    int size = bucketStats.size();
    if (size >= 2) {
      DescriptiveStatistics first = bucketStats.get(times.get(0));
      DescriptiveStatistics last = bucketStats.get(times.get(times.size() - 1));
      double increase = last.getPercentile(50) / first.getPercentile(50);
      // A simple heuristic, if the median runtime went up by five from the first to
      // last complete bucket, we assume we are seeing unbounded growth
      if (increase > 5.0) {
        throw new RuntimeException("Queue not in steady state: " + last.getMean()
            + " vs " + first.getMean());
      }
    }
  }
View Full Code Here

   
    // Run the benchmark a few times to let JIT kick in
    int bucketSizeMs = bucketSizeS * 1000;
    int trialLengthMs = trialLengthS * 1000;
    runExperiment(15.0, coreThreadPoolSize, coreThreadPoolSize, bucketSizeMs,
       trialLengthMs, new DescriptiveStatistics(), new DescriptiveStatistics());
    runExperiment(15.0, coreThreadPoolSize, coreThreadPoolSize, bucketSizeMs,
        trialLengthMs, new DescriptiveStatistics(), new DescriptiveStatistics());

    for (double i = startRate; i <= endRate; i = i + rateStep) {
      try {
        DescriptiveStatistics runTimes = new DescriptiveStatistics();
        DescriptiveStatistics waitTimes = new DescriptiveStatistics();
        runExperiment(i, coreThreadPoolSize, coreThreadPoolSize, bucketSizeMs,
            trialLengthMs, runTimes, waitTimes);
        System.out.println(i + " run " + runTimes.getPercentile(50.0) + " " +
            runTimes.getPercentile(95) + " " + runTimes.getPercentile(99));
        System.out.println(i + " wait " + waitTimes.getPercentile(50.0) + " " +
            waitTimes.getPercentile(95) + " " + waitTimes.getPercentile(99));
      }
      catch (RuntimeException e) {
        System.out.println(e);
        break;
      }
    }

    for (double i = startRate; i <= endRate; i = i + rateStep) {
      try {
        DescriptiveStatistics runTimes = new DescriptiveStatistics();
        DescriptiveStatistics waitTimes = new DescriptiveStatistics();
        runExperiment(i, coreThreadPoolSize, Integer.MAX_VALUE, bucketSizeMs,
            trialLengthMs, runTimes, waitTimes);
        System.out.println(i + " run " + runTimes.getPercentile(50.0) + " " +
            runTimes.getPercentile(95) + " " + runTimes.getPercentile(99));
        System.out.println(i + " wait " + waitTimes.getPercentile(50.0) + " " +
            waitTimes.getPercentile(95) + " " + waitTimes.getPercentile(99));
      }
      catch (RuntimeException e) {
        System.out.println(e);
        break;
      }
View Full Code Here

TOP

Related Classes of org.apache.commons.math.stat.descriptive.DescriptiveStatistics

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.