MATLAB Answers

0

How to use multistart with 'fit' function

roni zidane さんによって質問されました 2019 年 1 月 4 日
最新アクティビティ Alex Sha
さんによって 回答されました 2019 年 4 月 29 日
Hi There,
i want to use 'Multistart' to find the best solution for a bi-exponential decay function that i am fitting to my data with bounds.
Below is the code i am using.
% bi-exponential decay model
fparam = fittype(@(a,b,c,d,x)(a)*exp(-(1/b)*x)+abs(1-a)*(exp(-(1/c)*x))+d);
lb1 = [0,0,0,0];
ub1 = [1,30,200,80];
b0 = [0.3,0.2,20,10];
x = [3.39,8.59,13.8,19,24.2,29.4,34.6,39.81,45.0,50.21];
y = [1,0.2905,0.0894,0.0838,0.1173,0.1006,0.0782,0.0894,0.1061,0.0726]
opts = fitoptions('Display','Off','Method','NonlinearLeastSquares','Normalize','Off',...
'Startpoint',b0, 'Robust','On','Lower',lb1,'Upper',ub1,...
'TolFun',1e-3);
[estTmp,Goft,Out] = fit(x,y,fparam,opts);
Since i need to start somewhere i have randomly chosen 'b0' values. I want to avoid local minima, so i want to use 'Multistart' function for optimization and find the best solution within the 'bounds' (here given by 'lb1', 'ub1').
Can someone please help me bridge 'Multistart' with 'fit' ?
P.S. I know someone might suggest to use 'lsqnonlin' instead of 'fit'. The reason i am not using it is becasue i need the output 'stats' (e.g. goodness of fit and R^2 values) which i might have to compute manually in 'lsqnonlin'. So please suggest me only the ways to combine 'Multistart' and 'fit'

  0 件のコメント

サインイン to comment.

2 件の回答

Alan Weiss
回答者: Alan Weiss
2019 年 1 月 4 日
 採用された回答

As documented, the only local solvers available for MultiStart are fmincon, fminunc, lsqcurvefit, and lsqnonlin. Sorry, no other local solvers are supported.
Alan Weiss
MATLAB mathematical toolbox documentation

  2 件のコメント

roni zidane 2019 年 1 月 7 日
Hi Alan,
That's unfortunate. In that case, Would you have any solution about how to calculate Goodness of Fit, and R^2 from either 'lsqnolin' or 'lsqcurvefit' ?
The reason i avoid using either 'lsqnonlin' or 'lsqcurvefit' are the following:
1) i want to use 'Robust' option as mentioned in my 'opts' variable in my original post.
Also when i try to find best fit solution with 'lsqnonlin', I get fig.1 result, where the instead of starting to fit from datapoint 1 , The fitting start from 1.4 or so (Though i have provided 'lb' and 'ub'), and it is far from the ideal solution.
So ,
2) my question will be, how do i make sure that the fitting starts at datapoint 1 with 'lsqnonlin' ? 3) How do i calculate goodness of Fit and R^2 from 'lsqnonlin' result?
Alan Weiss
2019 年 1 月 7 日
As far as getting the curve to start from level 1 at x = 3.39, I suggest that you shift all x values by 3.39 (so x = 0 corresponds to your first data point) and then set d = 0 in your formula (fit parameters a, b, and c, but do not allow a nonzero value of d). Then your curve will start at the height 1 at x = 0.
To calculate the goodness of fit, see this old documentation example.
I am not sure that calculating R^2 makes much sense in nonlinear fitting.
Alan Weiss
MATLAB mathematical toolbox documentation

サインイン to comment.


Alex Sha
回答者: Alex Sha
2019 年 4 月 29 日

Multi-solutions (Parameter a is different):
1:
Root of Mean Square Error (RMSE): 0.109662308225183
Sum of Squared Residual: 0.12025821845275
Correlation Coef. (R): 0.948796774493673
R-Square: 0.900215319289597
Parameter Best Estimate
---------- -------------
a 0.057712785437929
b 7.20470183282193
c 7.20470183925339
d 0.0814111332963631
2:
Root of Mean Square Error (RMSE): 0.109662308225183
Sum of Squared Residual: 0.12025821845275
Correlation Coef. (R): 0.948796774685829
R-Square: 0.900215319654232
Parameter Best Estimate
---------- -------------
a 0.0035886762500919
b 7.20470208037725
c 7.20470182707246
d 0.0814111343856455
3:
Sum of Squared Residual: 0.12025821845275
Correlation Coef. (R): 0.948796775443418
R-Square: 0.900215321091827
Parameter Best Estimate
---------- -------------
a 0.176245451532707
b 7.20470187824529
c 7.20470176505555
d 0.0814111355698764

  0 件のコメント

サインイン to comment.



Translated by