fit.5
non-linear least squares fitting functions
FIT INITIALIZATION
fc Set fit criteria and options fv [value] Set fit printout verbosity wt [i|s|n|u] Select weighting of data points gp Get values for parameters lm [# [lo hi]] Set constraints on parameters vp Select parameters to vary ra [0|#] Select range of data to fit
The # option in the ra command means you select which independent variable to use in the command (if you have more than one). If none is specified, independent variable number 1 is used. If the argument is 0,the ranges are reset to the data minimum and maximum for all independent variables.
The options selected with gp, lm, vp and ra may also be selected on the command line to the fi command (see below).
GETTING AND EXCHANGING DATA POINTS
2d Select 2D exchange mode 3d Select 3D exchange mode gd [options] Get data points from file or keyboard pg [x [y]] Get data points from plot ps [x [y]] Send data points to plot md [x [y]] [o] [p#=value ...] Make plot data (o=one-to-one) mr [x [y]] [/] [p#=value ...] Make plot residuals (/=divide by y's) sa [file [a|w]] Save fit data to screen or file sA [file [a|w]] Save plot data to screen or file
Two sets of data points are maintained: those used for fitting and those exchanged with C-PLOT and used for plotting. These commands deal with obtaining and exchanging those data points.
The x (and y in 3D mode) options in pg, ps, md and mr are used to specify which independent variable(s) (if the fit is configured for more than one) to be transferred to the plot program x (and y in 3D mode) values.
The 2d and 3d commands only affect the exchange mode with the plot program. In 2D exchange mode, only cplot x, y and possibly y error-bar values (with mr and ps)are changed, x error-bar values are set to 0. Also, the pg command only reads in values for one independent variable. The values of the other independent variables are unchanged.
The 3D exchange mode is only available if the fit is configured with more than one independent variable. In 3D exchange mode, the fit dependent variable is transferred to and from the cplot z variable. With the md command, the number-of-intervals parameters can be set to nonzero values for the x and y independent variables, to create a grid of x-y values to be created. The independent variables not sent to the plot program are held constant.
The sa and sA commands can direct output to the screen or to a file. An argument of a will append the data to a file. An argument of w will overwrite the file. The gd command uses similar syntax to C-PLOT's, but only implements modes 1, 2 and 3. (See the gd help file.) Provisions are made for reading additional independent variables if the user's function requires them, however.
FITTING AND FIT RESULTS
ch [p#=val ... ] Calculate chi squared fi [opts] Fit data points sp [file [a|w]] Save parameters sP [file [a|w]] Save parameters and errors sf [file [a|w]] Save fit results sF [file [a|w]] Save fit results and errors rp [file|. [#]] Read parameters from a file (dot means same file as before) (# is parameter set number)
Command line options for the fi command are:
fi [+|-]# ... p#=v ... L#=v ... U#=v ... n=v f#=v t#=v
The # arguments specify the parameter numbers of the parameters to be varied (can also be set with vp).An initial + or - adds or removes the specified parameter from the list of those to be varied. The expression p#=v assigns the value v to parameter # (can also be set with gp). The arguments L#=v and U#=v specify lower and upper constraints on parameter # (can also be set with lm).The n=v specifies the maximum number of iterations (can also be set with fc),while f#=v and t#=v specify the range for independent variable number # (can also be set with ra). If # is missing, independent variable 1 is used.
All changed values stay in effect for all subsequent commands.
The text saved to a file with the commands sp, sP, sf and sF is in a format appropriate for using the files as C-PLOT annotation. The output can be sent to the screen or to a file, and the file can be appended or overwritten.
COMMAND FILES
do file [args ... ] Take commands from a file mk file Save commands in a command file em End making a command file
UTILITY COMMANDS
cd [dir] Change directory h Help er Erase the screen u [cmd] Unix shell (execute cmd) V Print current version and title ex Exit program ^D Exit
DIRECTING OUTPUT TO A FILE
The sa, sA, sp, sP, sf, sF and fi commands can have output directed to a file in addition to the screen. The syntax is::
cmd [ opts ] > file
or:
cmd [ opts ] >> file
The first example opens file for writing. The second appends to file. If file is the single character ., the same file is used as last time, and the output is appended.
COMMAND FILES
Command files work just as with the cplot program. In addition, command files can be executed when the fit is invoked from cplot by putting the name of the command file after the name of the fit program::
fn program.5 cmdfile [args ...]
or:
fn . cmdfile [args ...]
With the dot, the same fit process as last time resumes.
Also, when invoking type 5 (fitting) user functions from a cplot program command file, you can arrange to have the fitting function read commands from the command file for a while and then have control returned to cplot. If the command file contains the lines:
fn fitfunc.5 - ... ex
or (to use the same fitting function as last time):
fn - ... ex
the commands between the fn command and ex will be executed by the fitting function. Any commands following ex will be read by the cplot program.
If you type a ^C while running a command file in this manner, the FIT> prompt should reappear. Any cplot command-file will be terminated on return to plot.
MORE FN OPTIONS
You can pass a series of commands to a fit function using the following syntax::
fn fit.5 cmd1; cmd2; ... fn . - cmd1; cmd2; ... fn - cmd1; cmd2; ...
The second and third examples use the currently executing function. Each semicolon-separated command in the argument list is just what you would enter on each line of input if you were running the fit function interactively. For example, the command:
fn - md; 0; 10; 100
would make 101 data points from 0 to 10.
SYMBOL NAMES
The following symbols are used within the fitting program.
- sigma
- error bar on y value (1 standard deviation).
- weight
- 1 / sigma.
- residual
- weight(i) * (y_data(i) - y_model(i)).
- phi
- sum of the residuals.
- degrees_of_freedom
- number_of_points - number_of_parameters.
- chi-squared
- phi / degrees_of_freedom.
- lambda
- Marquardt algorithm compromise parameter - large values emphasize gradient search over parabolic (Taylor series) expansion.
- gamma
- Angle (in parameter space) between gradient and direction of current iteration's step.
- step
- Length (in parameter space) of current step.