Example usage for org.apache.commons.math3.stat.descriptive DescriptiveStatistics addValue

List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics addValue

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive DescriptiveStatistics addValue.

Prototype

public void addValue(double v) 

Source Link

Document

Adds the value to the dataset.

Usage

From source file:com.fpuna.preproceso.TestApacheMathLibDemo.java

/**
 * @param args//from   www .j  a va2 s. c  om
 */
public static void main(String[] args) {

    RandomGenerator randomGenerator = new JDKRandomGenerator();
    System.out.println(randomGenerator.nextInt());
    System.out.println(randomGenerator.nextDouble());

    /**
     * Descriptive Statistics like MEAN,GP,SD,MAX
    *
     */
    DescriptiveStatistics stats = new DescriptiveStatistics();
    stats.addValue(1);
    stats.addValue(2);
    stats.addValue(3);
    stats.addValue(4);
    stats.addValue(5);
    stats.addValue(6);
    stats.addValue(7);
    System.out.print("Mean : " + stats.getMean() + "\n");
    System.out.print("Standard deviation : " + stats.getStandardDeviation() + "\n");
    System.out.print("Max : " + stats.getMax() + "\n");

    /**
     * Complex number format a+bi
    *
     */
    Complex c1 = new Complex(1, 2);
    Complex c2 = new Complex(2, 3);
    System.out.print("Absolute of c1 " + c1.abs() + "\n");
    System.out.print("Addition : " + (c1.add(c2)) + "\n");
}

From source file:es.upm.oeg.tools.rdfshapes.libdemo.CommonsMathDemo.java

public static void main(String[] args) {

    DescriptiveStatistics stats = new DescriptiveStatistics();

    int inputArray[] = { 3, 4, 5, 6, 2, 3, 4, 3, 3, 4, 3, 6, 3, 2, 3, 1, 2, 1, 1, 1, 3 };

    // Add the data from the array
    for (int i = 0; i < inputArray.length; i++) {
        stats.addValue(inputArray[i]);
    }/*from w  w w.j  av  a2  s.  c  om*/

    double mean = stats.getMean();
    double std = stats.getStandardDeviation();
    double median = stats.getPercentile(50);

    System.out.println("mean" + stats.getMean());
    System.out.println("standard deviation" + stats.getStandardDeviation());
    System.out.println("skewness" + stats.getSkewness());

}

From source file:knop.psfj.utils.MathUtils.java

/**
 * The main method./*from ww  w .  j  ava  2  s  .  c  om*/
 *
 * @param args the arguments
 */
public static void main(String[] args) {
    System.out.println(MathUtils.round(1.44));
    System.out.println(MathUtils.round(1.49999));
    System.out.println(MathUtils.formatDouble(0.1, "um"));
    System.out.println(MathUtils.formatDouble(0.0034553, MICROMETERS));
    System.out.println(MathUtils.formatDouble(0.033454, MICROMETERS));
    System.out.println(MathUtils.formatDouble(0.31123, MICROMETERS));
    System.out.println(MathUtils.formatDouble(3.1123, MICROMETERS));
    System.out.println(MathUtils.formatDouble(30.05, MICROMETERS));
    System.out.println(MathUtils.formatDouble(300.404, MICROMETERS));
    System.out.println(MathUtils.formatDouble(17.0, MICROMETERS, 1));

    DescriptiveStatistics stats = new DescriptiveStatistics();

    for (int i = 0; i != 100; i++) {
        stats.addValue(100 + 1.0 * i / 12);
    }
    System.out.println(stats);
    System.out.println(MathUtils.formatStatistics(stats, DEGREES));
    System.out.println(MathUtils.getNumberAfterDot("12.534 nm"));

    System.out.println(MathUtils.getNumberAfterDot("12.53"));
    System.out.println(MathUtils.getNumberAfterDot("12 nm"));
    System.out.println(MathUtils.getNumberAfterDot("12.34 nm"));
}

From source file:com.sop4j.SimpleStatistics.java

public static void main(String[] args) {
    final MersenneTwister rng = new MersenneTwister(); // used for RNG... READ THE DOCS!!!
    final int[] values = new int[NUM_VALUES];

    final DescriptiveStatistics descriptiveStats = new DescriptiveStatistics(); // stores values
    final SummaryStatistics summaryStats = new SummaryStatistics(); // doesn't store values
    final Frequency frequency = new Frequency();

    // add numbers into our stats
    for (int i = 0; i < NUM_VALUES; ++i) {
        values[i] = rng.nextInt(MAX_VALUE);

        descriptiveStats.addValue(values[i]);
        summaryStats.addValue(values[i]);
        frequency.addValue(values[i]);/*from  w w w.  j  ava 2s.  co m*/
    }

    // print out some standard stats
    System.out.println("MIN: " + summaryStats.getMin());
    System.out.println("AVG: " + String.format("%.3f", summaryStats.getMean()));
    System.out.println("MAX: " + summaryStats.getMax());

    // get some more complex stats only offered by DescriptiveStatistics
    System.out.println("90%: " + descriptiveStats.getPercentile(90));
    System.out.println("MEDIAN: " + descriptiveStats.getPercentile(50));
    System.out.println("SKEWNESS: " + String.format("%.4f", descriptiveStats.getSkewness()));
    System.out.println("KURTOSIS: " + String.format("%.4f", descriptiveStats.getKurtosis()));

    // quick and dirty stats (need a little help from Guava to convert from int[] to double[])
    System.out.println("MIN: " + StatUtils.min(Doubles.toArray(Ints.asList(values))));
    System.out.println("AVG: " + String.format("%.4f", StatUtils.mean(Doubles.toArray(Ints.asList(values)))));
    System.out.println("MAX: " + StatUtils.max(Doubles.toArray(Ints.asList(values))));

    // some stats based upon frequencies
    System.out.println("NUM OF 7s: " + frequency.getCount(7));
    System.out.println("CUMULATIVE FREQUENCY OF 7: " + frequency.getCumFreq(7));
    System.out.println("PERCENTAGE OF 7s: " + frequency.getPct(7));
}

From source file:fr.inria.eventcloud.benchmarks.QuadrupleStatsEvaluator.java

public static void main(String[] args) throws FileNotFoundException {
    final DescriptiveStatistics g = new DescriptiveStatistics();
    final DescriptiveStatistics s = new DescriptiveStatistics();
    final DescriptiveStatistics p = new DescriptiveStatistics();
    final DescriptiveStatistics o = new DescriptiveStatistics();

    RDFDataMgr.parse(new StreamRDF() {

        @Override/*from   www  .jav  a 2  s.  c o m*/
        public void triple(Triple triple) {
        }

        @Override
        public void start() {
        }

        @Override
        public void quad(Quad quad) {

            g.addValue(SemanticCoordinate.applyDopingFunction(quad.getGraph())
                    // quad.getGraph().toString()
                    .length());
            s.addValue(SemanticCoordinate.applyDopingFunction(quad.getSubject())
                    // quad.getSubject().toString()
                    .length());
            p.addValue(SemanticCoordinate.applyDopingFunction(quad.getPredicate())
                    // quad.getPredicate().toString()
                    .length());
            o.addValue(SemanticCoordinate.applyDopingFunction(quad.getObject())
                    // quad.getObject().toString()
                    .length());
        }

        @Override
        public void prefix(String prefix, String iri) {
        }

        @Override
        public void finish() {
        }

        @Override
        public void base(String base) {
        }
    }, new FileInputStream(args[0]), Lang.TRIG);

    double percentage = 0.99;

    System.out.println("g --> " + g.getPercentile(percentage));
    System.out.println("s --> " + s.getPercentile(percentage));
    System.out.println("p --> " + p.getPercentile(percentage));
    System.out.println("o --> " + o.getPercentile(percentage));
}

From source file:cc.redberry.core.performance.StableSort.java

/**
 * @param args the command line arguments
 *//* w  w  w. j a  va2s.  c o  m*/
public static void main(String[] args) {
    try {

        //burn JVM
        BitsStreamGenerator bitsStreamGenerator = new Well19937c();

        for (int i = 0; i < 1000; ++i)
            nextArray(1000, bitsStreamGenerator);

        System.out.println("!");
        BufferedWriter timMeanOut = new BufferedWriter(
                new FileWriter("/home/stas/Projects/stableSort/timMean.dat"));
        BufferedWriter insertionMeanOut = new BufferedWriter(
                new FileWriter("/home/stas/Projects/stableSort/insertionMean.dat"));

        BufferedWriter timMaxOut = new BufferedWriter(
                new FileWriter("/home/stas/Projects/stableSort/timMax.dat"));
        BufferedWriter insertionMaxOut = new BufferedWriter(
                new FileWriter("/home/stas/Projects/stableSort/insertionMax.dat"));

        BufferedWriter timSigOut = new BufferedWriter(
                new FileWriter("/home/stas/Projects/stableSort/timSig.dat"));
        BufferedWriter insertionSigOut = new BufferedWriter(
                new FileWriter("/home/stas/Projects/stableSort/insertionSig.dat"));

        DescriptiveStatistics timSort;
        DescriptiveStatistics insertionSort;

        int tryies = 200;
        int arrayLength = 0;
        for (; arrayLength < 1000; ++arrayLength) {

            int[] coSort = nextArray(arrayLength, bitsStreamGenerator);

            timSort = new DescriptiveStatistics();
            insertionSort = new DescriptiveStatistics();
            for (int i = 0; i < tryies; ++i) {
                int[] t1 = nextArray(arrayLength, bitsStreamGenerator);
                int[] t2 = t1.clone();

                long start = System.currentTimeMillis();
                ArraysUtils.timSort(t1, coSort);
                long stop = System.currentTimeMillis();
                timSort.addValue(stop - start);

                start = System.currentTimeMillis();
                ArraysUtils.insertionSort(t2, coSort);
                stop = System.currentTimeMillis();
                insertionSort.addValue(stop - start);
            }
            timMeanOut.write(arrayLength + "\t" + timSort.getMean() + "\n");
            insertionMeanOut.write(arrayLength + "\t" + insertionSort.getMean() + "\n");

            timMaxOut.write(arrayLength + "\t" + timSort.getMax() + "\n");
            insertionMaxOut.write(arrayLength + "\t" + insertionSort.getMax() + "\n");

            timSigOut.write(arrayLength + "\t" + timSort.getStandardDeviation() + "\n");
            insertionSigOut.write(arrayLength + "\t" + insertionSort.getStandardDeviation() + "\n");
        }
        timMeanOut.close();
        insertionMeanOut.close();
        timMaxOut.close();
        insertionMaxOut.close();
        timSigOut.close();
        insertionSigOut.close();
    } catch (IOException ex) {
        Logger.getLogger(StableSort.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:mase.deprecated.FastMathTest.java

public static void main(String[] args) {
    double MIN = -10;
    double MAX = 10;
    int N = 10000;
    DescriptiveStatistics diff = new DescriptiveStatistics();
    DescriptiveStatistics diffJava = new DescriptiveStatistics();
    long tFast = 0, tNormal = 0, tBounded = 0, tJava = 0;
    for (int i = 0; i < N; i++) {
        double x = Math.random() * (MAX - MIN) + MIN;
        long t = System.nanoTime();
        double v1 = (1.0 / (1.0 + FastMath.expQuick(-1 * x)));
        tFast += System.nanoTime() - t;
        t = System.nanoTime();/* w  ww.ja v  a 2  s . co  m*/
        double v2 = (1.0 / (1.0 + FastMath.exp(-1 * x)));
        tNormal += System.nanoTime() - t;
        t = System.nanoTime();
        double v3 = (1.0 / (1.0 + BoundMath.exp(-1 * x)));
        tBounded += System.nanoTime() - t;
        t = System.nanoTime();
        double v4 = (1.0 / (1.0 + Math.exp(-1 * x)));
        tJava += System.nanoTime() - t;
        diff.addValue(Math.abs(v1 - v2));
        diffJava.addValue(Math.abs(v3 - v1));
    }

    System.out.println("MAX: " + diff.getMax());
    System.out.println("MEAN: " + diff.getMean());
    System.out.println("MAX JAVA: " + diffJava.getMax());
    System.out.println("MEAN JAVA: " + diffJava.getMean());

    System.out.println("Fast: " + tFast);
    System.out.println("Normal: " + tNormal);
    System.out.println("Bounded: " + tBounded);
    System.out.println("Java: " + tJava);
}

From source file:cc.redberry.core.performance.ProductBijectionPerformanceTest.java

public static void main(String[] args) {
    int badCounter = 0;
    //        CC.resetTensorNames(-3912578993076521674L);
    RandomTensor rp = new RandomTensor(4, 10, new int[] { 4, 0, 0, 0 }, new int[] { 10, 0, 0, 0 }, false);
    rp.reset(-3806751651286565680L);//from w w  w.j  a va2s .  com
    System.out.println("Random Seed = " + rp.getSeed());
    System.out.println("NM Seed = " + CC.getNameManager().getSeed());
    DescriptiveStatistics timeStats = new DescriptiveStatistics();
    DescriptiveStatistics trysStats = new DescriptiveStatistics();
    int count = 0;
    while (++count < 500) {
        //            CC.resetTensorNames();
        Tensor t = rp.nextProduct(15);
        if (!(t instanceof Product))
            continue;

        Product from = (Product) t;

        long start = System.nanoTime();
        ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), from.getContent());

        int[] bijection;
        boolean good = false;
        int trys = 0;
        OUTER: while (trys++ < 5000 && (bijection = port.take()) != null) {
            for (int i = 0; i < bijection.length; ++i)
                if (bijection[i] != i)
                    continue OUTER;
            good = true;
            break;
        }

        double millis = 1E-6 * (System.nanoTime() - start);
        timeStats.addValue(millis);
        trysStats.addValue(trys);

        if (!good)
            throw new RuntimeException();
    }
    System.out.println(timeStats);
    System.out.println(trysStats);
}

From source file:com.weibo.motan.demo.client.DemoRpcClient.java

public static void main(String[] args) throws Exception {
    final DescriptiveStatistics stats = new SynchronizedDescriptiveStatistics();

    int threads = Integer.parseInt(args[0]);

    DubboBenchmark.BenchmarkMessage msg = prepareArgs();
    final byte[] msgBytes = msg.toByteArray();

    int n = 1000000;
    final CountDownLatch latch = new CountDownLatch(n);

    ExecutorService es = Executors.newFixedThreadPool(threads);

    final AtomicInteger trans = new AtomicInteger(0);
    final AtomicInteger transOK = new AtomicInteger(0);

    ApplicationContext ctx = new ClassPathXmlApplicationContext(
            new String[] { "classpath:motan_demo_client.xml" });

    MotanDemoService service = (MotanDemoService) ctx.getBean("motanDemoReferer");

    long start = System.currentTimeMillis();
    for (int i = 0; i < n; i++) {
        es.submit(() -> {/*from  www . j  a v a2  s  . com*/
            try {

                long t = System.currentTimeMillis();
                DubboBenchmark.BenchmarkMessage m = testSay(service, msgBytes);
                t = System.currentTimeMillis() - t;
                stats.addValue(t);

                trans.incrementAndGet();

                if (m != null && m.getField1().equals("OK")) {
                    transOK.incrementAndGet();
                }

            } finally {
                latch.countDown();
            }
        });
    }

    latch.await();

    start = System.currentTimeMillis() - start;

    System.out.printf("sent     requests    : %d\n", n);
    System.out.printf("received requests    : %d\n", trans.get());
    System.out.printf("received requests_OK : %d\n", transOK.get());
    System.out.printf("throughput  (TPS)    : %d\n", n * 1000 / start);

    System.out.printf("mean: %f\n", stats.getMean());
    System.out.printf("median: %f\n", stats.getPercentile(50));
    System.out.printf("max: %f\n", stats.getMax());
    System.out.printf("min: %f\n", stats.getMin());

    System.out.printf("99P: %f\n", stats.getPercentile(90));

}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step5bGoldLabelStatistics.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    String inputDir = args[0];//www  . ja v  a  2  s .c  o m

    Collection<File> files = IOHelper.listXmlFiles(new File(inputDir));

    int totalPairsWithReasonSameAsGold = 0;

    DescriptiveStatistics ds = new DescriptiveStatistics();

    DescriptiveStatistics statsPerTopic = new DescriptiveStatistics();

    Map<String, Integer> goldDataDistribution = new HashMap<>();

    int totalGoldReasonTokens = 0;

    for (File file : files) {
        List<AnnotatedArgumentPair> argumentPairs = (List<AnnotatedArgumentPair>) XStreamTools.getXStream()
                .fromXML(file);

        int pairsPerTopicCounter = 0;

        for (AnnotatedArgumentPair annotatedArgumentPair : argumentPairs) {
            String goldLabel = annotatedArgumentPair.getGoldLabel();

            int sameInOnePair = 0;

            if (goldLabel != null) {
                if (!goldDataDistribution.containsKey(goldLabel)) {
                    goldDataDistribution.put(goldLabel, 0);
                }

                goldDataDistribution.put(goldLabel, goldDataDistribution.get(goldLabel) + 1);

                // get gold reason statistics
                for (AnnotatedArgumentPair.MTurkAssignment assignment : annotatedArgumentPair.mTurkAssignments) {
                    String label = assignment.getValue();

                    if (goldLabel.equals(label)) {
                        sameInOnePair++;

                        totalGoldReasonTokens += assignment.getReason().split("\\W+").length;
                    }
                }

                pairsPerTopicCounter++;
            }

            ds.addValue(sameInOnePair);
            totalPairsWithReasonSameAsGold += sameInOnePair;

        }

        statsPerTopic.addValue(pairsPerTopicCounter);
    }

    System.out.println("Total reasons matching gold " + totalPairsWithReasonSameAsGold);
    System.out.println(ds);

    int totalPairs = 0;
    for (Integer pairs : goldDataDistribution.values()) {
        totalPairs += pairs;
    }

    System.out.println(goldDataDistribution);
    System.out.println(goldDataDistribution.values());
    System.out.println("Total pairs: " + totalPairs);

    System.out.println("Stats per topic: " + statsPerTopic);
    System.out.println("Total gold reason tokens: " + totalGoldReasonTokens);

}