Difference fit result form nlinfit and lsqcurvefit
15 次查看(过去 30 天)
显示 更早的评论
Hi all
I have found online that nlinfit and lsqcurvefit are based on the same principles, but could it be that I got a different fit from one than from the other? I used both, but got better results using lsqcurvefit.
Thank you!
0 个评论
采纳的回答
John D'Errico
2023-2-4
And, so?
Many problems will have multiple locally optimal solutions. Neither of those tools even hopes to be a globally optimal solver. So at best, they find a solution based on where you start them out. The solution is one where no search direction will yield an improvement over the current point, but it may easily be a local minimum.
However, they are different solvers. Given the same problem, two different solvers need not converge to the same solution. This is a term called a basin of attraction.
On this specific example, you got a better result from lsqcurvefit. That is irrelevant, as on the next problem, nlinfit might do better.
If you want better results, then use better starting values. That is always true. If you want better help than this, then show your data and tell us what starting values you used, and of course the model being fit.
5 个评论
John D'Errico
2023-2-4
@Wout Laeremans And you clearly did not read my answer.
Yes. It is entirely possible they will generate a different solution, given the same model, AND the same starting values. This is entirely possible. I said EXACTLY that. Different optimizers do not need to converge to the same solution.
Do the two codes use (by default) the same algoritm? NO. They do not.
Nlinfit uses Levenberg-Marquardt, whereas lsqcurvefit uses a trust-region-reflective code. Levenberg-Marquardt is an OPTION for lsqcurvefit, but not the default. Even if you tell lsqcurvefit to use LM, I still would not gaurantee the two implementations are identical, so they may still have different basins of attraction.
Have you made some mistake in your code? It appears the two calls you made are similar. But since they were made to two different algorithms, go back and read my answer. They do not need to converge to the same result.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!