Examples of DescriptiveStatistics


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

     * values and execute multi-pass algorithms
     */
    @Test
    public void testDescriptiveStatistics() throws Exception {

        DescriptiveStatistics u = new DescriptiveStatistics();

        loadStats("data/PiDigits.txt", u);
        Assert.assertEquals("PiDigits: std", std, u.getStandardDeviation(), 1E-14);
        Assert.assertEquals("PiDigits: mean", mean, u.getMean(), 1E-14);

        loadStats("data/Mavro.txt", u);
        Assert.assertEquals("Mavro: std", std, u.getStandardDeviation(), 1E-14);
        Assert.assertEquals("Mavro: mean", mean, u.getMean(), 1E-14);

        loadStats("data/Michelso.txt", u);
        Assert.assertEquals("Michelso: std", std, u.getStandardDeviation(), 1E-14);
        Assert.assertEquals("Michelso: mean", mean, u.getMean(), 1E-14);

        loadStats("data/NumAcc1.txt", u);
        Assert.assertEquals("NumAcc1: std", std, u.getStandardDeviation(), 1E-14);
        Assert.assertEquals("NumAcc1: mean", mean, u.getMean(), 1E-14);

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

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

    /**
     * loads a DescriptiveStatistics off of a test file
     */
    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;

        InputStream resourceAsStream = CertifiedDataTest.class.getResourceAsStream(resource);
        Assert.assertNotNull("Could not find resource "+resource,resourceAsStream);
        BufferedReader in =
            new BufferedReader(
                    new InputStreamReader(
                            resourceAsStream));

        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

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

            sample[i] = FastMath.random();
        }
        // normalize this sample
        double standardizedSample[] = StatUtils.normalize(sample);

        DescriptiveStatistics stats = new DescriptiveStatistics();
        // Add the data from the array
        for (int i = 0; i < length; i++) {
            stats.addValue(standardizedSample[i]);
        }
        // the calculations do have a limited precision   
        double distance = 1E-10;
        // check the mean an standard deviation
        Assert.assertEquals(0.0, stats.getMean(), distance);
        Assert.assertEquals(1.0, stats.getStandardDeviation(), distance);

    }
View Full Code Here

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

     * @param sample Sample to normalize.
     * @return normalized (standardized) sample.
     * @since 2.2
     */
    public static double[] normalize(final double[] sample) {
        DescriptiveStatistics stats = new DescriptiveStatistics();

        // Add the data from the series to stats
        for (int i = 0; i < sample.length; i++) {
            stats.addValue(sample[i]);
        }

        // Compute mean and standard deviation
        double mean = stats.getMean();
        double standardDeviation = stats.getStandardDeviation();

        // initialize the standardizedSample, which has the same length as the sample
        double[] standardizedSample = new double[sample.length];

        for (int i = 0; i < sample.length; i++) {
View Full Code Here

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

        }

        @Override
        public Block evaluateFinal()
        {
            DescriptiveStatistics statistics = new DescriptiveStatistics();
            for (int i = 0; i < accumulators.size(); i++) {
                BlockCursor cursor = accumulators.get(i).evaluateFinal().cursor();
                checkArgument(cursor.advanceNextPosition(), "accumulator returned no results");
                statistics.addValue(getNumeric(cursor));
            }

            BlockBuilder builder = new BlockBuilder(SINGLE_VARBINARY);
            builder.append(formatApproximateOutput(statistics, confidence));
            return builder.build();
View Full Code Here

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

        }

        @Override
        public void evaluateFinal(int groupId, BlockBuilder output)
        {
            DescriptiveStatistics statistics = new DescriptiveStatistics();
            for (int i = 0; i < accumulators.size(); i++) {
                BlockBuilder builder = new BlockBuilder(accumulators.get(i).getFinalTupleInfo());
                accumulators.get(i).evaluateFinal(groupId, builder);
                BlockCursor cursor = builder.build().cursor();
                checkArgument(cursor.advanceNextPosition(), "accumulator returned no results");
                statistics.addValue(getNumeric(cursor));
            }

            output.append(formatApproximateOutput(statistics, confidence));
        }
View Full Code Here

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

    @Test
    public void testMultiplePositions()
            throws Exception
    {
        DescriptiveStatistics stats = new DescriptiveStatistics();

        for (int i = 0; i < 500; ++i) {
            int uniques = ThreadLocalRandom.current().nextInt(20000) + 1;

            List<Object> values = createRandomSample(uniques, (int) (uniques * 1.5));

            long actual = estimateGroupByCount(values);
            double error = (actual - uniques) * 1.0 / uniques;

            stats.addValue(error);
        }

        assertLessThan(stats.getMean(), 1.0e-2);
        assertLessThan(Math.abs(stats.getStandardDeviation() - ApproximateCountDistinctAggregations.getStandardError()), 1.0e-2);
    }
View Full Code Here

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

                new int[]{10, 0, 0, 0},
                false);
        rp.reset(-3806751651286565680L);
        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, target = from;

            long start = System.nanoTime();
            ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), target.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);
View Full Code Here

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

                new int[]{10, 0, 0, 0},
                false);
        rp.reset(-3806751651286565680L);
        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);
View Full Code Here

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

            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();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.