Nonlinear fitting - No output function with MultiStart

조회 수: 1 (최근 30일)
Samuele Bolotta
Samuele Bolotta 2021년 3월 15일
댓글: Samuele Bolotta 2021년 3월 16일
I'm fitting a function to some nonlinear data. However, the output that I get is:
MultiStart with properties:
UseParallel: 0
Display: 'final'
FunctionTolerance: 1.0000e-06
MaxTime: Inf
OutputFcn: []
PlotFcn: []
StartPointsToRun: 'all'
XTolerance: 1.0000e-06
No plot and not output function.
This is the code:
% Parameters
p(1) = G_max_chl;
p(2) = G_max_glu;
p(3) = tau_rise_In;
p(4) = tau_decay_In;
p(5) = tau_rise_Ex;
p(6) = tau_decay_Ex;
% Create the objective function
fitfcn = @(p, Vm, EGlu, EChl, dt, tmax) ((p(1)) .* ((1 - exp(-(0:dt:tmax-dt) / p(3))) .* exp(-(0:dt:tmax-dt) / p(4))) * (Vm - EChl)) + ((p(2)) .* ((1 - exp(-(0:dt:tmax-dt) / p(5))) .* exp(-(0:dt:tmax-dt) / p(6))) * (Vm - EGlu));
% Create the training data
rng default % For reproducibility
N = 200; % Number of data points
preal = [80,15,0.44,0.73,15,3]; % Real coefficients
Vm = -30;
Eglu = 0;
EChl = -70;
dt = 0.1;
tmax = 120;
ydata = fitfcn(preal,xdata); % Response data with noise
ydata = awgn(ydata,35,'measured');
% Set bounds and initial point.
lb = [0,0,0,0,0,0];
ub = [150,150,5,5,20,20];
p0 = 5*ones(1,6); % Arbitrary initial points
% Find the best local fit
[xfitted,errorfitted] = lsqcurvefit(fitfcn,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('PlotFcns',@gsplotbestf);
[xmulti,errormulti] = run(ms,problem,200)
I am not sure what I'm doing wrong.

채택된 답변

Star Strider
Star Strider 2021년 3월 15일
Unfortunately, this:
fitfcn = @(p, Vm, EGlu, EChl, dt, tmax) ((p(1)) .* ((1 - exp(-(0:dt:tmax-dt) / p(3))) .* exp(-(0:dt:tmax-dt) / p(4))) * (Vm - EChl)) + ((p(2)) .* ((1 - exp(-(0:dt:tmax-dt) / p(5))) .* exp(-(0:dt:tmax-dt) / p(6))) * (Vm - EGlu));
is not going to work with lsqcurvefit, or likely any other optimisation function.
The problems (that I can easily see) are:
fitfcn = @(p, Vm, EGlu, EChl, dt, tmax) ((p(1)) .* ((1 - exp(-(0:dt:tmax-dt) / p(3))) .* exp(-(0:dt:tmax-dt) / p(4))) * (Vm - EChl)) + ((p(2)) .* ((1 - exp(-(0:dt:tmax-dt) / p(5))) .* exp(-(0:dt:tmax-dt) / p(6))) * (Vm - EGlu));
↑ ← 't MUST BE AN INDEPENDENT VARIABLE ↑ ↑ ← ↑ ← EXTRA PARAMETERS ↑ ← t ↑← 't ↑ ← ↑ ← EXTRA PARAMETERS
So it should be:
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));
and the lsqcurvefit call:
B = lsqcurvefit(@(p,t)fitfcn(p, t, Vm, EGlu, EChl), B0, t, ydata)
with ‘Vm’, ‘EGlu’ and ‘EChl’ existing in the calling function workspace.
That should come close to working, although it may require some revision.
I cannot test it so I am posting it as UNTESTED CODE.
  댓글 수: 5
Star Strider
Star Strider 2021년 3월 16일
The error appears to be here:
ms = MultiStart('PlotFcns',@gsplotbestf);
that will likely be solved by eliminating the ‘s’:
ms = MultiStart('PlotFcn',@gsplotbestf);
I usually use ga (genetic algorithm) of this sort of problem because I have more experience with it. I have used GlobalSearch as well a few times, however not MultiStart.
If the data are generated by your actual objective function to which you just added noise, the Golbal Optimization Toolbox functions will likely converge on the correct parameter set providing that the noise does not completely obscure the underlying signal. Providing the correct magnitudes of the initial parameter set is likely important (or likewise using the bound limits to force them into a specific range of magnitudes), however the initial parameter estimates provided to global optimisation functions are likely less important because the algorithms will eventually find the best set.
Samuele Bolotta
Samuele Bolotta 2021년 3월 16일
Thanks for your explanation!
Unfortunately, even removing the 's' it still gives me the same error. Doing this, I can find a local but not the global minimum. I'll try with GA, but would like to understand what I'm doing wrong here first.
% 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)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Global or Multiple Starting Point Search에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by