Example usage for org.apache.commons.math3.stat.descriptive.moment Variance evaluate

List of usage examples for org.apache.commons.math3.stat.descriptive.moment Variance evaluate

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive.moment Variance evaluate.

Prototype

@Override
public double evaluate(final double[] values) throws MathIllegalArgumentException 

Source Link

Document

Returns the variance of the entries in the input array, or Double.NaN if the array is empty.

Usage

From source file:Rotationforest.Covariance.java

/**
 * Compute a covariance matrix from a matrix whose columns represent
 * covariates.//www . ja va2  s  .  c  o  m
 * @param matrix input matrix (must have at least one column and two rows)
 * @param biasCorrected determines whether or not covariance estimates are bias-corrected
 * @return covariance matrix
 * @throws MathIllegalArgumentException if the matrix does not contain sufficient data
 */
protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected)
        throws MathIllegalArgumentException {
    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)));
        outMatrix.setEntry(i, i, variance.evaluate(matrix.getColumn(i)));
    }
    //return outMatrix;
    return outMatrix;

}