public void JaggedCholeskyDecompositionConstructorTest2()
{
double[,] value = // positive-definite
{
{ 2, -1, 0 },
{ -1, 2, -1 },
{ 0, -1, 2 }
};
double[,] expected =
{
{ 1.0000, 0.0000, 0.0000 },
{ -0.5000, 1.0000, 0.0000 },
{ 0.0000, -0.6667, 1.0000 }
};
double[,] diagonal =
{
{ 2.0000, 0.0000, 0.0000 },
{ 0.0000, 1.5000, 0.0000 },
{ 0.0000, 0.0000, 1.3333 },
};
var chol = new JaggedCholeskyDecomposition(value.ToJagged(), true);
double[][] L = chol.LeftTriangularFactor;
double[][] D = chol.DiagonalMatrix;
Assert.IsTrue(Matrix.IsEqual(L, expected, 0.001));
Assert.IsTrue(Matrix.IsEqual(D, diagonal, 0.001));
// Decomposition Identity
Assert.IsTrue(Matrix.IsEqual(Matrix.Multiply(Matrix.Multiply(L, D), L.Transpose()), value, 0.001));
Assert.IsTrue(Matrix.IsEqual(chol.Reverse(), value, 1e-6));
Assert.AreEqual(new LuDecomposition(value).Determinant, chol.Determinant, 1e-10);
Assert.IsTrue(chol.IsPositiveDefinite);
}