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


C# DenseVector.L2Norm方法代码示例

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


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

示例1: TryFindRoot

        /// <summary>Find a solution of the equation f(x)=0.</summary>
        /// <param name="f">The function to find roots from.</param>
        /// <param name="initialGuess">Initial guess of the root.</param>
        /// <param name="accuracy">Desired accuracy. The root will be refined until the accuracy or the maximum number of iterations is reached.</param>
        /// <param name="maxIterations">Maximum number of iterations. Usually 100.</param>
        /// <param name="root">The root that was found, if any. Undefined if the function returns false.</param>
        /// <returns>True if a root with the specified accuracy was found, else false.</returns>
        public static bool TryFindRoot(Func<double[], double[]> f, double[] initialGuess, double accuracy, int maxIterations, out double[] root)
        {
            var x = new DenseVector(initialGuess);

            double[] y0 = f(initialGuess);
            var y = new DenseVector(y0);
            double g = y.L2Norm();

            Matrix<double> B = CalculateApproximateJacobian(f, initialGuess, y0);

            for (int i = 0; i <= maxIterations; i++)
            {
                var dx = (DenseVector) (-B.LU().Solve(y));
                var xnew = x + dx;
                var ynew = new DenseVector(f(xnew.Values));
                double gnew = ynew.L2Norm();

                if (gnew > g)
                {
                    double g2 = g*g;
                    double scale = g2/(g2 + gnew*gnew);
                    if (scale == 0.0)
                    {
                        scale = 1.0e-4;
                    }

                    dx = scale*dx;
                    xnew = x + dx;
                    ynew = new DenseVector(f(xnew.Values));
                    gnew = ynew.L2Norm();
                }

                if (gnew < accuracy)
                {
                    root = xnew.Values;
                    return true;
                }

                // update Jacobian B
                DenseVector dF = ynew - y;
                Matrix<double> dB = (dF - B.Multiply(dx)).ToColumnMatrix() * dx.Multiply(1.0 / Math.Pow(dx.L2Norm(), 2)).ToRowMatrix();
                B = B + dB;

                x = xnew;
                y = ynew;
                g = gnew;
            }

            root = null;
            return false;
        }
开发者ID:jafffy,项目名称:mathnet-numerics,代码行数:58,代码来源:Broyden.cs

示例2: PrepareResults


//.........这里部分代码省略.........

                result.AppendLine();
                result.AppendLine("Calibration Matrix: ");

                result.Append("|" + CameraInternalMatrix[0, 0].ToString("F3"));
                result.Append("; " + CameraInternalMatrix[0, 1].ToString("F3"));
                result.Append("; " + CameraInternalMatrix[0, 2].ToString("F3"));
                result.AppendLine("|");

                result.Append("|" + CameraInternalMatrix[1, 0].ToString("F3"));
                result.Append("; " + CameraInternalMatrix[1, 1].ToString("F3"));
                result.Append("; " + CameraInternalMatrix[1, 2].ToString("F3"));
                result.AppendLine("|");

                result.Append("|" + CameraInternalMatrix[2, 0].ToString("F3"));
                result.Append("; " + CameraInternalMatrix[2, 1].ToString("F3"));
                result.Append("; " + CameraInternalMatrix[2, 2].ToString("F3"));
                result.AppendLine("|");

                result.AppendLine();
                result.AppendLine("Rotation Matrix: ");

                result.Append("|" + CameraRotationMatrix[0, 0].ToString("F3"));
                result.Append("; " + CameraRotationMatrix[0, 1].ToString("F3"));
                result.Append("; " + CameraRotationMatrix[0, 2].ToString("F3"));
                result.AppendLine("|");

                result.Append("|" + CameraRotationMatrix[1, 0].ToString("F3"));
                result.Append("; " + CameraRotationMatrix[1, 1].ToString("F3"));
                result.Append("; " + CameraRotationMatrix[1, 2].ToString("F3"));
                result.AppendLine("|");

                result.Append("|" + CameraRotationMatrix[2, 0].ToString("F3"));
                result.Append("; " + CameraRotationMatrix[2, 1].ToString("F3"));
                result.Append("; " + CameraRotationMatrix[2, 2].ToString("F3"));
                result.AppendLine("|");

                result.AppendLine();
                result.AppendLine("Translation Vector: ");

                result.Append("|" + CameraTranslation[0].ToString("F3"));
                result.AppendLine("|");
                result.Append("|" + CameraTranslation[1].ToString("F3"));
                result.AppendLine("|");
                result.Append("|" + CameraTranslation[2].ToString("F3"));
                result.AppendLine("|");

                double error = 0.0;
                double relerror = 0.0;
                double rerrx = 0.0;
                double rerry = 0.0;
                for(int p = 0; p < Points.Count; ++p)
                {
                    var cp = Points[p];
                    Vector<double> ip = new DenseVector(new double[] { cp.ImgX, cp.ImgY, 1.0 });
                    Vector<double> rp = new DenseVector(new double[] { cp.RealX, cp.RealY, cp.RealZ, 1.0 });

                    Vector<double> eip = CameraMatrix * rp;
                    eip.DivideThis(eip[2]);

                    var d = (ip - eip);
                    error += d.L2Norm();
                    ip[2] = 0.0;
                    relerror += d.L2Norm() / ip.L2Norm();
                    rerrx += Math.Abs(d[0]) / Math.Abs(ip[0]);
                    rerry += Math.Abs(d[1]) / Math.Abs(ip[1]);
                }

                result.AppendLine();
                result.AppendLine("Projection error ( d(xi, PXr)^2 ): ");
                result.AppendLine("Points count: " + Points.Count.ToString());
                result.AppendLine("Total: " + error.ToString("F4"));
                result.AppendLine("Mean: " + (error / Points.Count).ToString("F4"));
                result.AppendLine("Realtive: " + (relerror).ToString("F4"));
                result.AppendLine("Realtive mean: " + (relerror / Points.Count).ToString("F4"));
                result.AppendLine("Realtive in X: " + (rerrx).ToString("F4"));
                result.AppendLine("Realtive in X mean: " + (rerrx / Points.Count).ToString("F4"));
                result.AppendLine("Realtive in Y: " + (rerry).ToString("F4"));
                result.AppendLine("Realtive in Y mean: " + (rerry / Points.Count).ToString("F4"));

                if(MinimaliseSkew == true)
                {
                    result.AppendLine("SkewMini - base residual: " + _zeroSkewMini.BaseResidiual.ToString("F4"));
                    result.AppendLine("Skewini - best residual: " + _zeroSkewMini.MinimumResidiual.ToString("F4"));
                }

                if(LinearOnly == false)
                {
                    result.AppendLine("GeoMini - base residual: " + _miniAlg.BaseResidiual.ToString("F4"));
                    result.AppendLine("GeoMini - best residual: " + _miniAlg.MinimumResidiual.ToString("F4"));
                }
            }
            else
            {
                result.AppendLine("Camera not yet computed");
                return result.ToString();
            }

            return result.ToString();
        }
开发者ID:KFlaga,项目名称:Cam3D,代码行数:101,代码来源:CamCalibrator.cs


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