esfit

Least-squares fitting of EPR spectra, single and multiple components.

Syntax
esfit(SimFnc,expSpc,Sys0,Vary,Exp);
esfit(SimFnc,expSpc,Sys0,Vary,Exp,SimOpt);
esfit(SimFnc,expSpc,Sys0,Vary,Exp,SimOpt,FitOpt);
BestSys = esfit(...)
[BestSys,BestSpc] = esfit(...)

See also the user guide on fitting.

Description

esfit fits EPR spectra simulated with garlic, pepper, chili etc. to experimental spectral data using least-squares fitting algorithms.

If no output is requested, esfit start an interactive user interface that allows extensive control over the fitting process and also allows the export of the fitting results to the workspace. In the UI, the fitting algorithm can be changed, parameters can be excluded from the fit, and multiple fit set can be stored.

If the user interface is not desired, then esfit should be called with one or two output arguments:

The input parameters are the following:

The structure FitOpt contains fitting options. The most important ones select the fitting algorithm and the function to use for computing the residuals:

Method
A string indicating the least-squares fitting method to be used, consisting of up to two keywords. One keyword specifies the algorithm, and another one selects the way residuals are computed. Some examples:
FitOpt.Method = 'simplex fcn';
FitOpt.Method = 'genetic int';

The keywords for choosing one of the available algorithm are

If you don't specify anything, the default 'simplex' is used.

The second keyword specifies what the residuals and consequently the root-mean-square deviation (rmsd) should be computed from. Usually the residuals are computed by taking the difference of the experimental and the simulated spectrum. However, the spectra can be transformed before computing the residuals.

The default value is 'fcn'. If there are many resolved lines, 'int' gives better convergence.
Scaling
This string specifies the scaling method. There are different ways a simulated spectrum can be scaled and shifted to overlap as much as possible with the experimental one. The possible values are

If the baseline of the experimental spectra has been corrected beforehand, the best choice is 'maxabs'. This is also the default value. If the noise level is high, 'lsq' is a better choice:

FitOpt.Scaling = 'lsq';
To include corrections for a baseline in the expermental spectrum, use 'lsq0, 'lsq1, or 'lsq2.

There are some more options which are recognized by all fitting algorithms:

OutArg
This is an array with two numbers [nArgOut useArg] that tells esfit how to use the output arguments of the simulation function. nArgOut is the number of outputs provided by the function. esfit will call the function asking for this number of outputs. The second number, useArg, tells esfit which of the output arguments actually contains the simulated data.

E.g. OutArg = [3 2] indicates to call the function asking for three outputs and then to use output number 2 for the fitting.

For the common EasySpin simulation function, OutArg is chosen automatically. For custom simulation functions that deviate in their output behavior, OutArg might be useful.

maxTime
Time, in minutes, after which esfit will terminate even if the fitting has not yet converged.
PrintLevel
A number, 0 or 1. If set to 0, the fitting functions don't write anything to the command window. If set to 1 (default), they print information about the progress of the fitting.

Each of the available fitting algorithms can be fine-tuned using a set of parameters.

Parameters for Nelder/Mead downhill simplex:

RandomStart
If set to 1, the starting point in the parameter space is chosen randomly, within the given limits. If set to 0, the center of the parameter space is used as starting point. By default, RandomStart is 0.
TolEdgeLength
Termination tolerance for the length of the parameter step. This number refers to the rescaled fitting parameters, as described above.
TolFun
Termination tolerance for function value change.
SimplexPars
An array of four elements [rho chi psi sigma], where rho is the reflection coefficient, chi is the expansion coefficient, psi is the contraction coefficient, and sigma is the shrink coefficient. The default values are [1,2,0.5,0.5].
delta
Size parameter of the initial simplex. The default value is 0.1.

Parameters for Levenberg-Marquardt:

RandomStart
If set to 1, the starting point in the parameter space is chosen randomly, within the given limits. If set to 0, the center of the parameter space is used as starting point. By default, RandomStart is 0.
TolStep
Termination tolerance for the length of the parameter step. This number refers to the rescaled fitting parameters, as described above.
TolFun
Termination tolerance for function value change.
lambda
Starting value of Marquardt parameter λ, default value is 0.001.
delta
Step size for computing the finite-difference approximation of the Jacobian. Default is 1e-7.

Parameters for Monte Carlo:

nTrials
Number of random trial simulations.
TolFun
Termination tolerance for error function value change.

Parameters for the genetic algorithm:

PopulationSize
A number giving the size of the population, that is the number of parameter sets and simulations in one generation. The default value is 20, but for fittings with many parameters, this value should be increased.
maxGenerations
A number specifying the maximum number of generations the algorithm should run. After this number has been reached, the algorithm terminates, no matter how good or bad the best fit so far is. The default value is 40, but has to increased for fittings with many parameters. If only very few parameters are fitted, maxGenerations can be decreased.

Parameters for the grid search:

GridSize
A number or an array that specifies how many grid points there should be for each parameter. If one number is given, it is valid for all parameters. For example, let's assume that one g value and the linewidth are being fitted:
Vary.g = [0 0.001 0]; Vary.lw = 0.2;
Then GridSize can contain 1 or 2 numbers:
FitOpt.GridSize = 10;   % 10 points for each parameter, making 100 grid points total
FitOpt.GridSize = [20 3]; % 10 points along g and 3 along lw, giving a total of 60

Parameters for the particle swarm algorithm:

nParticles
Number of particles in the particle swarm.
TolFun
Termination tolerance for function value change.
SwarmParams
A vector of four parameters for the algorithm, [k w c1 c2]. k is the velocity limit and determines how far a particle can move in an iteration (default 0.2). w is the inertial coefficient (default 0.5) and describes the propensity of the particle of moving in the same direction as in the iteration before. c1 is the cognitive coefficient (default 2) and determines to what degree a particle moves towards the currently optimal point. c2 is the social coeffient (default 1) and describes how much the particle is following the other particles. Together, k, c1 and c2 determine in which direction a particle will move in a given iteration.
Algorithms

Internally, esfit rescales the parameters to be fitted. E.g. if the linewidth should be fitted and is expected to be around 5 mT, plus minus about 1.5 mT, Sys.lw = 3; and Vary.lw = 1.5. After rescaling, esfit treats 5 mT as x = 0, 3.5 mT as -1 and 6.5 mT as +1.

For details about the algorithms implemented in esfit, see e.g.

Examples

Here is a very simple example. Let's assume the experimental data are stored in expspec. Then the following code performs a least-squares fitting using the simplex algorithm.

Exp.mwFreq = 9.5;
Sys0.g = [2.1 2.2]
Sys0.lwpp = 0.1;
Vary.g = [0.05 0.02];
esfit('pepper',expspc,Sys0,Vary,Exp);

See the example section for a full example. Also, read the user guide about fitting.

See also

chili, garlic, pepper