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

CholeskyDecompositionConstructorTest4() private method

private CholeskyDecompositionConstructorTest4 ( ) : void
return void
        public void CholeskyDecompositionConstructorTest4()
        {
            // Based on tests by Ken Johnson

            double[,] value = // positive-definite
            {
               {  2,  0,  0 },
               { -1,  2,  0 },
               {  0, -1,  2 }
            };

            double[,] expected =
            {
                {  1.4142,  0.0000, 0.0000 },
                { -0.7071,  1.2247, 0.0000 },
                {  0.0000, -0.8165, 1.1547 }
            };


            var chol = new CholeskyDecomposition(value, false, valueType: MatrixType.LowerTriangular);
            double[,] L = chol.LeftTriangularFactor;

            Assert.IsTrue(Matrix.IsEqual(L, expected, 1e-4));
            Assert.AreEqual(4, chol.Determinant, 1e-10);
            Assert.IsTrue(chol.IsPositiveDefinite);
            Assert.IsTrue(Matrix.IsEqual(chol.Reverse(), value.GetSymmetric(type: MatrixType.LowerTriangular), 1e-4));


            double[,] expected2 =
            {
                 {  1.0000,  0.0000,  0.0000 },
                 { -0.5000,  1.0000,  0.0000 },
                 {  0.0000, -0.6667,  1.0000 }
            };

            chol = new CholeskyDecomposition(value, robust: true, valueType: MatrixType.LowerTriangular);
            L = chol.LeftTriangularFactor;

            Assert.IsTrue(Matrix.IsEqual(L, expected2, 1e-4));
            Assert.IsTrue(Matrix.IsEqual(chol.Reverse(), value.GetSymmetric(type: MatrixType.LowerTriangular), 1e-6));
            Assert.IsTrue(chol.IsPositiveDefinite);

            Assert.AreEqual(4, chol.Determinant, 1e-10);
        }