public void CholeskyDecompositionConstructorTest3()
{
float[][] value = // not positive-definite
{
new float[] { 6, -1, 2, 6 },
new float[] { -1, 3, -3, -2 },
new float[] { 2, -3, 2, 0 },
new float[] { 6, -2, 0, 0 },
};
float[][] expected =
{
new float[] { 1.0000f, 0f, 0f, 0f },
new float[] { -0.1667f, 1.0000f, 0f, 0f },
new float[] { 0.3333f, -0.9412f, 1.0000f, 0f },
new float[] { 1.0000f, -0.3529f, 2.5000f, 1.0000f },
};
float[][] diagonal =
{
new float[] { 6.0000f, 0f, 0f, 0f },
new float[] { 0f, 2.8333f, 0f, 0f },
new float[] { 0f, 0f, -1.1765f, 0f },
new float[] { 0f, 0f, 0f, 1.0000f },
};
var chol = new JaggedCholeskyDecompositionF(value, robust: true);
float[][] L = chol.LeftTriangularFactor;
float[][] D = chol.DiagonalMatrix;
Assert.IsTrue(Matrix.IsEqual(L, expected, 1e-3f));
Assert.IsTrue(Matrix.IsEqual(D, diagonal, 1e-3f));
// Decomposition Identity
Assert.IsTrue(Matrix.IsEqual(Matrix.Multiply(Matrix.Multiply(L, D), L.Transpose()), value, 1e-3f));
Assert.IsTrue(Matrix.IsEqual(chol.Reverse(), value, 1e-3f));
Assert.AreEqual(new JaggedLuDecompositionF(value).Determinant, chol.Determinant, 1e-4f);
Assert.IsFalse(chol.IsPositiveDefinite);
}