MATLAB:使用MultiStart进行非线性拟合可以找到局部最小值,但不能找到全局最小值



我正在为一些非线性数据拟合一个函数。然而,我得到的输出是:

Attempt to execute SCRIPT MultiStart as a function:
/MATLAB Drive/Amsterdam/2 Fitting/MultiStart.m
Error in MultiStart (line 42)
ms = MultiStart('PlotFcn',@gsplotbestf);

这是我的密码。我已经指定了参数、初始值、目标函数和边界。我的代码确实找到了局部最小值,但找不到全局最小值。

function [EPSC, IPSC, CPSC, t] = generate_current(G_max_chl, G_max_glu, EGlu, EChl, Vm, tau_rise_In, tau_decay_In, tau_rise_Ex, tau_decay_Ex,tmax)

dt = 0.1;                               % time step duration (ms)
t = 0:dt:tmax-dt;

% Compute compound current

IPSC = ((G_max_chl) .* ((1 - exp(-t / tau_rise_In)) .* exp(-t / tau_decay_In)) * (Vm - EChl));

EPSC = ((G_max_glu) .* ((1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex)) * (Vm - EGlu));

CPSC = IPSC + EPSC;

end

在用前面的函数生成数据后,我有了拟合程序:


% Simulated data
[~,~,CPSC,t] = generate_current(80,15,0,-70,-30,0.44,15,0.73,3,120);
% % Parameters
G_max_chl = 80;                          % Maximal conductance of Chl
G_max_glu = 15;                          % Maximal conductance of Glu
tau_rise_Ex = 0.73;                      % Tau rise for E
tau_rise_In = 0.44;                      % Tau rise for I
tau_decay_Ex = 3;                        % Tau decay for E
tau_decay_In = 15;                       % Tau decay for I
p = [G_max_chl,  G_max_glu, tau_rise_In, tau_decay_In, tau_rise_Ex, tau_decay_Ex];
dt = 0.1;
tmax = 121;
t = 1:0.1:tmax-dt;
Vm = -30;
EGlu = 0;
EChl = -70;
% Create the objective function
fitfcn = @(p, t, Vm, EGlu, EChl) ((p(1)) .* ((1 - exp(-t / p(3))) .* exp(-t / p(4))) * (Vm - EChl)) + ((p(2)) .* ((1 - exp(-t / p(5))) .* exp(-t / p(6))) * (Vm - EGlu));
preal = [80,15,0.44,0.73,15,3]; % Real coefficients
xdata = t;
ydata = CPSC; % Response data with noise
% Set bounds and initial point.
lb = [0,0,0,0,0,0];
ub = [150,150,5,5,20,20];
p0 = [50,50,1,1,1,1]; % Arbitrary initial points
% Find the best local fit
[xfitted,errorfitted] = lsqcurvefit(@(p,t)fitfcn(p, t, Vm, EGlu, EChl), p0, xdata, ydata,lb,ub)
%Set up the problem for MultiStart.
problem = createOptimProblem('lsqcurvefit','x0',p0,'objective',fitfcn,...
'lb',lb,'ub',ub,'xdata',xdata,'ydata',ydata);
% Find a global solution
ms = MultiStart('PlotFcn',@gsplotbestf);
[xmulti,errormulti] = run(ms,problem,200)

在Matlab的搜索路径中的/MATLAB Drive/Amsterdam/2 Fitting位置有一个名为MultiStart.m的脚本。当您调用MultiStart()时,Matlab假设您调用的是该脚本,而不是内置的MultiStart函数。

您需要将脚本重命名为与Matlab的内置函数名不冲突的名称,或者从Matlab的搜索路径中删除/MATLAB Drive/Amsterdam/2 Fitting

相关内容

  • 没有找到相关文章

最新更新