How to guess initialization parameters for non-linear curve fitting to get the best fit?
39 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to fit my data to this equation:
y= (a*x+b*x^2*a*c)/(1+b*x*a),
where, a,b,and c are variables
I need to find the values of the variables using the curve fitting toolbox. The answers changes with the initial guess that is provided. So is there a way to know which initial guess could provied the best fit? Following are the x and y values.
x=[0.001, 0.002, 0.003, 0.004, 0.005, 0.006]
y=[0.0692, 0.0995, 0.1375, 0.1566, 0.2215, 0.2955]
1 commentaire
Alex Sha
le 16 Mai 2023
The issue of how to guess initialization parameters has been discussed many times, it is problem-depended, and usually the good understanding of the problem background will help to guess the good start-values, besides, luck is also very important.
One more way is to apply Global Optimization Algorithms, which is no need to guess initial start-values, like the best result below, which is the unique stable global solution.
However, refer to the picture, the fitting function does not match the data very well, or the amount of data is too small.
Sum Squared Error (SSE): 0.000839843899134794
Root of Mean Square Error (RMSE): 0.0118310601041974
Correlation Coef. (R): 0.989750305617155
R-Square: 0.979605667469251
Parameter Best Estimate
--------- -------------
a 48.0837565749668
b -5.34531290872802
c 47.8382259562215
Réponses (2)
Sandeep
le 19 Juin 2023
Hi Rinsha Padmrajan,
As @Alex Sha suggested guessing appropriate initialization parameters is problem dependent and understanding the problem background will help. To find the best fit for the values of variables a, b, and c in the given equation, you can try different initial guesses until a suitable result is obtained. Moreover, the initial values should not be chosen just randomly. One way to do so is by considering the behavior of the function and choosing the initial values around that. We can see that the function involves both quadratic and linear terms of x. So, it would be beneficial to choose initial values of a and b that account for these terms. While for variable c the magnitude of it can be assumed based on data scaling.
Another helpful approach is to plot the data, so you can get a better idea of the required initial values by visual examination. Plotting the data can help you understand what values of parameters are needed to achieve the desired fit.
Finally, optimizing the least squares (LSQ) error could provide the most accurate initial guesses for the variables. The LSQ error is obtained by computing the difference between the predicted and observed values of y and then squaring this value. This LSQ error can be minimized using optimization methods like lsqcurvefit function in MATLAB.
For more information refer the documentation page: Solve nonlinear curve-fitting (data-fitting) problems in least-squares sense - MATLAB lsqcurvefit (mathworks.com)
0 commentaires
Matt J
le 19 Juin 2023
Modifié(e) : Matt J
le 19 Juin 2023
Re-arrange the equation as follows
y = a*b*c*x^2 + (a-y*b*a)*x
= C*x^2 + D*x
Assume C and D can be treated as constants and solve the linear system,
x=[0.001, 0.002, 0.003, 0.004, 0.005, 0.006]';
y=[0.0692, 0.0995, 0.1375, 0.1566, 0.2215, 0.2955]';
p = [x.^2,x]\y;
C=p(1);
D=p(2);
Now, using the second coefficient D, solve for a assuming b=1,
b=1;
a = (1-b*y)\(D*y.^0);
Now solve for c
c=C/a/b;
Now use this as an initial guess to fminsearch,
p=fminsearch(@(p) norm(objfun(p,x)-y) , [a,b,c], optimset('MaxIter',2000,'MaxFunEvals',inf))
f=@(x)objfun(p,x);
R2=1-norm(f(x)-y).^2/norm(y-mean(y)).^2
xs=linspace(min(x), max(x));
plot(x,y,'o',xs, f(xs))
function F=objfun(p,x)
a=p(1); b=p(2); c=p(3);
F=(a*x+b*x.^2*a*c)./(1+b*x*a);
end
0 commentaires
Voir également
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!