public void InverseTest()
        {
            var value = new double[][]
            { 
                  new double[] { 1.0, 1.0 },
                  new double[] { 2.0, 2.0 }
            };

            var target = new JaggedSingularValueDecomposition(value);

            var expected = new double[][]
            {
               new double[] { 0.1, 0.2 },
               new double[] { 0.1, 0.2 }
            };

            var actual = target.Solve(Matrix.JaggedIdentity(2));
            Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-3));
            Assert.IsTrue(Matrix.IsEqual(value, target.Reverse(), 1e-5));
            actual = target.Inverse();
            Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-3));
        }
Esempio n. 2
0
        public void InverseTest2()
        {
            int n = 5;

            var I = Jagged.Identity(n);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    double[][] value = Jagged.Magic(n);

                    var target = new JaggedSingularValueDecomposition(value);

                    double[][] solution = target.Solve(I);
                    double[][] inverse  = target.Inverse();
                    double[][] reverse  = target.Reverse();

                    Assert.IsTrue(Matrix.IsEqual(solution, inverse, 1e-4));
                    Assert.IsTrue(Matrix.IsEqual(value, reverse, 1e-4));
                }
            }
        }
Esempio n. 3
0
        public void InverseTest()
        {
            var value = new double[][]
            {
                new double[] { 1.0, 1.0 },
                new double[] { 2.0, 2.0 }
            };

            var target = new JaggedSingularValueDecomposition(value);

            var expected = new double[][]
            {
                new double[] { 0.1, 0.2 },
                new double[] { 0.1, 0.2 }
            };

            var actual = target.Solve(Matrix.JaggedIdentity(2));

            Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-3));
            Assert.IsTrue(Matrix.IsEqual(value, target.Reverse(), 1e-5));
            actual = target.Inverse();
            Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-3));
        }
Esempio n. 4
0
        public void InverseTestNaN()
        {
            int n = 5;

            var I = Matrix.Identity(n).ToJagged();

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    double[][] value = Matrix.Magic(n).ToJagged();

                    value[i][j] = double.NaN;

                    var target = new JaggedSingularValueDecomposition(value);

                    double[][] solution = target.Solve(I);
                    double[][] inverse  = target.Inverse();

                    Assert.IsTrue(Matrix.IsEqual(solution, inverse));
                }
            }
        }
        public void InverseTestNaN()
        {
            int n = 5;

            var I = Matrix.Identity(n).ToArray();

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    double[][] value = Matrix.Magic(n).ToArray();

                    value[i][j] = double.NaN;

                    var target = new JaggedSingularValueDecomposition(value);

                    double[][] solution = target.Solve(I);
                    double[][] inverse = target.Inverse();

                    Assert.IsTrue(Matrix.IsEqual(solution, inverse));
                }
            }
        }
        public void InverseTest2()
        {
            int n = 5;

            var I = Jagged.Identity(n);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    double[][] value = Jagged.Magic(n);

                    var target = new JaggedSingularValueDecomposition(value);

                    double[][] solution = target.Solve(I);
                    double[][] inverse = target.Inverse();
                    double[][] reverse = target.Reverse();

                    Assert.IsTrue(Matrix.IsEqual(solution, inverse, 1e-4));
                    Assert.IsTrue(Matrix.IsEqual(value, reverse, 1e-4));
                }
            }
        }