How to resolve : increase max function value in fitting using fminsearch?

Hi
I was trying to fit my data with fminsearch function with following code:
f = @(a,b,c,x) a - b.*(x).^c;
obj_fun = @(params) norm(f(params(1), params(2), params(3), x) -y);
sol = fminsearch(obj_fun, [1,1,1]);
err = .02*ones(size(x));
errorbar(x,y,err,'horizontal','s',"MarkerFaceColor",[0.8500, 0.3250, 0.0980], ...
"MarkerSize",4,"CapSize",4,"Color",[0.8500, 0.3250, 0.0980],"LineWidth",1)
hold on
x = linspace(min,max,20);
plot(x,f(sol(1),sol(2),sol(3),x),'-',"Color",[0.8500, 0.3250, 0.0980],"LineWidth",1)
hold off
Its getting the fit, but I think this is not best optimum fit its showing following message:
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
Current function value: 2.586758
it will be realy great if some experties help me here to take care of this. Im attaching data here (data.txt).
Is there any other function which I can use instade of this to fit and better gobal optimazation.
Thank you in advance!

 Respuesta aceptada

Matt J
Matt J el 16 de Jun. de 2022
Editada: Matt J el 16 de Jun. de 2022
You could do as the message says and increas MaxFunEvals, but for your model, it would be better to download fminspleas,
[x,y]=readvars('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1034515/data.txt');
funlist={1,@(c,xd) -xd(:).^c};
[c,ab]=fminspleas(funlist, 1 ,x, y);
sol=[ab(:).',c]
sol = 1×3
-6.5546 -0.0000 -6.0133

2 comentarios

@Matt J thank you for your response!
Can you little bit elaborate the code, means fminsplease function and how your calculation that will be god to understand me as well!
Matt J
Matt J el 17 de Jun. de 2022
Editada: Matt J el 18 de Jun. de 2022
Fminspleas uses a technique which only needs to iterate over the c parameter, so it is an easier search.

Iniciar sesión para comentar.

Más respuestas (1)

Matt J
Matt J el 16 de Jun. de 2022
Editada: Matt J el 16 de Jun. de 2022
If you have the Curve Fitting Toolbox,
[x,y]=readvars('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1034515/data.txt');
ft=fit(x(:),y(:),'power2')
ft =
General model Power2: ft(x) = a*x^b+c Coefficients (with 95% confidence bounds): a = 1.124e-06 (-2.414e-05, 2.639e-05) b = -6.015 (-14.64, 2.609) c = -6.554 (-9.987, -3.121)
plot(ft,x,y)

5 comentarios

adding one term "d*x" for fitting function, the result will be much better:
y = a*x^b+c+d*x
Sum Squared Error (SSE): 1.0988630107163
Root of Mean Square Error (RMSE): 0.3494222232194
Correlation Coef. (R): 0.970379925110827
R-Square: 0.941637199058095
Parameter Best Estimate Std. Deviation Confidence Bounds[95%]
--------- ------------- -------------- ----------------------------------
a 430058778433358 0.125126556164325 [430058778433358, 430058778433359]
b 14.4836582099507 3.10784213390318 [6.49469567251403, 22.4726207473875]
c 18.5003218509943 36.6945561128952 [-75.8260375595516, 112.82668126154]
d -257.754044491992 1.5875823760405E-17 [-257.754044491992, -257.754044491992]
or the function: y=a*x^b+c+d*exp(e*x);
Sum Squared Error (SSE): 0.798012086224085
Root of Mean Square Error (RMSE): 0.297771740735171
Correlation Coef. (R): 0.978578556003836
R-Square: 0.957615990270552
Parameter Best Estimate Std. Deviation Confidence Interval[95%] (Diff-OK)
--------- ------------- -------------- ----------------------------------
a -3.96448222151296E-7 7.34052972781328E-6 [-2.07770260544974E-5, 1.99841296101948E-5]
b -7.72186291539508 6.95514357122107 [-27.0324372396597, 11.5887114088695]
c -1.28127707754111 12.6536549323532 [-36.4134553773351, 33.8509012222529]
d 286678.994342762 1537623.25203099 [-3982447.55739699, 4555805.54608251]
e -97.6137053829133 77.3303025621153 [-312.317045414963, 117.089634649136]
@Alex Sha I canot add one more variable which may chage my fiiting model assumptions. can you plese suggest any other function with which I can proceed?
@Sonnath what is unacceptable about the fit that your current model gives you? You'll notice that both fit() and fminspleas() are in agreement on the fitted parameters.
@Matt J Im more intrested in fitting coefficint than that the good visual fit. I tried with fminplease it doing the job!
Thanks! looking forword to your help in future as well!

Iniciar sesión para comentar.

Categorías

Preguntada:

el 16 de Jun. de 2022

Editada:

el 18 de Jun. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by