CholeskyDecompositionOpenGamma extends Decomposition<CholeskyDecompositionResult> { @Override public CholeskyDecompositionResult evaluate(final DoubleMatrix2D x) { return evaluate(x, DEFAULT_SYMMETRY_THRESHOLD, DEFAULT_POSITIVITY_THRESHOLD); }  @Override CholeskyDecompositionResult evaluate(final DoubleMatrix2D x); CholeskyDecompositionResult evaluate(final DoubleMatrix2D matrix, final double symmetryThreshold, final double positivityThreshold); static final double DEFAULT_SYMMETRY_THRESHOLD; static final double DEFAULT_POSITIVITY_THRESHOLD; }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullObjectMatrix() { CDOG.evaluate((DoubleMatrix2D) null); }
@Test public void recoverOrginal() { final CholeskyDecompositionResult result = CDOG.evaluate(A3); final DoubleMatrix2D a = (DoubleMatrix2D) ALGEBRA.multiply(result.getL(), result.getLT()); checkEquals(A3, a); }
@Test public void solveVector() { final CholeskyDecompositionResult result = CDOG.evaluate(A5); double[] b = new double[] {1.0, 2.0, 3.0, 4.0, -1.0}; double[] x = result.solve(b); DoubleMatrix1D ax = (DoubleMatrix1D) ALGEBRA.multiply(A5, new DoubleMatrix1D(x)); ArrayAsserts.assertArrayEquals("Cholesky decomposition OpenGamma - solve", b, ax.getData(), 1.0E-10); }
@Test public void solveMatrix() { final CholeskyDecompositionResult result = CDOG.evaluate(A5); double[][] b = new double[][] { {1.0, 2.0}, {2.0, 3.0}, {3.0, 4.0}, {4.0, -2.0}, {-1.0, -1.0}}; DoubleMatrix2D x = result.solve(new DoubleMatrix2D(b)); DoubleMatrix2D ax = (DoubleMatrix2D) ALGEBRA.multiply(A5, x); ArrayAsserts.assertArrayEquals("Cholesky decomposition OpenGamma - solve", b[0], ax.getData()[0], 1.0E-10); ArrayAsserts.assertArrayEquals("Cholesky decomposition OpenGamma - solve", b[1], ax.getData()[1], 1.0E-10); }
@Test public void compareCommon() { final CholeskyDecompositionResult resultOG = CDOG.evaluate(A3); final CholeskyDecompositionResult resultC = CDC.evaluate(A3); checkEquals(resultC.getL(), resultOG.getL()); checkEquals(ALGEBRA.getTranspose(resultC.getL()), resultOG.getLT()); assertEquals("Determinant", resultC.getDeterminant(), resultOG.getDeterminant(), 1.0E-10); }
@Test(enabled = false) public void performance() { long startTime, endTime; int nbTest = 100000; CholeskyDecompositionResult resultOG3 = CDOG.evaluate(A3); CholeskyDecompositionResult resultC3 = CDC.evaluate(A3); CholeskyDecompositionResult resultOG5 = CDOG.evaluate(A5); CholeskyDecompositionResult resultC5 = CDC.evaluate(A5); startTime = System.currentTimeMillis(); for (int looptest = 0; looptest < nbTest; looptest++) { resultOG3 = CDOG.evaluate(A3); } endTime = System.currentTimeMillis(); System.out.println(nbTest + " Cholesky decomposition 3x3 (OpenGamma): " + (endTime - startTime) + " ms - " + resultOG3.getL()); startTime = System.currentTimeMillis(); for (int looptest = 0; looptest < nbTest; looptest++) { resultC3 = CDC.evaluate(A3); } endTime = System.currentTimeMillis(); System.out.println(nbTest + " Cholesky decomposition 3x3 (Common wrapper): " + (endTime - startTime) + " ms - " + resultC3.getL()); startTime = System.currentTimeMillis(); for (int looptest = 0; looptest < nbTest; looptest++) { resultOG5 = CDOG.evaluate(A5); } endTime = System.currentTimeMillis(); System.out.println(nbTest + " Cholesky decomposition 5x5 (OpenGamma): " + (endTime - startTime) + " ms - " + resultOG5.getL()); startTime = System.currentTimeMillis(); for (int looptest = 0; looptest < nbTest; looptest++) { resultC5 = CDC.evaluate(A5); } endTime = System.currentTimeMillis(); System.out.println(nbTest + " Cholesky decomposition 5x5 (Common wrapper): " + (endTime - startTime) + " ms - " + resultC5.getL()); }