Next: , Previous: , Up: Internal Routines   [Contents][Index]

15.5.232 fit

fit( [x,] y, start=start, step=step [, lowbound=lowbound, highbound=highbound, weights=weights] [, qthresh=qthresh, pthresh=pthresh, ithresh=ithresh, dthresh=dthresh, fac=fac, niter=niter, nsame=nsame] [, err=err, fit=fit, tthresh=tthresh] [, /vocal, /down, /pchi, /gaussians, /powerfunc])

Iterative non-linear fit to Gaussians, power functions, and user-defined functions. The selected function is evaluated at positions x under guidance of trial model parameters and the found model values are compared with y. The model parameters are adjusted to minimize the differences between the model values and y. The return value is an array containing the best found model parameters and (at the end) the last fit quality number.

The fitted function depends on fit, /gaussians, and /powerfunc.


If specified, then it must be a string containing the name of a function that takes arguments par, x, y, and, optionally, w, with par an array containing the current fit parameters and w the weight of each data point, and that returns the fit quality which is a positive number that is closer to zero the better the fit is. Minimization of the fit quality is then the goal of the iterations.


If fit is not specified, then this keyword selects fitting to the sum of one or more gaussian functions of the form par(0) + par(1)*exp(-((x - par(2))/par(3))^2). In this case step must have four plus a multiple of three elements, and for each extra set of three an extra gaussian is added.


If fit is not specified, then this keyword selects fitting to a general power function superimposed on a linear trend, of the form par(0) + par(1)*x + par(2)*(x - par(3))^par(4).

The fit parameters that are tried depend on start, step, lowbound, and hibound.

x y

The data points to be fitted to.


In each iteration cycle, niter different parameter sets are tried. niter defaults to 10.


contains the start values of the parameters. This array must have a number of elements equal to the number of fit parameters or the number of fit parameters plus one. In the latter case, the last element is ignored. (This is so that output from a previous call to fit can be entered as start values for the next call.)


contains the initial rms values by which the parameters are randomly varied from iteration to iteration. This array must have one element for each fitted parameter.


contains lower bounds on the parameters (default: no bounds). This array must have one element per fitted parameter.


contains upper bounds on the parameters (default: no bounds). This array must have one element per fitted parameter.

The stop criterion on the iterations depend on qthresh, pthresh, ithresh, dthresh, tthresh, and nsame, and parameter change depends on fac. Estimated errors on the parameters are returned in err.


contains a threshold on the fit quality, below which iteration is ceased. Defaults to zero.


contains thresholds on the maximum absolute change in the best-so-far parameters. When the change in the last iteration cycle is smaller than the corresponding threshold for all parameters, then the iteration is ceased [note: not yet implemented]. defaults to zero.


contains a threshold on the number of iteration cycles, above which iteration is ceased. ithresh defaults to 1000.


contains a threshold on the relative change in the fit quality since the last iteration. If the relative change is less than dthresh, then iteration is ceased. dthresh defaults to 0.


contains the maximum number of seconds that the fit process may take. If at the end of an iteration it is more than tthresh seconds later than when the fit process began, then iteration is ceased. If this variable is equal to 0, then no time threshold is applied. It defaults to 3600, i.e., one hour.


If the best-so-far parameters do not change during nsame iteration cycles, then iterations are ceased. nsame defaults to 5.


contains a factor which limits the change of the rms spread of the parameters from iteration cycle to iteration cycle. The rms spread of each parameter in the next iteration cycle equals the change in the best-so-far value of that parameter since the last iteration cycle, but is limited in change to a factor of between fac and 1/fac. fac defaults to 0.5.


If err is defined, then rough estimates for the formal errors on the parameters are returned in it.


When the best-so-far parameters do not change from one iteration cycle to the next, then the rms parameter spread is decreased (if /down is specified, or by default) or increased (if /nodown is specified) by a factor of 2 in the next iteration cycle.


selects display of best-so-far parameters after each iteration cycle. Displayed is: iteration rms-error: fit-parameters. Only those fit parameters for which the corresponding step value is unequal to zero are shown, and at most the first twenty such parameters are displayed.

See also: trend, lsq, fit

Next: , Previous: , Up: Internal Routines   [Contents][Index]