【问题标题】:Matlab - Try various start points for gaussian fit, choose the one with highest rsquare and then plotMatlab - 尝试高斯拟合的各种起点,选择具有最高 rsquare 的起点,然后绘制
【发布时间】:2021-07-16 02:52:51
【问题描述】:

我正在批处理 1000 条数据。有时峰值位置和幅度会发生剧烈变化,程序很难用单个起点值找到这些峰值。我必须将我的数据分成更小的批次来更改起点值,这很耗时。

是否可以尝试各种起点值并选择具有最佳 rsquare 的那个?

ft = fittype('y0 + a*exp(-((x-xa)/(wa))^2), 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';

opts.StartPoint = [10 10 10 0]; % this is a, wa, xa and y0 - from the equation

[fitresult, gof] = fit(xData, yData, ft, opts);

alpha = gof.rsquare; % extract goodness of fit

if alpha < 0.98 % if rsquare (goodness of fit) is not good enough
    
for x = 100:10:500; y= 10:1:50 %these numbers are not set in stone - can be any number
    
opts.StartPoint = [10+x 10 10+y 0]; % tweak the start point values for the fit

[fitresult, gof] = fit(xData, yData, ft, opts); % fit again

然后选择具有最佳rsquare的起点并绘制结果。

% plot
f = figure('Name', 'Gauss','Pointer','crosshair');
h = plot(fitresult, xData, yData, '-o'); 

【问题讨论】:

  • 如果我没记错的话,您描述的是盆地跳跃方法。我认为你不需要像高斯一样强大的东西,尽管你可以查看 Jean Jacquelin 的工作,了解一些无需迭代即可获得真正准确的初始参数的好方法。
  • @MadPhysicist 感谢您的建议,我会阅读建议的参考。我正在批处理 1000 条数据。有时,峰值的位置和幅度会发生巨大变化,程序很难找到具有单个起点值的这些峰值。我必须将我的数据分成更小的批次来更改起点值,这很耗时。
  • 你需要一个好的猜测方法。我已经开始研究一个叫做 scikit-guess 的东西,你可能会发现它作为参考有用。

标签: matlab curve-fitting gaussian goodness-of-fit


【解决方案1】:

如果猜测有困难,我建议使用不同的方法,它不是迭代的,也不需要猜测参数的值来开始数值演算。

由于我没有您的问题的代表性数据,我无法检查以下建议的方法是否适合您的情况。这取决于数据的分散性和点的分布。

试试看。如果结果不正确,请告诉我。

下面显示了一个具有高度分散数据的数值示例。通过这个例子你可以检查方法是否正确实现。

注意:此方法可用于获取参数的一些近似值,这些近似值可以在通常的非线性回归软件中作为“猜测”值。

供参考:该方法是线性回归 wrt 一个积分方程,高斯函数是其解:

一般原则见:https://fr.scribd.com/doc/14674814/Regressions-et-equations-integrales

【讨论】:

    猜你喜欢
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多