Java Code Examples for org.apache.commons.math3.linear.MatrixUtils#blockInverse()

The following examples show how to use org.apache.commons.math3.linear.MatrixUtils#blockInverse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultivariateTDistribution.java    From macrobase with Apache License 2.0 6 votes vote down vote up
public MultivariateTDistribution(RealVector mean, RealMatrix covarianceMatrix, double degreesOfFreedom) {
    this.mean = mean;
    if (mean.getDimension() > 1) {
        this.precisionMatrix = MatrixUtils.blockInverse(covarianceMatrix, (-1 + covarianceMatrix.getColumnDimension()) / 2);
    } else {
        this.precisionMatrix = MatrixUtils.createRealIdentityMatrix(1).scalarMultiply(1. / covarianceMatrix.getEntry(0, 0));
    }
    this.dof = degreesOfFreedom;

    this.D = mean.getDimension();

    double determinant = new LUDecomposition(covarianceMatrix).getDeterminant();

    this.multiplier = Math.exp(Gamma.logGamma(0.5 * (D + dof)) - Gamma.logGamma(0.5 * dof)) /
            Math.pow(Math.PI * dof, 0.5 * D) /
            Math.pow(determinant, 0.5);
}
 
Example 2
Source File: KDE.java    From macrobase with Apache License 2.0 5 votes vote down vote up
private void calculateBandwidthAncillaries() {
    RealMatrix inverseBandwidth;
    if (bandwidth.getColumnDimension() > 1) {
        inverseBandwidth = MatrixUtils.blockInverse(bandwidth, (bandwidth.getColumnDimension() - 1) / 2);
    } else {
        // Manually invert size 1 x 1 matrix, because block Inverse requires dimensions > 1
        inverseBandwidth = bandwidth.copy();
        inverseBandwidth.setEntry(0, 0, 1.0 / inverseBandwidth.getEntry(0, 0));
    }
    this.bandwidthToNegativeHalf = (new EigenDecomposition(inverseBandwidth)).getSquareRoot();
    this.bandwidthDeterminantSqrt = Math.sqrt((new EigenDecomposition(bandwidth)).getDeterminant());
}
 
Example 3
Source File: AlgebraUtils.java    From macrobase with Apache License 2.0 5 votes vote down vote up
public static RealMatrix invertMatrix(RealMatrix matrix) {
    if (matrix.getColumnDimension() > 1) {
        return MatrixUtils.blockInverse(matrix, (matrix.getColumnDimension() - 1) / 2);
    } else {
        // Manually invert size 1 x 1 matrix, because block Inverse requires dimensions > 1
        return MatrixUtils.createRealIdentityMatrix(1).scalarMultiply(1. / matrix.getEntry(0, 0));
    }
}