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


C# UserDefinedMatrix.Svd方法代码示例

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


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

示例1: CanFactorizeRandomMatrix

        public void CanFactorizeRandomMatrix(int row, int column)
        {
            var matrixA = new UserDefinedMatrix(Matrix<double>.Build.Random(row, column, 1).ToArray());
            var factorSvd = matrixA.Svd();
            var u = factorSvd.U;
            var vt = factorSvd.VT;
            var w = factorSvd.W;

            // Make sure the U has the right dimensions.
            Assert.AreEqual(row, u.RowCount);
            Assert.AreEqual(row, u.ColumnCount);

            // Make sure the VT has the right dimensions.
            Assert.AreEqual(column, vt.RowCount);
            Assert.AreEqual(column, vt.ColumnCount);

            // Make sure the W has the right dimensions.
            Assert.AreEqual(row, w.RowCount);
            Assert.AreEqual(column, w.ColumnCount);

            // Make sure the U*W*VT is the original matrix.
            var matrix = u*w*vt;
            for (var i = 0; i < matrix.RowCount; i++)
            {
                for (var j = 0; j < matrix.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixA[i, j], matrix[i, j], 1.0e-11);
                }
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:30,代码来源:UserSvdTests.cs

示例2: CanCheckRankOfNonSquare

        public void CanCheckRankOfNonSquare(int row, int column)
        {
            var matrixA = new UserDefinedMatrix(Matrix<float>.Build.Random(row, column, 1).ToArray());
            var factorSvd = matrixA.Svd();

            var mn = Math.Min(row, column);
            Assert.AreEqual(factorSvd.Rank, mn);
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:8,代码来源:UserSvdTests.cs

示例3: CanCheckRankOfSquareSingular

        public void CanCheckRankOfSquareSingular(int order)
        {
            var matrixA = new UserDefinedMatrix(order, order);
            matrixA[0, 0] = 1;
            matrixA[order - 1, order - 1] = 1;
            for (var i = 1; i < order - 1; i++)
            {
                matrixA[i, i - 1] = 1;
                matrixA[i, i + 1] = 1;
                matrixA[i - 1, i] = 1;
                matrixA[i + 1, i] = 1;
            }

            var factorSvd = matrixA.Svd();

            Assert.AreEqual(factorSvd.Determinant, 0);
            Assert.AreEqual(factorSvd.Rank, order - 1);
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:18,代码来源:UserSvdTests.cs

示例4: CanCheckRankOfSquareSingular

        public void CanCheckRankOfSquareSingular([Values(10, 50, 100)] int order)
        {
            var matrixA = new UserDefinedMatrix(order, order);
            matrixA[0, 0] = 1;
            matrixA[order - 1, order - 1] = 1;
            for (var i = 1; i < order - 1; i++)
            {
                matrixA[i, i - 1] = 1;
                matrixA[i, i + 1] = 1;
                matrixA[i - 1, i] = 1;
                matrixA[i + 1, i] = 1;
            }

            var factorSvd = matrixA.Svd(true);

            Assert.AreEqual(factorSvd.Determinant, Complex32.Zero);
            Assert.AreEqual(factorSvd.Rank, order - 1);
        }
开发者ID:jvangael,项目名称:mathnet-numerics,代码行数:18,代码来源:UserSvdTests.cs

示例5: SolveVectorIfVectorsNotComputedThrowsInvalidOperationException

        public void SolveVectorIfVectorsNotComputedThrowsInvalidOperationException()
        {
            var matrixA = new UserDefinedMatrix(Matrix<float>.Build.Random(10, 10, 1).ToArray());
            var factorSvd = matrixA.Svd(false);

            var vectorb = new UserDefinedVector(Vector<float>.Build.Random(10, 1).ToArray());
            Assert.That(() => factorSvd.Solve(vectorb), Throws.InvalidOperationException);
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:8,代码来源:UserSvdTests.cs

示例6: CanSolveForRandomVectorWhenResultVectorGiven

        public void CanSolveForRandomVectorWhenResultVectorGiven(int row, int column)
        {
            var matrixA = new UserDefinedMatrix(Matrix<float>.Build.Random(row, column, 1).ToArray());
            var matrixACopy = matrixA.Clone();
            var factorSvd = matrixA.Svd();
            var vectorb = new UserDefinedVector(Vector<float>.Build.Random(row, 1).ToArray());
            var vectorbCopy = vectorb.Clone();
            var resultx = new UserDefinedVector(column);
            factorSvd.Solve(vectorb, resultx);

            var matrixBReconstruct = matrixA*resultx;

            // Check the reconstruction.
            for (var i = 0; i < vectorb.Count; i++)
            {
                Assert.AreEqual(vectorb[i], matrixBReconstruct[i], 1e-4);
            }

            // Make sure A didn't change.
            for (var i = 0; i < matrixA.RowCount; i++)
            {
                for (var j = 0; j < matrixA.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixACopy[i, j], matrixA[i, j]);
                }
            }

            // Make sure b didn't change.
            for (var i = 0; i < vectorb.Count; i++)
            {
                Assert.AreEqual(vectorbCopy[i], vectorb[i]);
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:33,代码来源:UserSvdTests.cs

示例7: CanSolveForRandomMatrixWhenResultMatrixGiven

        public void CanSolveForRandomMatrixWhenResultMatrixGiven(int row, int column)
        {
            var matrixA = new UserDefinedMatrix(Matrix<float>.Build.Random(row, column, 1).ToArray());
            var matrixACopy = matrixA.Clone();
            var factorSvd = matrixA.Svd();

            var matrixB = new UserDefinedMatrix(Matrix<float>.Build.Random(row, column, 1).ToArray());
            var matrixBCopy = matrixB.Clone();

            var matrixX = new UserDefinedMatrix(column, column);
            factorSvd.Solve(matrixB, matrixX);

            // The solution X row dimension is equal to the column dimension of A
            Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);

            // The solution X has the same number of columns as B
            Assert.AreEqual(matrixB.ColumnCount, matrixX.ColumnCount);

            var matrixBReconstruct = matrixA*matrixX;

            // Check the reconstruction.
            for (var i = 0; i < matrixB.RowCount; i++)
            {
                for (var j = 0; j < matrixB.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixB[i, j], matrixBReconstruct[i, j], 1e-4);
                }
            }

            // Make sure A didn't change.
            for (var i = 0; i < matrixA.RowCount; i++)
            {
                for (var j = 0; j < matrixA.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixACopy[i, j], matrixA[i, j]);
                }
            }

            // Make sure B didn't change.
            for (var i = 0; i < matrixB.RowCount; i++)
            {
                for (var j = 0; j < matrixB.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixBCopy[i, j], matrixB[i, j]);
                }
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:47,代码来源:UserSvdTests.cs

示例8: CanCheckRankSquare

        public void CanCheckRankSquare(int order)
        {
            var matrixA = new UserDefinedMatrix(Matrix<float>.Build.Random(order, order, 1).ToArray());
            var factorSvd = matrixA.Svd();

            if (factorSvd.Determinant != 0)
            {
                Assert.AreEqual(factorSvd.Rank, order);
            }
            else
            {
                Assert.AreEqual(factorSvd.Rank, order - 1);
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:14,代码来源:UserSvdTests.cs

示例9: CanSolveForRandomVector

        public void CanSolveForRandomVector(int row, int column)
        {
            var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.Random(row, column, 1).ToArray());
            var matrixACopy = matrixA.Clone();
            var factorSvd = matrixA.Svd();

            var vectorb = new UserDefinedVector(Vector<Complex>.Build.Random(row, 1).ToArray());
            var resultx = factorSvd.Solve(vectorb);

            Assert.AreEqual(matrixA.ColumnCount, resultx.Count);

            var matrixBReconstruct = matrixA*resultx;

            // Check the reconstruction.
            for (var i = 0; i < vectorb.Count; i++)
            {
                AssertHelpers.AlmostEqual(vectorb[i], matrixBReconstruct[i], 10);
            }

            // Make sure A didn't change.
            for (var i = 0; i < matrixA.RowCount; i++)
            {
                for (var j = 0; j < matrixA.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixACopy[i, j], matrixA[i, j]);
                }
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:28,代码来源:UserSvdTests.cs

示例10: SolveMatrixIfVectorsNotComputedThrowsInvalidOperationException

        public void SolveMatrixIfVectorsNotComputedThrowsInvalidOperationException()
        {
            var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.Random(10, 9, 1).ToArray());
            var factorSvd = matrixA.Svd(false);

            var matrixB = new UserDefinedMatrix(Matrix<Complex>.Build.Random(10, 9, 1).ToArray());
            Assert.That(() => factorSvd.Solve(matrixB), Throws.InvalidOperationException);
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:8,代码来源:UserSvdTests.cs


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