• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Solvers.Iterator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: DetermineStatus

        public void DetermineStatus()
        {
            var criteria = new List<IIterationStopCriterium<Complex32>>
            {
                new FailureStopCriterium(),
                new DivergenceStopCriterium(),
                new IterationCountStopCriterium<Complex32>(1)
            };

            var iterator = new Iterator<Complex32>(criteria);

            // First step, nothing should happen.
            iterator.DetermineStatus(
                0,
                DenseVector.Create(3, i => 4),
                DenseVector.Create(3, i => 4),
                DenseVector.Create(3, i => 4));
            Assert.AreEqual(IterationStatus.Continue, iterator.Status, "Incorrect status");

            // Second step, should run out of iterations.
            iterator.DetermineStatus(
                1,
                DenseVector.Create(3, i => 4),
                DenseVector.Create(3, i => 4),
                DenseVector.Create(3, i => 4));
            Assert.AreEqual(IterationStatus.StoppedWithoutConvergence, iterator.Status, "Incorrect status");
        }
开发者ID:TransientResponse,项目名称:mathnet-numerics,代码行数:27,代码来源:IteratorTest.cs


示例2: CreateDefault

        /// <summary>
        /// Creates a default iterator with all the <see cref="IIterationStopCriterium"/> objects.
        /// </summary>
        /// <returns>A new <see cref="IIterator"/> object.</returns>
        public static IIterator CreateDefault()
        {
            var iterator = new Iterator();
            iterator.Add(new FailureStopCriterium());
            iterator.Add(new DivergenceStopCriterium());
            iterator.Add(new IterationCountStopCriterium());
            iterator.Add(new ResidualStopCriterium());

            return iterator;
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:14,代码来源:Iterator.cs


示例3: 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<Complex32>(new IIterationStopCriterium<Complex32>[]
                    {
                        new IterationCountStopCriterium<Complex32>(1000),
                        new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration))
                    });
                var solver = new TFQMR(monitor);
                var matrixX = solver.Solve(matrixA, matrixB);

                if (!monitor.HasConverged)
                {
                    // 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.AreEqual(matrixB[i, j].Real, matrixBReconstruct[i, j].Real, (float) Math.Pow(1.0/10.0, iteration - 3));
                        Assert.AreEqual(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:primebing,项目名称:mathnet-numerics,代码行数:44,代码来源:TFQMRTest.cs


示例4: 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<Complex32>(new IIterationStopCriterium<Complex32>[]
                    {
                        new IterationCountStopCriterium<Complex32>(1000),
                        new ResidualStopCriterium((float) Math.Pow(1.0/10.0, iteration)),
                    });
                var solver = new GpBiCg(monitor);

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

                if (!monitor.HasConverged)
                {
                    // 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:primebing,项目名称:mathnet-numerics,代码行数:37,代码来源:GpBiCgTest.cs


示例5: 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 IterationCountStopCriterium<Complex32>(1000),
                    new ResidualStopCriterium<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:rmundy,项目名称:mathnet-numerics,代码行数:36,代码来源:GpBiCgTest.cs


示例6: SolveUnitMatrixAndBackMultiply

        public void SolveUnitMatrixAndBackMultiply()
        {
            // Create the identity matrix
            var matrix = SparseMatrix.Identity(100);

            // Create the y vector
            var y = DenseVector.Create(matrix.RowCount, i => 1);

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

            var solver = new TFQMR(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.HasConverged, "#04");

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


示例7: SolvePoissonMatrixAndBackMultiply

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

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

            // 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
            var y = DenseVector.Create(matrix.RowCount, i => 1);

            // Create an iteration monitor which will keep track of iterative convergence
            var monitor = new Iterator<Complex32>(new IIterationStopCriterium<Complex32>[]
                {
                    new IterationCountStopCriterium<Complex32>(MaximumIterations),
                    new ResidualStopCriterium(ConvergenceBoundary),
                    new DivergenceStopCriterium(),
                    new FailureStopCriterium()
                });
            var solver = new TFQMR(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.HasConverged, "#04");

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


示例8: SolveUnitMatrixAndBackMultiply

        public void SolveUnitMatrixAndBackMultiply()
        {
            // Create the identity matrix
            var matrix = SparseMatrix.CreateIdentity(100);

            // Create the y vector
            var y = DenseVector.Create(matrix.RowCount, i => Complex32.One);

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

            var solver = new BiCgStab();

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

            // 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 == IterationStatus.Converged, "#04");

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


示例9: DetermineStatusWithNegativeIterationNumberThrowsArgumentOutOfRangeException

        public void DetermineStatusWithNegativeIterationNumberThrowsArgumentOutOfRangeException()
        {
            var criteria = new List<IIterationStopCriterium<Complex32>>
            {
                new FailureStopCriterium(),
                new DivergenceStopCriterium(),
                new IterationCountStopCriterium<Complex32>(),
                new ResidualStopCriterium()
            };
            var iterator = new Iterator<Complex32>(criteria);

            Assert.Throws<ArgumentOutOfRangeException>(() => iterator.DetermineStatus(
                -1,
                DenseVector.Create(3, i => 4),
                DenseVector.Create(3, i => 5),
                DenseVector.Create(3, i => 6)));
        }
开发者ID:TransientResponse,项目名称:mathnet-numerics,代码行数:17,代码来源:IteratorTest.cs


示例10: ResetToPrecalculationState

        public void ResetToPrecalculationState()
        {
            var criteria = new List<IIterationStopCriterium<Complex32>>
            {
                new FailureStopCriterium(),
                new DivergenceStopCriterium(),
                new IterationCountStopCriterium<Complex32>(1)
            };

            var iterator = new Iterator<Complex32>(criteria);

            // First step, nothing should happen.
            iterator.DetermineStatus(
                0,
                DenseVector.Create(3, i => 4),
                DenseVector.Create(3, i => 4),
                DenseVector.Create(3, i => 4));
            Assert.AreEqual(IterationStatus.Continue, iterator.Status, "Incorrect status");

            iterator.Reset();
            Assert.AreEqual(IterationStatus.Continue, iterator.Status, "Incorrect status");
            Assert.AreEqual(IterationStatus.Continue, criteria[0].Status, "Incorrect status");
            Assert.AreEqual(IterationStatus.Continue, criteria[1].Status, "Incorrect status");
            Assert.AreEqual(IterationStatus.Continue, criteria[2].Status, "Incorrect status");
        }
开发者ID:TransientResponse,项目名称:mathnet-numerics,代码行数:25,代码来源:IteratorTest.cs


示例11: DetermineStatusWithoutStopCriteriaDoesNotThrow

 public void DetermineStatusWithoutStopCriteriaDoesNotThrow()
 {
     var iterator = new Iterator<Complex32>();
     Assert.DoesNotThrow(() => iterator.DetermineStatus(
         0,
         DenseVector.Create(3, i => 4),
         DenseVector.Create(3, i => 5),
         DenseVector.Create(3, i => 6)));
 }
开发者ID:TransientResponse,项目名称:mathnet-numerics,代码行数:9,代码来源:IteratorTest.cs


示例12: SolveUnitMatrixAndBackMultiply

        public void SolveUnitMatrixAndBackMultiply()
        {
            // Create the identity matrix
            var matrix = SparseMatrix.CreateIdentity(100);

            // Create the y vector
            var y = Vector<Complex32>.Build.Dense(matrix.RowCount, 1);

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

            var solver = new TFQMR();

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

            // 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 == IterationStatus.Converged, "#04");

            // Now compare the vectors
            Assert.LessOrEqual(Distance.Chebyshev(y, z), 2*ConvergenceBoundary);
        }
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:33,代码来源:TFQMRTest.cs


示例13: SolvePoissonMatrixAndBackMultiply

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

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

            // 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
            var y = Vector<Complex32>.Build.Dense(matrix.RowCount, 1);

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

            var solver = new TFQMR();

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

            // 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 == IterationStatus.Converged, "#04");

            // Now compare the vectors
            Assert.LessOrEqual(Distance.Chebyshev(y, z), 2*ConvergenceBoundary);
        }
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:69,代码来源:TFQMRTest.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Double.DenseMatrix类代码示例发布时间:2022-05-26
下一篇:
C# Complex32.SparseVector类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap