Accord.Tests.Math.CholeskyDecompositionTest.CholeskyDecompositionConstructorTest2 C# (CSharp) Method

CholeskyDecompositionConstructorTest2() private method

private CholeskyDecompositionConstructorTest2 ( ) : void
return void
        public void CholeskyDecompositionConstructorTest2()
        {
            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 CholeskyDecomposition(value, 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));
            Assert.IsTrue(chol.IsPositiveDefinite);

            // 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);
        }