首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MATLAB:用MultiStart进行非线性拟合找到局部但不是全局最小值

MATLAB:用MultiStart进行非线性拟合找到局部但不是全局最小值
EN

Stack Overflow用户
提问于 2021-03-17 00:55:12
回答 1查看 60关注 0票数 0

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

代码语言:javascript
复制
Attempt to execute SCRIPT MultiStart as a function:
/MATLAB Drive/Amsterdam/2 Fitting/MultiStart.m

Error in MultiStart (line 42)
ms = MultiStart('PlotFcn',@gsplotbestf);

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

代码语言:javascript
复制
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

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

代码语言:javascript
复制
% 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)
EN

回答 1

Stack Overflow用户

发布于 2021-03-17 08:11:08

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66659791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档