@Test
public void testMahalanobis() {

    MultivariateNormalDistribution mvNormal = getSample3dNormal();
    Gaussian gaussian = new Gaussian(mvNormal.getMeans(), mvNormal.getCovariances());
    int N = 100000;
    int k = 3;
    double[][] testData = new double[N][k];
    for (int i = 0; i < N; i++) {
        testData[i] = mvNormal.sample();
    }
    double[] mScores = new double[N];
    long startTime = System.currentTimeMillis();
    for (int i = 0; i < N; i++) {
        mScores[i] = gaussian.mahalanobis(testData[i]);
    }
    long endTime = System.currentTimeMillis();
    log.debug("Mahalobis distance on {} in {}", N, endTime-startTime);
    double[] dScores = new double[N];
    startTime = System.currentTimeMillis();
    for (int i = 0; i < N; i++) {
        dScores[i] = -Math.log(mvNormal.density(testData[i]));
    }
    endTime = System.currentTimeMillis();
    log.debug("LogPDF on {} in {}", N, endTime-startTime);
    // Check that mahalonbis distance has same relative magnitude as -log(pdf)
    for (int i = 1; i < N; i++) {
        assertEquals(mScores[i] > mScores[i-1], dScores[i] > dScores[i-1]);
    }
}