Matlab - 尝试高斯拟合的各种起点,选择具有最高 rsquare 的一个,然后绘制

问题描述

我正在批量处理 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'); 

解决方法

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

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

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

下面显示了具有高度分散数据的数值示例。通过此示例,您可以检查该方法是否正确实现。

enter image description here

enter image description here

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

有关信息:该方法是线性回归,它是高斯函数解的积分方程:

enter image description here

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...