Curve Fitting Toolbox: solution generated by the GUI not the same as the one generated by the line of codes (generating code)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Bastien Haemmerli
am 10 Mai 2022
Bearbeitet: Saarthak Gupta
am 6 Dez. 2023
I'm using the GUI coming with the curve fitting toolbox to help me generating a good fit.
I have a "shock damper" transfer function which ressemble somewhat a gaussian:
- value around 1 at "low frequency" (i.e. at low x-axis value the y-axis value is about 1)
- a peak at the "resonance frequency"
- a sharp decrease at "high frequency" toward 0 (i.e. at high x-axis value the y-axis value is closed to 0)
using then "Gaussian" with 5 terms on the GUI, I got a very good match between my datapoint.
notably the coefficient a1 = 0.5348
the fit option are left as standard. I'm not sure if the fact that the "fit computation did not converge" is the issue.
now when I use the option to "generate the code" and run it, I get a fitresult with other parameters.
notably the coefficient a1 = 0.4643
I checked all the options and parameters between the GUI and the generated code and they are identical.
and these changes as you can see under, lead to an actual less good fit at high frequency, with a curve that deviate with the general exponential decrease.
do you know why the GUI "converge" to a better solution than the generated code? how can I ensure to get the same solution with the generated code as with the GUI?
as a quick fix I will simply use in my code the coefficients I get from the GUI (hardcoding them), but I would like to be able to generate the same solution.
as it is with a GUI, I don't know how I should show the different details (i.e. it is not enough to simply copy the code). let me know what information you might need and I will provide it.
thank you for your assistance.
Akzeptierte Antwort
Saarthak Gupta
am 6 Dez. 2023
Bearbeitet: Saarthak Gupta
am 6 Dez. 2023
Hi Bastien,
It is highly likely that you are getting different fit coefficients while fitting the data because of the underlying algorithm’s failure to converge.
The algorithm terminates prematurely because the iteration count exceeds a pre-specified limit, and while the algorithm may be very close, it has not fully converged to the absolute minimum. Successive attempts to fit, too, may not reach convergence, hence the different results.
Under the default fit options (as in your case), the curve fitter uses the Levenberg-Marquardt algorithm which is a nonlinear least squares method. The algorithm converges when the difference between reduced chi-square values of two successive iterations is less than a certain tolerance value. When the process completes, we say that the fit has converged.
In most cases, failure to converge can be traced to one of the following reasons:
- Poor initial parameter values: Good initial values, whether empirical or estimated, significantly expedite the fitting process, reducing the time required for completion.
- Relative vs absolute minima: In many cases, the iterative process may identify a relative minimum rather than an absolute one, and in this instance, the process converges as further reduction of the reduced chi-square appears unattainable. To ascertain that the iterative procedure is approaching an absolute minimum, it is essential to initiate fitting from multiple distinct initial parameter values and observe consistent outcomes.
- Non-unique parameter values: The primary issue encountered in nonlinear fitting is the lack of convergence, where regardless of the chosen initial parameter values, the fit fails to stabilize, leading to continuous parameter changes and eventual divergence, and suggesting the need for adjustments to the fitting function and/or the data being utilized.
- Over-parameterized functions: If the function parameters have the same differential with respect to independent variables, it may suggest that the function is overparameterized.
- Bad data: Despite the function not being theoretically overparameterized, the iterative process might act as though it is, often occurring when the available data within a restricted interval of the independent variable(s) lack sufficient information to determine some or all the parameters.
Re-evaluating the data and the fit type would certainly help. Consider changing the starting parameters, changing the fit type, or adding more data points.
Please refer to the following MATLAB documentation for further reference:
- ‘fit’: https://www.mathworks.com/help/curvefit/fit.html
- ‘fitoptions’: https://www.mathworks.com/help/curvefit/fitoptions.html
- Least-Squares Algorithms: https://www.mathworks.com/help/optim/ug/least-squares-model-fitting-algorithms.html
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!