Package org.uncommons.maths.statistics

Examples of org.uncommons.maths.statistics.DataSet


    {
        // Variance of a Possion distribution equals its mean.
        final double expectedStandardDeviation = Math.sqrt(expectedMean);

        final int iterations = 10000;
        DataSet data = new DataSet(iterations);
        for (int i = 0; i < iterations; i++)
        {
            int value = generator.nextValue();
            assert value >= 0 : "Value must be non-negative: " + value;
            data.addValue(value);
        }
        assert Maths.approxEquals(data.getArithmeticMean(), expectedMean, 0.02)
                : "Observed mean outside acceptable range: " + data.getArithmeticMean();
        assert Maths.approxEquals(data.getSampleStandardDeviation(), expectedStandardDeviation, 0.02)
                : "Observed standard deviation outside acceptable range: " + data.getSampleStandardDeviation();
    }
View Full Code Here


    private void checkDistribution(NumberGenerator<Double> generator,
                                   double expectedMean,
                                   double expectedStandardDeviation)
    {
        final int iterations = 10000;
        DataSet data = new DataSet(iterations);
        for (int i = 0; i < iterations; i++)
        {
            data.addValue(generator.nextValue());
        }
        assert Maths.approxEquals(data.getArithmeticMean(), expectedMean, 0.02)
                : "Observed mean outside acceptable range: " + data.getArithmeticMean();
        assert Maths.approxEquals(data.getSampleStandardDeviation(), expectedStandardDeviation, 0.02)
                : "Observed standard deviation outside acceptable range: " + data.getSampleStandardDeviation();
        // Expected median is the same as expected mean.
        assert Maths.approxEquals(data.getMedian(), expectedMean, 0.02)
                : "Observed median outside acceptable range: " + data.getMedian();
    }
View Full Code Here

    {
        final double expectedMean = n * p;
        final double expectedStandardDeviation = Math.sqrt(n * p * (1 - p));

        final int iterations = 10000;
        DataSet data = new DataSet(iterations);
        for (int i = 0; i < iterations; i++)
        {
            int value = generator.nextValue();
            assert value >= 0 && value <= n : "Value out-of-range: " + value;
            data.addValue(value);
        }
        assert Maths.approxEquals(data.getArithmeticMean(), expectedMean, 0.02d)
                : "Observed mean outside acceptable range: " + data.getArithmeticMean();
        assert Maths.approxEquals(data.getSampleStandardDeviation(), expectedStandardDeviation, 0.02)
                : "Observed standard deviation outside acceptable range: " + data.getSampleStandardDeviation();
    }
View Full Code Here

        final double standardDeviation = range / Math.sqrt(12);
        NumberGenerator<Integer> generator = new DiscreteUniformGenerator(min,
                                                                          max,
                                                                          new MersenneTwisterRNG());
        final int iterations = 10000;
        DataSet data = new DataSet(iterations);
        for (int i = 0; i < iterations; i++)
        {
            int value = generator.nextValue();
            assert value >= min && value <= max : "Value out-of-range: " + value;
            data.addValue(value);
        }
        assert Maths.approxEquals(data.getArithmeticMean(), expectedMean, 0.02)
            : "Observed mean outside acceptable range: " + data.getArithmeticMean();
        assert Maths.approxEquals(data.getSampleStandardDeviation(), standardDeviation, 0.02)
            : "Observed standard deviation outside acceptable range: " + data.getSampleStandardDeviation();
        // Expected median is the same as expected mean.
        assert Maths.approxEquals(data.getMedian(), expectedMean, 0.02)
            : "Observed mean outside acceptable range: " + data.getMedian();
    }
View Full Code Here

        final double standardDeviation = range / Math.sqrt(12);
        NumberGenerator<Double> generator = new ContinuousUniformGenerator(min,
                                                                           max,
                                                                           new MersenneTwisterRNG());
        final int iterations = 10000;
        DataSet data = new DataSet(iterations);
        for (int i = 0; i < iterations; i++)
        {
            double value = generator.nextValue();
            assert value >= min && value <= max : "Value out-out-of-range: " + value;
            data.addValue(value);
        }
        assert Maths.approxEquals(data.getArithmeticMean(), expectedMean, 0.02)
            : "Observed mean outside acceptable range: " + data.getArithmeticMean();
        assert Maths.approxEquals(data.getSampleStandardDeviation(), standardDeviation, 0.02)
            : "Observed standard deviation outside acceptable range: " + data.getSampleStandardDeviation();
        // Expected median is the same as expected mean.
        assert Maths.approxEquals(data.getMedian(), expectedMean, 0.02)
            : "Observed mean outside acceptable range: " + data.getMedian();
    }
View Full Code Here

     */
    public static double calculateSampleStandardDeviation(Random rng,
                                                          int maxValue,
                                                          int iterations)
    {
        DataSet dataSet = new DataSet(iterations);
        for (int i = 0; i < iterations; i++)
        {
            dataSet.addValue(rng.nextInt(maxValue));
        }
        return dataSet.getSampleStandardDeviation();
    }
View Full Code Here

        final double expectedMean = 1 / rate;
        final double expectedStandardDeviation = Math.sqrt(1 / (rate * rate));
        final double expectedMedian = Math.log(2) / rate;

        final int iterations = 10000;
        DataSet data = new DataSet(iterations);
        for (int i = 0; i < iterations; i++)
        {
            data.addValue(generator.nextValue());
        }
        // Exponential distribution appears to be a bit more volatile than the others in
        // terms of conforming to expectations, so use a 4% tolerance here, instead of the 2%
        // used for other distributions, to avoid too many false positives.
        assert Maths.approxEquals(data.getArithmeticMean(), expectedMean, 0.04d)
            : "Observed mean outside acceptable range: " + data.getArithmeticMean();
        assert Maths.approxEquals(data.getSampleStandardDeviation(), expectedStandardDeviation, 0.04d)
            : "Observed standard deviation outside acceptable range: " + data.getSampleStandardDeviation();
        assert Maths.approxEquals(data.getMedian(), expectedMedian, 0.04d)
            : "Observed median outside acceptable range: " + data.getMedian();
    }
View Full Code Here

    public <S> List<S> select(List<EvaluatedCandidate<S>> population,
                              boolean naturalFitnessScores,
                              int selectionSize,
                              Random rng)
    {
        DataSet statistics = new DataSet(population.size());
        for (EvaluatedCandidate<S> candidate : population)
        {
            statistics.addValue(candidate.getFitness());
        }

        List<EvaluatedCandidate<S>> scaledPopulation = new ArrayList<EvaluatedCandidate<S>>(population.size());
        for (EvaluatedCandidate<S> candidate : population)
        {
            double scaledFitness = getSigmaScaledFitness(candidate.getFitness(),
                                                         statistics.getArithmeticMean(),
                                                         statistics.getStandardDeviation());
            scaledPopulation.add(new EvaluatedCandidate<S>(candidate.getCandidate(),
                                                           scaledFitness));
        }
        return delegate.select(scaledPopulation, naturalFitnessScores, selectionSize, rng);
    }
View Full Code Here

                                                          boolean naturalFitness,
                                                          int eliteCount,
                                                          int iterationNumber,
                                                          long startTime)
    {
        DataSet stats = new DataSet(evaluatedPopulation.size());
        for (EvaluatedCandidate<T> candidate : evaluatedPopulation)
        {
            stats.addValue(candidate.getFitness());
        }
        return new PopulationData<T>(evaluatedPopulation.get(0).getCandidate(),
                                     evaluatedPopulation.get(0).getFitness(),
                                     stats.getArithmeticMean(),
                                     stats.getStandardDeviation(),
                                     naturalFitness,
                                     stats.getSize(),
                                     eliteCount,
                                     iterationNumber,
                                     System.currentTimeMillis() - startTime);
    }
View Full Code Here

TOP

Related Classes of org.uncommons.maths.statistics.DataSet

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.