Re: curve fitting using self-defined function



Richeng Zheng wrote:
Hi guys,
My professor and I are having a question about fitting a set of data using a self-defined function, ex. fittype = a* ( x - 43 ) ^ b + c, using the fit function. However, the confusion comes when the function returned way-off values for the parameters, a, b and c, and thus the fitting function; the returned fitting function with the parameters are not even close to the source curve. In addition, what is very surprising is that sometimes it even generated different sets of values for the parameters when the same source data was repeatedly inputed. Anyone knows any solution to accurately fit a data with a user defined function. Thank alot in advance guys.

I think what you're running into is this (from the fit reference page in the doc):

"For some nonlinear library models (rational and Weibull), and all custom
nonlinear models, default initial values for coefficients are selected uniformly
at random from the interval (0,1). As a result, multiple fits using the same
data and model may lead to different fitted coefficients. To avoid this, initial
values for coefficients can be specified through a fitoptions structure
or a vector value for the StartPoint property. Alternatively,
the initial state of the random number generator rand can
be set before fitting.

All other nonlinear library models automatically compute reasonable
initial values. These initial values depend on the data, and are based on
model-specific heuristics."

Nonlinear curve fitting is often highly dependent on the initial values for the coefficients, in the sense that the sum of suqared residuals criterion has multiple local minima, and many of them are not good fits to the data at all. With a custom model especially, you are better off trying to choose reasonable initial values to lessen the chances of ending up in one of those bad local minima.

Hope this helps.

- Peter Perkins
The MathWorks, Inc.

.



Relevant Pages

  • Re: how can I alter the x-data of a cfit object after fitting?
    ... These three numbers correspond to the coefficients ... improve the quality of the fit. ... I am fitting histogram data with a Gaussian, ... calibration first and then feed the data to the fitting ...
    (comp.soft-sys.matlab)
  • Re: Connecting external propane appliance to existing RV tank.
    ... hose you'll need and whatever hose fits will need an end cap that fits ... Maybe you can look at a fitting and determine the correct mating size? ... BBROYGBVGW I used to order them by the thousands when I managed an electronics dept. ...
    (rec.outdoors.rv-travel)
  • Re: In need of vectorization help
    ... My application is quite similar - i am carrying out ... Using the data from previous fits, ... This _significantly_ speeds up fitting. ...
    (comp.soft-sys.matlab)
  • Re: Levenberg Marquardt curve fitting
    ... Levenberg-Marquardt has problems when the coefficients it is fitting ... The function your describe has lots of local minima ... I would strongly recommend you find a copy of Numerical Recipes in C, ...
    (comp.lang.labview)
  • Re: Least square curve fitting
    ... however the coefficients are not the ones I expected, ... of the fitting appears to be twice too big. ...
    (comp.soft-sys.matlab)