public void CholeskyDecompositionFConstructorTest2()
{
float[][] value = // positive-definite
{
new float[] { 2, -1, 0 },
new float[] { -1, 2, -1 },
new float[] { 0, -1, 2 }
};
float[][] expected =
{
new float[] { 1.0000f, 0.0000f, 0.0000f },
new float[] { -0.5000f, 1.0000f, 0.0000f },
new float[] { 0.0000f, -0.6667f, 1.0000f }
};
float[][] diagonal =
{
new float[] { 2.0000f, 0.0000f, 0.0000f },
new float[] { 0.0000f, 1.5000f, 0.0000f },
new float[] { 0.0000f, 0.0000f, 1.3333f },
};
var chol = new JaggedCholeskyDecompositionF(value, true);
float[][] L = chol.LeftTriangularFactor;
float[][] D = chol.DiagonalMatrix;
Assert.IsTrue(Matrix.IsEqual(L, expected, 0.001f));
Assert.IsTrue(Matrix.IsEqual(D, diagonal, 0.001f));
// 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-10);
Assert.IsTrue(chol.IsPositiveDefinite);
}