||
高斯拟合属于非线性拟合,这里最小二乘法,全局最优拟合方法为例,写一个代码,供大家参考:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | close all; clear all; clc; %% Pharmacokinetic Data t = -10:0.2:10; %#ok<*NOPTS> c = 5*exp(-((t)/4).^2)+randn(size(t))*0.1; plot(t,c,'o'), xlabel('t'), ylabel('c');hold on %% 3 Compartment Model model = @(b,t) (b(1)+b(2)*exp(-((t-b(3))./b(4)).^2)) %% Define Optimization Problem problem = createOptimProblem('lsqcurvefit', 'objective', model, 'xdata', t, 'ydata', c, 'x0',ones(1,4)) % 'lb', [-10 -10 -10 0],'ub', [ 10 10 10 0.5],'options',optimset('OutputFcn', @curvefittingPlotIterates) %% solve % b = lsqcurvefit(problem) %Direct fitting may lead to local optimum %% Multistart ms = MultiStart('PlotFcns',@gsplotbestf) [b,fval,exitflag,output,solutions] = run(ms, problem, 100) %#ok<*NASGU,*ASGLU> %% figure; plot(t,c,'o'), xlabel('t'), ylabel('c');hold on hold on; xfdata=-10:0.2:10; yfdata= b(1)+b(2)*exp(-((xfdata-b(3))./b(4)).^2); plot(xfdata,yfdata,'r') hold off; (1)迭代过程 |
(2) 拟合结果
注:18行代码,为直接用最小二乘法拟合,但这种方法往往只能找到局部最优。
转载请注明:笑凌子 » 高斯非线性最小二乘法(全局优化)拟合
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-15 15:27
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社