问题描述
我在 java 中使用非线性最小二乘 Levenburg Marquardt 算法来拟合许多指数曲线 (A+Bexp(Cx)).尽管数据非常干净并且与模型有很好的近似性,但即使迭代次数过多(5000-6000),算法也无法对其中的大多数进行建模.对于它可以建模的曲线,它在大约 150 次迭代中完成.
I'm using the non linear least squares Levenburg Marquardt algorithm in java to fit a number of exponential curves (A+Bexp(Cx)). Although the data is quite clean and has a good approximation to the model the algorithm is not able to model the majority of them even with a excessive number of iterations(5000-6000). For the curves it can model, it does so in about 150 iterations.
LeastSquaresProblem problem = new LeastSquaresBuilder()
.start(start).model(jac).target(dTarget)
.lazyEvaluation(false).maxEvaluations(5000)
.maxIterations(6000).build();
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
LeastSquaresOptimizer.Optimum optimum = optimizer.optimize(problem);}
我的问题是如何在 apache commons 中定义收敛标准以阻止它达到最大迭代次数?
My question is how would I define a convergence criteria in apache commons in order to stop it hitting a max number of iterations?
推荐答案
我不认为 Java 是您的问题.让我们解决数学问题.
I don't believe Java is your problem. Let's address the mathematics.
如果你改变你的函数,这个问题更容易解决.
This problem is easier to solve if you change your function.
你假设的方程是:
y = A + B*exp(C*x)
如果你能这样做会更容易:
It'd be easier if you could do this:
y-A = B*exp(C*x)
现在 A 只是一个常数,可以为零或任何您需要向上或向下移动曲线的值.让我们称这个变量为 z:
Now A is just a constant that can be zero or whatever value you need to shift the curve up or down. Let's call that variable z:
z = B*exp(C*x)
取双方的自然对数:
ln(z) = ln(B*exp(C*x))
我们可以简化右边以获得最终结果:
We can simplify that right hand side to get the final result:
ln(z) = ln(B) + C*x
将您的 (x, y) 数据转换为 (x, z),您可以使用直线的最小二乘拟合,其中 C
是 (x, z) 空间中的斜率和 ln(B)
是截距.有很多软件可以做到这一点.
Transform your (x, y) data to (x, z) and you can use least squares fitting of a straight line where C
is the slope in (x, z) space and ln(B)
is the intercept. Lots of software available to do that.
这篇关于最小二乘 Levenburg Marquardt 与 Apache 公地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!