简体   繁体   English

Levenberg-Marquardt-算法和 ODR 之间的区别

[英]Difference between Levenberg-Marquardt-Algorithm and ODR

I was able to fit curves to ax/y dataset using peak-o-mat , as shown below.我能够使用peak-o-mat将曲线拟合到 ax/y 数据集,如下所示。 Thats a linear background and 10 lorentzian curves.那是线性背景和 10 条洛伦兹曲线。Peak-o-mat结果

Since I need to fit many similar curves I wrote a scripted fitting routine, using mpfit.py , which is a Levenberg-Marquardt-Algorithm.由于我需要拟合许多相似的曲线,因此我使用mpfit.py编写了一个脚本化的拟合例程,这是一种 Levenberg-Marquardt-Algorithm。 However the fit takes longer and, in my opinion, is less accurate than the peak-o-mat result:然而,拟合需要更长的时间,而且在我看来,它不如 peak-o-mat 结果准确:

Starting values起始值起始值

Fit result with fixed linear background (values for linear background taken from the peak-o-mat result)具有固定线性背景的拟合结果(从 peak-o-mat 结果中获取的线性背景值)适合固定

Fit result with all variables free适合所有变量的结果免费安装

I believe the starting values are already very close, but even with the fixed linear background, the left lorentzian is clearly a degradation of the fit.我相信起始值已经非常接近,但即使有固定的线性背景,左洛伦兹显然是拟合的退化。

The result is even worse for total free fit.完全自由配合的结果更糟。

Peak-o-mat appears to use scipy.odr.odrpack . Peak-o-mat 似乎使用scipy.odr.odrpack Now what is more likely:现在更有可能的是:

  1. I did some implementation error?我做了一些实施错误?
  2. odrpack is more suitable for this particular problem? odrpack 更适合这个特定问题?

Fitting to a more simple problem (linear data with one peak in the middle) shows very good correlation between peak-o-mat and my script.拟合一个更简单的问题(中间有一个峰的线性数据)显示 peak-o-mat 和我的脚本之间有很好的相关性。 Also I did not find a lot about ordpack.我也没有找到很多关于 ordpack 的信息。

Edit: It seems I could answer the question by myself, however the answer is a bit unsettling.编辑:看来我可以自己回答这个问题,但答案有点令人不安。 Using scipy.odr (which allows fitting with odr or leastsq method) both give the result as peak-o-mat, even without constraints.使用 scipy.odr(允许使用 odr 或 leastsq 方法进行拟合)都将结果作为 peak-o-mat,即使没有约束。

The image below shows again the data, the start values (almost perfect) and then the odr and leastsq fits.下图再次显示了数据、起始值(几乎完美)以及 odr 和 leastsq 拟合。 The component curves are for the odr one组件曲线是针对 odr 的

scipy.odr

I will switch to odr, but this still leaves me upset.我会改用 odr,但这仍然让我心烦意乱。 The methods (mpfit.py, scipy.optimize.leastsq, scipy.odr in leastsq mode) 'should' yield the same results.这些方法(mpfit.py、scipy.optimize.leastsq、leastsq 模式下的 scipy.odr)“应该”产生相同的结果。

And for people stumbling upon this post: to do the odr fit an error must be specified for x and y values.对于偶然发现这篇文章的人:要执行 odr 拟合,必须为 x 和 y 值指定错误。 If there is no error, use small values with sx << sy.如果没有错误,请使用 sx << sy 的小值。

linear = odr.Model(f)
mydata = odr.RealData(x, y, sx = 1e-99, sy = 0.01)
myodr = odr.ODR(mydata, linear, beta0 = beta0, maxit = 2000)
myoutput1 = myodr.run() 

You can use peak-o-mat for scripting as well.您也可以使用 peak-o-mat 编写脚本。 The easiest would be to create project containing all data you want to fit via the GUI, clean it, transform it and attach (ie choose a model, provide an initial guess and fit) the base model to one of the sets.最简单的方法是创建包含您想要通过 GUI 拟合的所有数据的项目,清理它,转换它并将基本模型附加(即选择一个模型,提供初始猜测和拟合)到其中一个集合。 Then you can (deep)copy that model and attach it to all of the other data sets.然后您可以(深度)复制该模型并将其附加到所有其他数据集。 Try this:试试这个:

from peak_o_mat.project import Project
from peak_o_mat.fit import Fit
from copy import deepcopy

p = Project()
p.Read('in.lpj')

base = p[2][0]    # this is the set which has been fit already

for data in p[2][1:]: # all remaining sets of plot number 2

    mod = deepcopy(base.mod)
    data.mod = mod

    f = Fit(data, data.mod)
    res = f.run()

    pars = res[0]
    err = res[1]

    data.mod._newpars(pars, err)

    print data.mod.parameters_as_table()

p.Write('out')

Please tell me, if you need more details.如果您需要更多详细信息,请告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Neurolab中的Levenberg-Marquardt算法替代方案 - Levenberg-Marquardt algorithm alternatives in Neurolab 具有 GPU 支持的 Levenberg-Marquardt 算法 - Levenberg-Marquardt algorithm with GPU support keras将Levenberg-Marquardt优化算法实现为自定义优化器 - keras implementation of Levenberg-Marquardt optimization algorithm as a custom optimizer 使用Python中的Levenberg-Marquardt算法优化方程组 - Optimizing set of equations with Levenberg-Marquardt algorithm in Python 使用最小二乘法(Levenberg-Marquardt算法)将双曲线拟合到线性数据的程序不能按预期工作 - Program to fit a hyperbola to linear data using least squares (Levenberg-Marquardt algorithm) not working as expected 使用leastsq方法为levenberg marquardt查找参数 - Finding params using leastsq method for levenberg marquardt 基于 scipy.optimize.basinhopping 中的 Levenberg-Marquardt 的自定义最小化器 - Custom minimizer based on Levenberg-Marquardt in scipy.optimize.basinhopping 在Scipy的minimum_squares函数中使用Levenberg-Marquardt方法 - Using Levenberg-Marquardt method in scipy's least_squares function 高斯拟合python中的直方图数据:Trust Region v / s Levenberg Marquardt - Gaussian fit to a histogram data in python: Trust Region v/s Levenberg Marquardt 我们可以在 tf.keras.sequential 编译器中实现 levenberg_marquardt 优化器吗? - Can we implement levenberg_marquardt optimizer in tf.keras.sequential compiler?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM