How to guess initialization parameters for non-linear curve fitting to get the best fit?
39 次查看(过去 30 天)
显示 更早的评论
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 个评论
Alex Sha
2023-5-16
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
回答(2 个)
Sandeep
2023-6-19
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 个评论
Matt J
2023-6-19
编辑:Matt J
2023-6-19
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!