Package org.apache.commons.math3.stat.descriptive

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


        GLSMultipleLinearRegression gls = new GLSMultipleLinearRegression();
        gls.newSampleData(longley, nObs, 6);
        gls.newCovarianceData(cov.getData());
       
        // Create aggregators for stats measuring model performance
        DescriptiveStatistics olsBetaStats = new DescriptiveStatistics();
        DescriptiveStatistics glsBetaStats = new DescriptiveStatistics();
       
        // Generate Y vectors for 10000 models, estimate GLS and OLS and
        // Verify that OLS estimates are better
        final int nModels = 10000;
        for (int i = 0; i < nModels; i++) {
           
            // Generate y = xb + u with u cov
            RealVector u = MatrixUtils.createRealVector(gen.nextVector());
            double[] y = u.add(x.operate(b)).toArray();
           
            // Estimate OLS parameters
            ols.newYSampleData(y);
            RealVector olsBeta = ols.calculateBeta();
           
            // Estimate GLS parameters
            gls.newYSampleData(y);
            RealVector glsBeta = gls.calculateBeta();
           
            // Record deviations from "true" beta
            double dist = olsBeta.getDistance(b);
            olsBetaStats.addValue(dist * dist);
            dist = glsBeta.getDistance(b);
            glsBetaStats.addValue(dist * dist);
           
        }
       
        // Verify that GLS is on average more efficient, lower variance
        assert(olsBetaStats.getMean() > 1.5 * glsBetaStats.getMean());
        assert(olsBetaStats.getStandardDeviation() > glsBetaStats.getStandardDeviation())
    }
View Full Code Here


            sample[i] = Math.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

        }

        @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 = VARCHAR.createBlockBuilder(new BlockBuilderStatus());
            String result = formatApproximateOutput(statistics, confidence);
            builder.appendSlice(Slices.utf8Slice(result));
View Full Code Here

        }

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

            String result = formatApproximateOutput(statistics, confidence);
            output.appendSlice(Slices.utf8Slice(result));
        }
View Full Code Here

    @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

    this.numTests = numTests;
    this.iters = iters;
    this.frames = frames;
    stats = new DescriptiveStatistics[numTests];
    for (int i = 0; i < numTests; i++) {
      stats[i] = new DescriptiveStatistics(iters * frames + 1);
      testOrder.add(i);
    }
  }
View Full Code Here

public class TestHyperLogLog {
  @Test(groups = "slow")
  public void testError()
    throws Exception {
    DescriptiveStatistics stats = new DescriptiveStatistics();
    int buckets = 2048;
    for (int i = 0; i < 10000; ++i) {
      HyperLogLog estimator = new HyperLogLog(buckets);
      Set<Long> randomSet = makeRandomSet(5 * buckets);
      for (Long value : randomSet) {
        estimator.add(value);
      }

      double error = (estimator.estimate() - randomSet.size()) * 1.0 / randomSet.size();
      stats.addValue(error);
    }

    assertTrue(stats.getMean() < 1e-2);
    assertTrue(stats.getStandardDeviation() < 1.04 / Math.sqrt(buckets));
  }
View Full Code Here

                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

            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

            //Initialization of outer statistic agregators
            DescriptiveStatistics[] statsMean = new DescriptiveStatistics[maxThread];
            DescriptiveStatistics[] statsSTD = new DescriptiveStatistics[maxThread];
            for (int threads = 1; threads <= maxThread; ++threads) {
                statsMean[threads - 1] = new DescriptiveStatistics();
                statsSTD[threads - 1] = new DescriptiveStatistics();
            }

            for (; trys-- > 0;) { //Each try == one random sum
                DescriptiveStatistics[] stats = new DescriptiveStatistics[maxThread];
                Sum[] sums = random2Sums();
                System.out.println("try " + trys);
                for (int threads = 1; threads <= maxThread; ++threads) {
                    DescriptiveStatistics ds = new DescriptiveStatistics();

                    for (int i = 0; i < 10; ++i) { //Each random sum repeatedly tested 1000 times
                        long start = System.nanoTime();

                        Tensor res = Expand.expandPairOfSumsConcurrent(sums[0], sums[1], threads);
//                        System.out.println(res.size() + " " + res);
                        ds.addValue(System.nanoTime() - start);
                    }

                    stats[threads - 1] = ds; //Saving statistics for one thread
                }
View Full Code Here

TOP

Related Classes of org.apache.commons.math3.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.