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


C# GpBiCg类代码示例

本文整理汇总了C#中GpBiCg的典型用法代码示例。如果您正苦于以下问题:C# GpBiCg类的具体用法?C# GpBiCg怎么用?C# GpBiCg使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: CanSolveForRandomMatrix

        public void CanSolveForRandomMatrix(int order)
        {
            var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
            var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order);

            var monitor = new Iterator<Complex>(
                new IterationCountStopCriterium<Complex>(1000),
                new ResidualStopCriterium(1e-10));

            var solver = new GpBiCg();
            var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);

            // 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].Real, matrixBReconstruct[i, j].Real, 1.0e-5);
                    Assert.AreEqual(matrixB[i, j].Imaginary, matrixBReconstruct[i, j].Imaginary, 1.0e-5);
                }
            }
        }
开发者ID:TransientResponse,项目名称:mathnet-numerics,代码行数:30,代码来源:GpBiCgTest.cs

示例2: CanSolveForRandomMatrix

        public void CanSolveForRandomMatrix(int order)
        {
            var matrixA = Matrix<double>.Build.Random(order, order, 1);
            var matrixB = Matrix<double>.Build.Random(order, order, 1);

            var monitor = new Iterator<double>(
                new IterationCountStopCriterium<double>(1000),
                new ResidualStopCriterium<double>(1e-10));

            var solver = new GpBiCg();
            var matrixX = matrixA.SolveIterative(matrixB, solver, monitor);

            // 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], 1.0e-7);
                }
            }
        }
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:29,代码来源:GpBiCgTest.cs

示例3: CanSolveForRandomMatrix

        public void CanSolveForRandomMatrix(int order)
        {
            var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
            var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order);

            var monitor = new Iterator(new IIterationStopCriterium<double>[]
                                       {
                                           new IterationCountStopCriterium(1000),
                                           new ResidualStopCriterium(1e-10)
                                       });
            var solver = new GpBiCg(monitor);
            var matrixX = solver.Solve(matrixA, matrixB);

            // 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.AreApproximatelyEqual(matrixB[i, j], matrixBReconstruct[i, j], 1.0e-7);
                }
            }
        }
开发者ID:xmap2008,项目名称:mathnet-numerics,代码行数:29,代码来源:GpBiCgTest.cs

示例4: SolveLongMatrixThrowsArgumentException

        public void SolveLongMatrixThrowsArgumentException()
        {
            var matrix = new SparseMatrix(3, 2);
            var input = new DenseVector(3);

            var solver = new GpBiCg();
            Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
        }
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:8,代码来源:GpBiCgTest.cs

示例5: SolveLongMatrixThrowsArgumentException

        public void SolveLongMatrixThrowsArgumentException()
        {
            var matrix = new SparseMatrix(3, 2);
            Vector input = new DenseVector(3);

            var solver = new GpBiCg();
            Assert.Throws<ArgumentException>(() => solver.Solve(matrix, input));
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:8,代码来源:GpBiCgTest.cs

示例6: SolveWideMatrixThrowsArgumentException

        public void SolveWideMatrixThrowsArgumentException()
        {
            var matrix = new SparseMatrix(2, 3);
            var input = new DenseVector(2);

            var solver = new GpBiCg();
            Assert.That(() => matrix.SolveIterative(input, solver), Throws.ArgumentException);
        }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:8,代码来源:GpBiCgTest.cs

示例7: CanSolveForRandomMatrix

        public void CanSolveForRandomMatrix(int order)
        {
            // Due to datatype "float" it can happen that solution will not converge for specific random matrix
            // That's why we will do 3 tries and downgrade stop criterium each time
            for (var iteration = 6; iteration > 3; iteration--)
            {
                var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
                var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order);

                var monitor = new Iterator(new IIterationStopCriterium<float>[]
                                           {
                                               new IterationCountStopCriterium(MaximumIterations),
                                               new ResidualStopCriterium((float)Math.Pow(1.0/10.0, iteration))
                                           });
                var solver = new GpBiCg(monitor);
                var matrixX = solver.Solve(matrixA, matrixB);

                if (!(monitor.Status is CalculationConverged))
                {
                    // Solution was not found, try again downgrading convergence boundary
                    continue;
                }

                // 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.AreApproximatelyEqual(matrixB[i, j], matrixBReconstruct[i, j], (float)Math.Pow(1.0 / 10.0, iteration - 3));
                    }
                }

                return;
            }

            Assert.Fail("Solution was not found in 3 tries");
        }
开发者ID:xmap2008,项目名称:mathnet-numerics,代码行数:44,代码来源:GpBiCgTest.cs

示例8: CanSolveForRandomMatrix

        public void CanSolveForRandomMatrix(int order)
        {
            for (var iteration = 5; iteration > 3; iteration--)
            {
                var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
                var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order);

                var monitor = new Iterator(new IIterationStopCriterium<Complex32>[]
                                           {
                                               new IterationCountStopCriterium(1000),
                                               new ResidualStopCriterium((float)Math.Pow(1.0 / 10.0, iteration))
                                           });
                var solver = new GpBiCg(monitor);
                var matrixX = solver.Solve(matrixA, matrixB);

                if (!(monitor.Status is CalculationConverged))
                {
                    // Solution was not found, try again downgrading convergence boundary
                    continue;
                }

                // 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.AreApproximatelyEqual(matrixB[i, j].Real, matrixBReconstruct[i, j].Real, (float)Math.Pow(1.0 / 10.0, iteration - 3));
                        Assert.AreApproximatelyEqual(matrixB[i, j].Imaginary, matrixBReconstruct[i, j].Imaginary, (float)Math.Pow(1.0 / 10.0, iteration - 3));
                    }
                }
                return;
            }

            Assert.Fail("Solution was not found in 3 tries");
        }
开发者ID:xmap2008,项目名称:mathnet-numerics,代码行数:42,代码来源:GpBiCgTest.cs

示例9: CanSolveForRandomVector

        public void CanSolveForRandomVector(int order)
        {
            var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
            var vectorb = MatrixLoader.GenerateRandomDenseVector(order);

            var monitor = new Iterator(new IIterationStopCriterium<double>[]
                                       {
                                           new IterationCountStopCriterium(1000),
                                           new ResidualStopCriterium(1e-10),
                                       });
            var solver = new GpBiCg(monitor);

            var resultx = solver.Solve(matrixA, vectorb);
            Assert.AreEqual(matrixA.ColumnCount, resultx.Count);

            var bReconstruct = matrixA * resultx;

            // Check the reconstruction.
            for (var i = 0; i < order; i++)
            {
                Assert.AreApproximatelyEqual(vectorb[i], bReconstruct[i], 1e-7);
            }
        }
开发者ID:xmap2008,项目名称:mathnet-numerics,代码行数:23,代码来源:GpBiCgTest.cs

示例10: CanSolveForRandomVector

        public void CanSolveForRandomVector(int order)
        {
            for (var iteration = 5; iteration > 3; iteration--)
            {
                var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
                var vectorb = MatrixLoader.GenerateRandomDenseVector(order);

                var monitor = new Iterator(new IIterationStopCriterium[]
                                           {
                                               new IterationCountStopCriterium(1000),
                                               new ResidualStopCriterium((float)Math.Pow(1.0 / 10.0, iteration)),
                                           });
                var solver = new GpBiCg(monitor);

                var resultx = solver.Solve(matrixA, vectorb);

                if (!(monitor.Status is CalculationConverged))
                {
                    // Solution was not found, try again downgrading convergence boundary
                    continue;
                }

                Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
                var matrixBReconstruct = matrixA * resultx;

                // Check the reconstruction.
                for (var i = 0; i < order; i++)
                {
                    Assert.AreEqual(vectorb[i].Real, matrixBReconstruct[i].Real, (float)Math.Pow(1.0 / 10.0, iteration - 3));
                    Assert.AreEqual(vectorb[i].Imaginary, matrixBReconstruct[i].Imaginary, (float)Math.Pow(1.0 / 10.0, iteration - 3));
                }

                return;
            }

            Assert.Fail("Solution was not found in 3 tries");
        }
开发者ID:nrolland,项目名称:mathnet-numerics,代码行数:37,代码来源:GpBiCgTest.cs

示例11: CanSolveForRandomVector

        public void CanSolveForRandomVector(int order)
        {
            for (var iteration = 5; iteration > 3; iteration--)
            {
                var matrixA = Matrix<Complex32>.Build.Random(order, order, 1);
                var vectorb = Vector<Complex32>.Build.Random(order, 1);

                var monitor = new Iterator<Complex32>(
                    new IterationCountStopCriterion<Complex32>(1000),
                    new ResidualStopCriterion<Complex32>(Math.Pow(1.0/10.0, iteration)));

                var solver = new GpBiCg();

                var resultx = matrixA.SolveIterative(vectorb, solver, monitor);

                if (monitor.Status != IterationStatus.Converged)
                {
                    // Solution was not found, try again downgrading convergence boundary
                    continue;
                }

                Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
                var matrixBReconstruct = matrixA*resultx;

                // Check the reconstruction.
                for (var i = 0; i < order; i++)
                {
                    Assert.AreEqual(vectorb[i].Real, matrixBReconstruct[i].Real, (float)Math.Pow(1.0/10.0, iteration - 3));
                    Assert.AreEqual(vectorb[i].Imaginary, matrixBReconstruct[i].Imaginary, (float)Math.Pow(1.0/10.0, iteration - 3));
                }

                return;
            }

            Assert.Fail("Solution was not found in 3 tries");
        }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:36,代码来源:GpBiCgTest.cs

示例12: SolveUnitMatrixAndBackMultiply

        public void SolveUnitMatrixAndBackMultiply()
        {
            // Create the identity matrix
            Matrix<double> matrix = SparseMatrix.Identity(100);

            // Create the y vector
            Vector<double> y = new DenseVector(matrix.RowCount, 1);

            // Create an iteration monitor which will keep track of iterative convergence
            var monitor = new Iterator(new IIterationStopCriterium<double>[]
                                       {
                                           new IterationCountStopCriterium(MaximumIterations),
                                           new ResidualStopCriterium(ConvergenceBoundary),
                                           new DivergenceStopCriterium(),
                                           new FailureStopCriterium()
                                       });
            var solver = new GpBiCg(monitor);

            // Solve equation Ax = y
            var x = solver.Solve(matrix, y);

            // Now compare the results
            Assert.IsNotNull(x, "#02");
            Assert.AreEqual(y.Count, x.Count, "#03");

            // Back multiply the vector
            var z = matrix.Multiply(x);

            // Check that the solution converged
            Assert.IsTrue(monitor.Status is CalculationConverged, "#04");

            // Now compare the vectors
            for (var i = 0; i < y.Count; i++)
            {
                Assert.IsTrue((y[i] - z[i]).IsSmaller(ConvergenceBoundary, 1), "#05-" + i);
            }
        }
开发者ID:xmap2008,项目名称:mathnet-numerics,代码行数:37,代码来源:GpBiCgTest.cs

示例13: SolvePoissonMatrixAndBackMultiply

        public void SolvePoissonMatrixAndBackMultiply()
        {
            // Create the matrix
            var matrix = new SparseMatrix(100);

            // Assemble the matrix. We assume we're solving the Poisson equation
            // on a rectangular 10 x 10 grid
            const int GridSize = 10;

            // The pattern is:
            // 0 .... 0 -1 0 0 0 0 0 0 0 0 -1 4 -1 0 0 0 0 0 0 0 0 -1 0 0 ... 0
            for (var i = 0; i < matrix.RowCount; i++)
            {
                // Insert the first set of -1's
                if (i > (GridSize - 1))
                {
                    matrix[i, i - GridSize] = -1;
                }

                // Insert the second set of -1's
                if (i > 0)
                {
                    matrix[i, i - 1] = -1;
                }

                // Insert the centerline values
                matrix[i, i] = 4;

                // Insert the first trailing set of -1's
                if (i < matrix.RowCount - 1)
                {
                    matrix[i, i + 1] = -1;
                }

                // Insert the second trailing set of -1's
                if (i < matrix.RowCount - GridSize)
                {
                    matrix[i, i + GridSize] = -1;
                }
            }

            // Create the y vector
            Vector<double> y = new DenseVector(matrix.RowCount, 1);

            // Create an iteration monitor which will keep track of iterative convergence
            var monitor = new Iterator(new IIterationStopCriterium<double>[]
                                       {
                                           new IterationCountStopCriterium(MaximumIterations),
                                           new ResidualStopCriterium(ConvergenceBoundary),
                                           new DivergenceStopCriterium(),
                                           new FailureStopCriterium()
                                       });

            var solver = new GpBiCg(monitor);

            // Solve equation Ax = y
            var x = solver.Solve(matrix, y);

            // Now compare the results
            Assert.IsNotNull(x, "#02");
            Assert.AreEqual(y.Count, x.Count, "#03");

            // Back multiply the vector
            var z = matrix.Multiply(x);

            // Check that the solution converged
            Assert.IsTrue(monitor.Status is CalculationConverged, "#04");

            // Now compare the vectors
            for (var i = 0; i < y.Count; i++)
            {
                Assert.IsTrue(System.Math.Abs(y[i] - z[i]).IsSmaller(ConvergenceBoundary, 1), "#05-" + i);
            }
        }
开发者ID:xmap2008,项目名称:mathnet-numerics,代码行数:74,代码来源:GpBiCgTest.cs

示例14: CanSolveForRandomVector

        public void CanSolveForRandomVector([Values(4, 8, 10)] int order)
        {
            var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
            var vectorb = MatrixLoader.GenerateRandomDenseVector(order);

            var monitor = new Iterator(new IIterationStopCriterium[]
                                       {
                                           new IterationCountStopCriterium(1000), 
                                           new ResidualStopCriterium(1e-10), 
                                       });
            var solver = new GpBiCg(monitor);

            var resultx = solver.Solve(matrixA, vectorb);
            Assert.AreEqual(matrixA.ColumnCount, resultx.Count);

            var matrixBReconstruct = matrixA * resultx;

            // Check the reconstruction.
            for (var i = 0; i < order; i++)
            {
                Assert.AreEqual(vectorb[i].Real, matrixBReconstruct[i].Real, 1e-5);
                Assert.AreEqual(vectorb[i].Imaginary, matrixBReconstruct[i].Imaginary, 1e-5);
            }
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:24,代码来源:GpBiCgTest.cs

示例15: CanSolveForRandomVector

        public void CanSolveForRandomVector(int order)
        {
            // Due to datatype "float" it can happen that solution will not converge for specific random matrix
            // That's why we will do 3 tries and downgrade stop criterion each time
            for (var iteration = 6; iteration > 3; iteration--)
            {
                var matrixA = Matrix<float>.Build.Random(order, order, 1);
                var vectorb = Vector<float>.Build.Random(order, 1);

                var monitor = new Iterator<float>(
                    new IterationCountStopCriterion<float>(MaximumIterations),
                    new ResidualStopCriterion<float>(Math.Pow(1.0/10.0, iteration)));

                var solver = new GpBiCg();
                var resultx = matrixA.SolveIterative(vectorb, solver, monitor);

                if (monitor.Status != IterationStatus.Converged)
                {
                    // Solution was not found, try again downgrading convergence boundary
                    continue;
                }

                Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
                var matrixBReconstruct = matrixA*resultx;

                // Check the reconstruction.
                for (var i = 0; i < order; i++)
                {
                    Assert.AreEqual(vectorb[i], matrixBReconstruct[i], (float)Math.Pow(1.0/10.0, iteration - 3));
                }

                return;
            }
        }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:34,代码来源:GpBiCgTest.cs


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