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

CholeskyDecompositionConstructorTest3() private method

private CholeskyDecompositionConstructorTest3 ( ) : void
return void
        public void CholeskyDecompositionConstructorTest3()
        {
            double[,] value = // not positive-definite
            {
               {  6, -1,  2,  6 },
               { -1,  3, -3, -2 },
               {  2, -3,  2,  0 },
               {  6, -2,  0,  0 },
            };

            double[,] expected =
            {
                {  1.0000,         0,         0,         0 },
                { -0.1667,    1.0000,         0,         0 },
                {  0.3333,   -0.9412,    1.0000,         0 },
                {  1.0000,   -0.3529,    2.5000,    1.0000 },
            };

            double[,] diagonal =
            {
                { 6.0000,         0,         0,         0 },
                {      0,    2.8333,         0,         0 },
                {      0,         0,   -1.1765,         0 },
                {      0,         0,         0,    1.0000 },
            };

            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.IsFalse(chol.IsPositiveDefinite);

            // Decomposition Identity
            Assert.IsTrue(Matrix.IsEqual(L.Multiply(D).Multiply(L.Transpose()), value, 0.001));
            Assert.IsTrue(Matrix.IsEqual(chol.Reverse(), value, 1e-6));

            Assert.AreEqual(new LuDecomposition(value).Determinant, chol.Determinant, 1e-10);
        }