Example usage for org.apache.commons.math.linear BlockRealMatrix BlockRealMatrix

List of usage examples for org.apache.commons.math.linear BlockRealMatrix BlockRealMatrix

Introduction

In this page you can find the example usage for org.apache.commons.math.linear BlockRealMatrix BlockRealMatrix.

Prototype

public BlockRealMatrix(final int rows, final int columns) throws IllegalArgumentException 

Source Link

Document

Create a new matrix with the supplied row and column dimensions.

Usage

From source file:Covariance.java

/**
 * Compute a covariance matrix from a matrix whose columns represent 
 * covariates. //  w  w w . j  a  va  2  s  . c o  m
 * @param matrix input matrix (must have at least two columns and two rows) 
 * @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), i, matrix.getColumn(j), j, biasCorrected);
            outMatrix.setEntry(i, j, cov);
            outMatrix.setEntry(j, i, cov);
        }
        outMatrix.setEntry(i, i, variance.evaluate(matrix.getColumn(i)));
    }
    return outMatrix;
}