当前位置: 首页>>代码示例>>C#>>正文


C# SingularValueDecomposition.Inverse方法代码示例

本文整理汇总了C#中Accord.Math.Decompositions.SingularValueDecomposition.Inverse方法的典型用法代码示例。如果您正苦于以下问题:C# SingularValueDecomposition.Inverse方法的具体用法?C# SingularValueDecomposition.Inverse怎么用?C# SingularValueDecomposition.Inverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Accord.Math.Decompositions.SingularValueDecomposition的用法示例。


在下文中一共展示了SingularValueDecomposition.Inverse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InverseTest

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

            SingularValueDecomposition target = new SingularValueDecomposition(value);

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

            double[,] actual = target.Solve(Matrix.Identity(2));
            Assert.IsTrue(Matrix.IsEqual(expected, actual, 0.001));

            actual = target.Inverse();
            Assert.IsTrue(Matrix.IsEqual(expected, actual, 0.001));
        }
开发者ID:KommuSoft,项目名称:accord_framework,代码行数:22,代码来源:SingularValueDecompositionTest.cs

示例2: InverseTest2

        public void InverseTest2()
        {
            int n = 5;

            var I = Matrix.Identity(n);

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

                    var target = new SingularValueDecomposition(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));
                }
            }
        }
开发者ID:accord-net,项目名称:framework,代码行数:23,代码来源:SingularValueDecompositionTest.cs

示例3: MahalanobisTest3

        public void MahalanobisTest3()
        {
            // Example from Statistical Distance Calculator
            // http://maplepark.com/~drf5n/cgi-bin/dist.cgi

            double[,] cov = 
            {
                { 1.030303, 2.132728, 0.576716 },
                { 2.132728, 4.510515, 1.185771 },
                { 0.576716, 1.185771, 0.398922 }
            };



            double[] x, y;
            double actual, expected;

            var svd = new SingularValueDecomposition(cov, true, true, true);

            var inv = cov.Inverse();
            var pinv = svd.Inverse();
            Assert.IsTrue(inv.IsEqual(pinv, 1e-6));

            x = new double[] { 2, 4, 1 };
            y = new double[] { 0, 0, 0 };

            {
                var bla = cov.Solve(x);
                var blo = svd.Solve(x);
                var ble = inv.Multiply(x);
                var bli = pinv.Multiply(x);

                Assert.IsTrue(bla.IsEqual(blo, 1e-6));
                Assert.IsTrue(bla.IsEqual(ble, 1e-6));
                Assert.IsTrue(bla.IsEqual(bli, 1e-6));
            }

            expected = 2.0773536867741504;
            actual = Distance.Mahalanobis(x, y, inv);
            Assert.AreEqual(expected, actual, 1e-6);

            actual = Distance.Mahalanobis(x, y, svd);
            Assert.AreEqual(expected, actual, 1e-6);


            x = new double[] { 7, 5, 1 };
            y = new double[] { 1, 0.52, -79 };

            expected = 277.8828871106366;
            actual = Distance.Mahalanobis(x, y, inv);
            Assert.AreEqual(expected, actual, 1e-5);
            actual = Distance.Mahalanobis(x, y, svd);
            Assert.AreEqual(expected, actual, 1e-5);
        }
开发者ID:accord-net,项目名称:framework,代码行数:54,代码来源:DistanceTest.cs


注:本文中的Accord.Math.Decompositions.SingularValueDecomposition.Inverse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。