Accord.Math.Decompositions.CholeskyDecomposition.Inverse C# (CSharp) Méthode

Inverse() public méthode

Computes the inverse of the matrix given to the Cholesky decomposition.
public Inverse ( ) : ].double[
Résultat ].double[
        public double[,] Inverse()
        {
            if (!symmetric)
            {
                throw new InvalidOperationException("Matrix is not symmetric.");
            }

            if (!robust && !positiveDefinite)
            {
                throw new InvalidOperationException("Matrix is not positive definite.");
            }

            int dimension = L.GetLength(0);

            double[,] B = Matrix.Identity(dimension);


            // Solve L*Y = B;
            for (int k = 0; k < dimension; k++)
            {
                for (int j = 0; j < k; j++)
                {
                    for (int i = 0; i < k; i++)
                        B[k, j] -= B[i, j]*L[k, i];

                    B[k, j] /= L[k, k];
                }
            }

            if (robust)
            {
                for (int k = 0; k < dimension; k++)
                    for (int j = 0; j <= k; j++)
                        B[k, j] /= D[k];
            }

            // Solve L'*X = Y;
            for (int k = dimension - 1; k >= 0; k--)
            {
                for (int j = 0; j < dimension; j++)
                {
                    for (int i = k + 1; i < dimension; i++)
                        B[k, j] -= B[i, j]*L[i, k];

                    B[k, j] /= L[k, k];
                }
            }

            return B;
        }
    }

Usage Example

        public void InverseTest1()
        {
            double[,] value = // positive-definite
            {
                {  2, -1,  0 },
                { -1,  2, -1 },
                {  0, -1,  2 }
            };

            var chol = new CholeskyDecomposition(value, robust: false);
            Assert.IsTrue(chol.IsPositiveDefinite);
            var L = chol.LeftTriangularFactor;

            float[][] expected =
            {
                new float[] { 0.750f, 0.500f, 0.250f },
                new float[] { 0.500f, 1.000f, 0.500f },
                new float[] { 0.250f, 0.500f, 0.750f },
            };

            double[,] actual = chol.Inverse();
            Assert.IsTrue(actual.IsEqual(expected, 1e-6));

            double[,] inv = chol.Solve(Matrix.Identity(3));
            Assert.IsTrue(inv.IsEqual(expected, 1e-6));
        }
All Usage Examples Of Accord.Math.Decompositions.CholeskyDecomposition::Inverse