예제 #1
0
        public void InverseTest1()
        {
            float[][] value = // positive-definite
            {
                new float[] {  2, -1,  0 },
                new float[] { -1,  2, -1 },
                new float[] {  0, -1,  2 }
            };

            JaggedCholeskyDecompositionF chol = new JaggedCholeskyDecompositionF(value, robust: false);

            float[][] 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 },
            };

            float[][] actual = chol.Inverse();

            for (int i = 0; i < actual.Length; i++)
            {
                for (int j = 0; j < actual.Length; j++)
                {
                    Assert.AreEqual(expected[i][j], actual[i][j], 1e-6f);
                }
            }
        }
예제 #2
0
        public void InverseTest()
        {
            float[][] value = // not positive-definite
            {
                new float[] {  6, -1,  2,  6 },
                new float[] { -1,  3, -3, -2 },
                new float[] {  2, -3,  2,  0 },
                new float[] {  6, -2,  0,  0 },
            };

            JaggedCholeskyDecompositionF chol = new JaggedCholeskyDecompositionF(value, robust: true);

            float[][] L = chol.LeftTriangularFactor;

            float[][] expected =
            {
                new float[] {  0.400f,  1.200f,  1.400f, -0.500f },
                new float[] {  1.200f,  3.600f,  4.200f, -2.000f },
                new float[] {  1.400f,  4.200f,  5.400f, -2.500f },
                new float[] { -0.500f, -2.000f, -2.500f,  1.000f },
            };

            float[][] actual = chol.Inverse();

            Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-6f));
        }
예제 #3
0
        public void InverseTest1()
        {
            float[][] value = // positive-definite
            {
                new float[] {  2, -1,  0 },
                new float[] { -1,  2, -1 },
                new float[] {  0, -1,  2 }
            };

            var chol = new JaggedCholeskyDecompositionF(value, robust: false);

            Assert.IsTrue(chol.IsPositiveDefinite);
            float[][] 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 },
            };

            float[][] actual = chol.Inverse();
            Assert.IsTrue(actual.IsEqual(expected, 1e-5f));

            float[][] inv = chol.Solve(Jagged.Identity <float>(3));
            Assert.IsTrue(inv.IsEqual(expected, 1e-5f));
        }
        public void InverseTest1()
        {
            float[][] value = // positive-definite
            {
               new float[] {  2, -1,  0 },
               new float[] { -1,  2, -1 },
               new float[] {  0, -1,  2 }
            };

            JaggedCholeskyDecompositionF chol = new JaggedCholeskyDecompositionF(value, robust: false);
            float[][] 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 },
            };

            float[][] actual = chol.Inverse();

            for (int i = 0; i < actual.Length; i++)
                for (int j = 0; j < actual.Length; j++)
                    Assert.AreEqual(expected[i][j], actual[i][j], 1e-6f);
        }
        public void InverseTest()
        {
            float[][] value = // not positive-definite
            {
               new float[] {  6, -1,  2,  6 },
               new float[] { -1,  3, -3, -2 },
               new float[] {  2, -3,  2,  0 },
               new float[] {  6, -2,  0,  0 },
            };

            JaggedCholeskyDecompositionF chol = new JaggedCholeskyDecompositionF(value, robust: true);
            float[][] L = chol.LeftTriangularFactor;

            float[][] expected =
            {
                new float[] {  0.400f,  1.200f,  1.400f, -0.500f },
                new float[] {  1.200f,  3.600f,  4.200f, -2.000f },
                new float[] {  1.400f,  4.200f,  5.400f, -2.500f },
                new float[] { -0.500f, -2.000f, -2.500f,  1.000f },
            };

            float[][] actual = chol.Inverse();

            Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-6f));
        }
        public void InverseTest1()
        {
            float[][] value = // positive-definite
            {
               new float[] {  2, -1,  0 },
               new float[] { -1,  2, -1 },
               new float[] {  0, -1,  2 }
            };

            var chol = new JaggedCholeskyDecompositionF(value, robust: false);
            Assert.IsTrue(chol.IsPositiveDefinite);
            float[][] 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 },
            };

            float[][] actual = chol.Inverse();
            Assert.IsTrue(actual.IsEqual(expected, 1e-5f));

            float[][] inv = chol.Solve(Jagged.Identity<float>(3));
            Assert.IsTrue(inv.IsEqual(expected, 1e-5f));
        }