Why does my nonlinear (exponential or trigonometric) model fit poorly?
Show older comments
This is a question I see often online by users of curve fitting tools. Typically, I see someone try to use a tool like the curve fitting toolbox to fit some data, but all they get is something strange out the end.
Assuming the user has chosen a valid model for their data, a commn problem is simply poor starting values. So my answer here will attempt to explain what hapens, to show why things sometimes go astray.
I'll use the curve fitting toolbox for my examples, mainly because it is a nice tool that handles this sort of problem well and makes plots easily, but the stats TB or the optimization TB can do as nicely.
(If others wish to add their own answer to this question, feel free.)
Accepted Answer
More Answers (2)
Here are the most frequent pitfalls that I see:
(1) Bad Data
Either the data is too noisy or have too few data points. Garbage in, garbage out.
(2) Custom Model
The Curve FItting Toolbox has a built-in library of commonly encountered curve models. If your model is in the built-in library, fit() has a smart way of generating an initial guess for the iterative parameter search. However, for custom models, fit() has no choice but to make a random initial guess, which can lead to poor results. The user should provide an educated initial guess using the 'StartingPoint' fit option.
(3) Bad Units
Some users make unnatural choices of units for the x,y data and/or for the unknnowns parameters, like measuring the distance between atoms in miles instead of nanometers. This can create several problems...
First, Mathworks has defined default algorithm parameters, like TolX, TolFun, and DiffMinChange for the iterative search, with the assumption that 1e-6 represents a small change in your parameter values. With the wrong units, these defaults are completely inappropriate and can result in premature stopping of the iterations. You can change all the stopping parameters to suit your choice of units if you wish, but using more natural units can save you this hassle.
Second, it can make the iterative search ill-conditioned, because the predicted curve can change much more sharply in response to some parameters than others.
Third, if the algorithm is forced to add/subtract large numbers with very small numers, double float precision limitations may produce inaccurate results.
1 Comment
John D'Errico
on 11 Oct 2021
Categories
Find more on Mathematics and Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!












