In the course of data analysis, it is often necessary to fit non-XAFS data.
This can be any task similar to fitting a line or quadratic function to a
set of data (say
v.T), fitting a set of Lorentzian, Gaussian
and/or arc-tangent functions to a XANES spectra, or fitting some weighted
average of model XANES spectra to fit an unknown spectra. Building on the
general data-processing and XAFS modeling capabilities, IFEFFIT
provides a simple and powerful way to model many kinds of data.
The minimize() command implements a simple least-squares minimization routine. It takes as its primary argument a residual array to minimize in the least-squares sense. Usually the residual would be ``Data - Fit'', but you may want to provide some scaling, possibly emphasizing some region of the fit more than others.
The residual array is built just like any other array, and is expected to depend through definitions on a few variables defined with guess(). A very simple example would be a linear fit:
Ifeffit>read_data(my_data.dat, group = 'data', label = 'x y') Ifeffit>guess ( m = 1, b = 0 ) Ifeffit>fit.y = m * data.x + b Ifeffit>fit.resid = fit.y - data.y Ifeffit>minimize(fit.resid)This will adjust the variables m and b to best-fit the data. As with feffit(), the fitting statistics &fit_iteration, chi_square, chi_reduced, and r_factor will be written and uncertainties in the variables delta_m and delta_b will be created for the uncertainties in the fitted parameters. The correl() function described above can be used to retrieve the correlation between 2 fitting variables. Since the general problem of estimating uncertainties in experimental data is difficult, you'll need to be quite mindful of this fact and careful when interpreting these fitting statistics.
In order to specify an estimate of the uncertainty in the experimental data, create an array (of the same size as the residual array) containing the estimated uncertainty at each point, and tell minimize() to use this with the uncertainty argument:
Ifeffit> fit.eps = 0.01 * indarr(npts(fit.resid)) Ifeffit> minimize(fit.resid, uncertainty = fit.eps)
If you wish to limit the fit to be over a limited range of the residual array, you need to tell minimize() what array to use as the ordinate or ``x''-array, and the minimum and maximum ``x'' values to use:
Ifeffit> minimize(fit.resid, x =data.x, xmin= 2, xmax =10)There are several built-in special mathematical functions to aid in the modeling of data - more information can be found in the Reference Guide.