问题描述
我正在批量处理 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,opts); % fit again
然后选择具有最佳 rsquare 的起点并绘制结果。
% plot
f = figure('Name','Gauss','Pointer','crosshair');
h = plot(fitresult,xData,'-o');
解决方法
如果猜测困难,我建议使用不同的方法,它不是迭代的,不需要参数的猜测值来开始数值演算。
由于我没有您的问题的代表性数据,我无法检查下面提出的方法是否适合您的情况。这取决于数据的分散性和点的分布。
试试看。如果结果不正确,请告诉我。
下面显示了具有高度分散数据的数值示例。通过此示例,您可以检查该方法是否正确实现。
注意:此方法可用于获得参数的一些近似值,这些值可以作为常用非线性回归软件中的“猜测”值。
有关信息:该方法是线性回归,它是高斯函数解的积分方程:
一般原理见:https://fr.scribd.com/doc/14674814/Regressions-et-equations-integrales