最小二乘法Levenburg Marquardt与Apache Commons [英] Least squares Levenburg Marquardt with Apache commons
问题描述
我在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 Commons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!