throw new CardinalityException(m.numRows(), m.numCols());
}
// See http://www.mlahanas.de/Math/svd.htm for details,
// which specifically details the case of covariance matrix inversion
// Complexity: O(min(nm2,mn2))
SingularValueDecomposition svd = new SingularValueDecomposition(m);
Matrix sInv = svd.getS();
// Inverse Diagonal Elems
for (int i = 0; i < sInv.numRows(); i++) {
double diagElem = sInv.get(i, i);
if (diagElem > 0.0) {
sInv.set(i, i, 1 / diagElem);
} else {
throw new IllegalStateException("Eigen Value equals to 0 found.");
}
}
inverseCovarianceMatrix = svd.getU().times(sInv.times(svd.getU().transpose()));
Preconditions.checkArgument(inverseCovarianceMatrix != null, "inverseCovarianceMatrix not initialized");
}