Examples of Variance

Note that adding values using increment or incrementAll and then executing getResult will sometimes give a different, less accurate, result than executing evaluate with the full array of values. The former approach should only be used when the full array of values is not available.

The "population variance" ( sum((x_i - mean)^2) / n ) can also be computed using this statistic. The isBiasCorrected property determines whether the "population" or "sample" value is returned by the evaluate and getResult methods. To compute population variances, set this property to false.

Note that this implementation is not synchronized. If multiple threads access an instance of this class concurrently, and at least one of the threads invokes the increment() or clear() method, it must be synchronized externally.

@version $Revision: 1006299 $ $Date: 2010-10-10 16:47:17 +0200 (dim. 10 oct. 2010) $
  • org.apache.commons.math.stat.univariate.moment.Variance
    @version $Revision: 1.14 $ $Date: 2003/11/19 03:28:24 $
  • org.apache.commons.math3.stat.descriptive.moment.Variance
    cm.org/10.1145/359146.359152"> Chan, T. F. and J. G. Lewis 1979, Communications of the ACM, vol. 22 no. 9, pp. 526-531.
  • The evaluate methods leverage the fact that they have the full array of values in memory to execute a two-pass algorithm. Specifically, these methods use the "corrected two-pass algorithm" from Chan, Golub, Levesque, Algorithms for Computing the Sample Variance, American Statistician, vol. 37, no. 3 (1983) pp. 242-247.
  • Note that adding values using increment or incrementAll and then executing getResult will sometimes give a different, less accurate, result than executing evaluate with the full array of values. The former approach should only be used when the full array of values is not available.

    The "population variance" ( sum((x_i - mean)^2) / n ) can also be computed using this statistic. The isBiasCorrected property determines whether the "population" or "sample" value is returned by the evaluate and getResult methods. To compute population variances, set this property to false.

    Note that this implementation is not synchronized. If multiple threads access an instance of this class concurrently, and at least one of the threads invokes the increment() or clear() method, it must be synchronized externally.


    Examples of org.apache.commons.math.stat.descriptive.moment.Variance

        public void testInteraction() {

            FourthMoment m4 = new FourthMoment();
            Mean m = new Mean(m4);
            Variance v = new Variance(m4);
            Skewness s= new Skewness(m4);
            Kurtosis k = new Kurtosis(m4);

            for (int i = 0; i < testArray.length; i++){
                m4.increment(testArray[i]);
            }

            assertEquals(mean,m.getResult(),tolerance);
            assertEquals(var,v.getResult(),tolerance);
            assertEquals(skew ,s.getResult(),tolerance);
            assertEquals(kurt,k.getResult(),tolerance);

        }
    View Full Code Here

    Examples of org.apache.commons.math.stat.descriptive.moment.Variance

         * </p>
         * @return the variance
         */
        public double getVariance() {
            if (varianceImpl == variance) {
                return new Variance(secondMoment).getResult();
            } else {
                return varianceImpl.getResult();
            }
        }
    View Full Code Here

    Examples of org.apache.commons.math.stat.descriptive.moment.Variance

         * Calculates the variance of the y values.
         *
         * @return Y variance
         */
        protected double calculateYVariance() {
            return new Variance().evaluate(Y.getData());
        }
    View Full Code Here

    Examples of org.apache.commons.math.stat.descriptive.moment.Variance

         * @param biasCorrected determines whether or not covariance estimates are bias-corrected
         * @return covariance matrix
         */
        protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected) {
            int dimension = matrix.getColumnDimension();
            Variance variance = new Variance(biasCorrected);
            RealMatrix outMatrix = new BlockRealMatrix(dimension, dimension);
            for (int i = 0; i < dimension; i++) {
                for (int j = 0; j < i; j++) {
                  double cov = covariance(matrix.getColumn(i), matrix.getColumn(j), biasCorrected);
                  outMatrix.setEntry(i, j, cov);
                  outMatrix.setEntry(j, i, cov);
                }
                outMatrix.setEntry(i, i, variance.evaluate(matrix.getColumn(i)));
            }
            return outMatrix;
        }
    View Full Code Here

    Examples of org.apache.commons.math.stat.descriptive.moment.Variance

            for (final Cluster<T> cluster : clusters) {
                if (!cluster.getPoints().isEmpty()) {

                    // compute the distance variance of the current cluster
                    final T center = cluster.getCenter();
                    final Variance stat = new Variance();
                    for (final T point : cluster.getPoints()) {
                        stat.increment(point.distanceFrom(center));
                    }
                    final double variance = stat.getResult();

                    // select the cluster with the largest variance
                    if (variance > maxVariance) {
                        maxVariance = variance;
                        selected = cluster;
    View Full Code Here

    Examples of org.apache.commons.math.stat.descriptive.moment.Variance

        public void testInteraction() {
           
            FourthMoment m4 = new FourthMoment();
            Mean m = new Mean(m4);
            Variance v = new Variance(m4);
            Skewness s= new Skewness(m4);
            Kurtosis k = new Kurtosis(m4);

            for (int i = 0; i < testArray.length; i++){
                m4.increment(testArray[i]);
            }
           
            assertEquals(mean,m.getResult(),tolerance);
            assertEquals(var,v.getResult(),tolerance);
            assertEquals(skew ,s.getResult(),tolerance);
            assertEquals(kurt,k.getResult(),tolerance);

        }
    View Full Code Here

    Examples of org.apache.commons.math.stat.univariate.moment.Variance

        public void testInteraction() {
           
            FourthMoment m4 = new FourthMoment();
            Mean m = new Mean(m4);
            Variance v = new Variance(m4);
            Skewness s= new Skewness(m4);
            Kurtosis k = new Kurtosis(m4);

            for (int i = 0; i < testArray.length; i++){
                m4.increment(testArray[i]);
                m.increment(testArray[i]);
                v.increment(testArray[i]);
                s.increment(testArray[i]);
                k.increment(testArray[i]);
            }
           
            assertEquals(mean,m.getResult(),tolerance);
            assertEquals(var,v.getResult(),tolerance);
            assertEquals(skew ,s.getResult(),tolerance);
            assertEquals(kurt,k.getResult(),tolerance);

        }
    View Full Code Here

    Examples of org.apache.commons.math3.stat.descriptive.moment.Variance

         * <p>Double.NaN is returned if no values have been added.</p>
         *
         * @return the population variance
         */
        public double getPopulationVariance() {
            Variance populationVariance = new Variance(secondMoment);
            populationVariance.setBiasCorrected(false);
            return populationVariance.getResult();
        }
    View Full Code Here

    Examples of org.apache.commons.math3.stat.descriptive.moment.Variance

            dest.secondMoment = source.secondMoment.copy();
            dest.n = source.n;

            // Keep commons-math supplied statistics with embedded moments in synch
            if (source.getVarianceImpl() instanceof Variance) {
                dest.varianceImpl = new Variance(dest.secondMoment);
            } else {
                dest.varianceImpl = source.varianceImpl.copy();
            }
            if (source.meanImpl instanceof Mean) {
                dest.meanImpl = new Mean(dest.secondMoment);
    View Full Code Here

    Examples of org.apache.commons.math3.stat.descriptive.moment.Variance

                for (final Cluster<T> cluster : clusters) {
                    if (!cluster.getPoints().isEmpty()) {

                        // compute the distance variance of the current cluster
                        final T center = cluster.getCenter();
                        final Variance stat = new Variance();
                        for (final T point : cluster.getPoints()) {
                            stat.increment(point.distanceFrom(center));
                        }
                        varianceSum += stat.getResult();

                    }
                }

                if (varianceSum <= bestVarianceSum) {
    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.