User:Petergans/b/sandbox

From Wikipedia, the free encyclopedia

Non-linear least squares, also known as non-linear regression, is the form of least squares analysis which is used to fit a set of m observations with a model that is non-linear in n unknown parameters (m>n). The basis of the method is to approximate the model by a linear one and to refine the parameters by successive iterations. There are may similarities to linear least squares, but also some significant differences.

Contents

[edit] Theory

The objective consists of finding the minimum value of a sum of m squared residuals,ri, with respect to a set of n parameters of a model.

S=\sum_{i=1}^{i=m}r_i^2

Each residual is defined as the difference between the values of a dependent variable, yi and of the model function,f(x_i, \boldsymbol \beta), where xi is an independent variable and \boldsymbol \beta is a vector of n parameters. The values of the dependent variable are obtained from experimental measurements.

r_i= y_i - f(x_i, \boldsymbol \beta)

The minimum value of S occurs when the gradient is zero. Since the model contains n parameters there are n gradient equations.

\frac{\partial S}{\partial \beta_j}=2\sum_i r_i\frac{\partial r_i}{\partial \beta_j}=0 \ (j=1,n)

Now, in in a non-linear system the derivatives \frac{\partial r_i}{\partial \beta_j} are functions of both the independent variable and the parameters, so these gradient equations do not have a closed solution. Instead, initial values must be chosen for the parameters. Then, the parameters are refined iteratively, that is, the values are obtained by successive approximation.

\beta_j^{k+1}=\beta^k_j+\Delta \beta_j

k is an iteration number and the vector of increments, \Delta \beta_j\, is known as the shift vector. At each iteration The model is linearized by approximation to a first-order Taylor series expansion about  \boldsymbol \beta^k\!

f(x_i,\boldsymbol \beta)\approx f^k(x_i,\boldsymbol \beta) +\sum_j \frac{\partial f(x_i,\boldsymbol \beta)}{\partial \beta_j} \left(\beta^k_j -\beta_j \right)=f^k(x_i,\boldsymbol \beta) +\sum_j J_{ij} \Delta\beta_j

The Jacobian, J, is a function of constants, the independent variable and the parameters, so it changes from one iteration to the next. Thus, in terms of the linearized model, \frac{\partial r_i}{\partial \beta_j}=-J_{ij} and the residuals are given by

r_i=\Delta y_i- \sum_{j=1}^{j=n} J_{ij}\Delta\beta_j; \ \Delta y_i=y_i- f^k(x_i,\boldsymbol \beta)

Substiting these expressions into the gradient equations, they become

-2\sum_{i=1}^{i=m}J_{ij} \left( \Delta y_i-\sum_{j=1}^{i=n} J_{ij}\Delta \beta_j \right)=0

which, on rearrangement, become n simultaneous linear equations, the normal equations.

\sum_{i=1}^{i=m}\sum_{k=1}^{k=n} J_{ij}J_{ik}\Delta \beta_k=\sum_{i=1}^{i=m} J_{ij}\Delta y_i (j=1,n)\,

The normal equations are written in matrix notation as

\mathbf{\left(J^TJ\right)\Delta \boldsymbol \beta=J^T\Delta y}

When the observations are not equally reliable, a weighted sum of squares may be minimized.

S=\sum_{i=1}^{i=m}W_{ii}r_i^2

Each element of the diagonal weight matrix, W should, ideally, be equal to the the reciprocal of the variance of the measurement.[1] The normal equations are then

\mathbf{\left(X^TWX\right)\hat \boldsymbol \beta=X^TWy}

These equations form the basis for the Gauss-Newton algorithm for a non-linear least squares problem.

[edit] Differences between linear and non-linear least squares

  • NLLSQ (Non-linear least squares) requires initial estimates of the parameters, LLSQ (linear least squares) does not.
  • NLLSQ requires that the Jacobian be calculated. Analytical expressions for the partial derivatives can be complicated. If analytical expressions are impossible to obtain the partial derivatives must be calculated by numerical approximation.
  • In NLLSQ divergence is a common phenomenon whereas in LLSQ it is quite rare. Divergence occurs when the sum of squares increases from one iteration to the next. It is caused by the inadequacy of the approximation that the Taylor series can be truncated at the first term.
  • NLLSQ is an iterative process, LLSQ is not. The iterative process has to be terminated when a convergence criterion is satisfied.
  • In LLSQ the solution is unique, but in NLLSQ there may be multiple minima in the sum of squares.
  • In NLLSQ estimates of the parameter errors are biased, but in LLSQ they are not.

These differences must be considered whenever the solution to a non-linear least squares problem is being sought.

[edit] Geometrical interpretation

In linear least squares the objective function, S, is a quadratic function of the parameters.

S=\sum_i W_{ii} \left(y_i-\sum_jX_{ij}\beta_j \right)^2

When there is only one parameter The graph of S with respect to that parameter will be a parabola. With two or more parameters the contours of S with respect to any pair of parameters will be concentric ellipses (assuming that the normal equations matrix \mathbf{X^TWX} is positive definite). The minimum parameter values are to be found at the centre of the ellipses. The geometry of the general objective function can be described as paraboloid elliptical. In NLLSQ the objective function is quadratic with respect to the parameters only in a region close to its minimum value, where the truncated Taylor series is a good approximation to the model.

S \approx\sum_i W_{ii} \left(y_i-\sum_j J_{ij}\beta_j \right)^2

The more the parameter values differ from their optimal values, the more the contours deviate from elliptical shape. A consequence of this is that initial parameter estimates should be as close as practicable to their (unknown!) optimal values. It also explains how divergence can come about as the Gauss-Newton algorithm is convergent only when the objective function is approximately quadratic in the parameters.

[edit] Initial parameter estimates

Problems of ill-conditioning and divergence an be ameliorated by finding initial parameter estimates that are near to the optimal values. A good way to do this is by computer simulation. Both the observed and calculated data are displayed on a screen. The parameters of the model are adjusted by hand until the agreement between observed and calculated data is reasonably good. Although this will be a subjective judgment, it is sufficient to find a good starting point for the non-linear refinement.

[edit] Computation

[edit] Unmodified Gauss-Newton method

The normal equations

\mathbf{\left( J^TWJ \right)\Delta \boldsymbol\beta=\left( J^TW \right) \Delta y}

may be solved by any of the three methods described in linear least squares, namely, Cholesky decomposition, QR decomposition or singular value decomposition[2]. The parameters are updated iteratively

\boldsymbol\beta^{k+1}=\boldsymbol\beta^k+\Delta \boldsymbol\beta

where k is an iteration number. Whilst this method may be adequate for simple models, it will fail if divergence occurs. Therefore protection against divergence is pretty much essential.

[edit] Shift-cutting

If divergence occurs, a simple expedient is to reduce the length of the shift vector, \mathbf{\Delta \beta}, by a fraction, f

\boldsymbol\beta^{k+1}=\boldsymbol\beta^k+f\Delta \boldsymbol\beta

For example the length of the shift vector may be successively halved until the new value of the objective function is less than its value at the last iteration. The fraction, f could be optimized by a line search.[3] As each trial value of f requires the objective function to be re-calculated it is not worth optimizing its value too stringently.

When using shift-cutting, the direction of the shift vector remains unchanged. This limits the applicability of the method to situations where the direction of the shift vector is not very different from what it would be if the objective function were approximately quadratic in the parameters, \boldsymbol\beta^k.

[edit] Marquardt parameter

If divergence occurs and the direction of the shift vector is so far from its "ideal" direction that shift-cutting is not very effective, that is, the fraction, f required to avoid divergence is very small, the direction must be changed. This can achieved by using the Marquardt parameter.[4] In this method the normal equations are modified

\mathbf{\left( J^TWJ +\lambda I \right)\Delta \boldsymbol \beta=\left( J^TW \right) \Delta y}

where λ is the Marquardt parameter and I is an identity matrix. Increasing the value of λ has the effect of changing both the direction and the length of the shift vector. The shift vector is rotated towards the direction of steepest descent

when \lambda \mathbf{I>>J^TWJ}, \  \mathbf{\Delta \boldsymbol \beta} \approx 1/\lambda \mathbf{J^TW \Delta y}

\mathbf{J^TW \Delta y} is the steepest descent vector. So, when λ becomes very large, the shift vector becomes a small fraction of the steepest descent vector.

Various strategies have been proposed for the determination of the Marquardt parameter. As with shift-cutting, it is wasteful to optimize this parameter too stringently. Rather, once a value has been found that brings about a reduction in the value of the objective function, that value of the parameter is carried to the next iteration, reduced if possible, or increased if need be. When reducing the value of the Marquardt parameter, there is a cut-off value below which it is safe to set it to zero, that is, to continue with the unmodified Gauss-Newton method. The cut-off value may be set equal to the smallest singular value of the Jacobian. [2] A bound for this value is given by 1/\mbox{trace} \mathbf{\left(J^TWJ \right)^{-1}}. [5]

[edit] Convergence criteria

The common sense criterion for convergence is that the sum of squares noes not decrease from one iteration to the next. However this criterion is often difficult to implement in practice, for various reasons. A useful convergence criterion is

\left|\frac{S^k-S^{k+1}}{S^k}\right|<0.0001

The value 0.0001 is somewhat arbitrary and may need to changed. In particular it may need to be increased when experimental errors are large. An alternative criterion is

\left|\frac{\Delta \beta_j}{\beta_j}\right|<0.001, j=1,n

Again, the numerical value is somewhat arbitrary; 0.001 is equivalent to specifying that each parameter should be refined to 0.1% precision. This is reasonable when it is less than the largest relative standard deviation on the parameters.

[edit] Parameter errors, confidence limits, residuals etc.

For details concerning these topics see linear least squares#Parameter errors, correlation and confidence limits

[edit] Multiple minima

Multiple minima can occur in a variety of circumstances some of which are:

  • A parameter is raised to a power of two or more. For example, when fitting data to a Lorentzian curve
f(x_i, \boldsymbol \beta)=\frac{\alpha}{1+\left(\frac{\gamma-x_i}{\beta} \right)^2}

where α is the height, γ is the position and β is the half-width at half height, there are two solutions for the half-width, \hat \beta and -\hat \beta which give the same optimal value for the objective function.

  • Two parameters can be interchanged without changing the value of the model. A simple example is when the model contains the product of two parameters, since αβ will give the same value as βα.
  • A parameter is in a trigonometric function, such as \sin \beta\,, which has identical values at \hat \beta +2n \pi. See Levenberg-Marquardt algorithm for an example.

Not all multiple minima have equal values of the objective function. False minima, also known as local minima, occur when the objective function value is greater than its value at the so-called global minimum. For example, the model

f(x_i, \beta)=\left(1-3\beta +\beta^3 \right)x_i

has a local minimum at \beta\, = 1 and a global minimum at \hat \beta\, = -3.[6]

To be certain that the minimum found is the global minimum, the refinement should be started with widely differing initial values of the parameters. When the same minimum is found regardless of starting point, it is likely to be the global minimum.

When multiple minima exist there is an important consequence: the objective function will have a maximum value somewhere between two minima. The normal equations matrix is not positive definite at a maximum in the objective function, as the gradient is zero and no unique direction of descent exists. Refinement from a point (a set of parameter values) close to a maximum will be ill-conditioned and should be avoided as a starting point. For example, when fitting a Lorenzian the normal equations matrix is not positive definite when the half-width of the band is zero.[7]

[edit] Other methods

[edit] Transformation to a linear model

A non-linear model can sometimes be transformed into a linear one. For example, when the model is a simple exponential function,

f(x_i,\boldsymbol \beta)= \alpha e^{\beta x_i}

it can be transformed into a linear model by taking logarithms.

\log f(x_i,\boldsymbol \beta)=\log \alpha + \beta x_i

The sum of squares bcomes

S=\sum_i (\log y_i-\log \alpha - \beta x_i)^2\!

This procedure should be avoided if at all possible because it can give misleading results. This comes from the fact that whatever the experimental errors on y might be, the errors on log y are different. Therefore, when the transformed sum of squares is minimized different results will be obtained both for the parameter values and their calculated standard deviations. In practice, models like the exponential model can be fitted by least squares directly to the observed quantities in a spreadsheet, using an optimizer such as SOLVER in EXCEL.

Another example is furnished by Michaelis-Menten kinetics, used to determine two parameters V_{max}\ \mbox{and}\ K_m.

 v = \frac{V_{max} [S]}{K_{m} + [S]}

The Lineweaver-Burk plot

 \frac{1}{v} = \frac{1}{V_{max}} + \frac{K_m}{V_{max}[S]}

of 1/v against [S] is very sensitive to data error and it is strongly biased toward fitting the data in a particular range of the independent variable, [S].

[edit] Gradient methods

There are many examples in the scientific literature where different methods have been used for non-linear data-fitting problems. Before outlining some of them it is important to recognize that the Gauss-Newton-Marquardt method is by far the most effective method.

  • Calculation of the Jacobian by numerical approximation.

There are models for which it is either very difficult or even impossible to derive analytical expressions for the elements of the Jacobian. Then, the numerical approximation

\frac{\partial f(x_i, \boldsymbol \beta)}{\partial \beta_j} \approx \frac{\delta f(x_i, \boldsymbol \beta)}{\delta \beta_j}

is obtained by calculation of f(x_i, \boldsymbol \beta)\, for \beta_j\, and \beta_j+\delta \beta_j\,. The increment,\delta \beta_j\,, size should be chosen so the numerical derivative is not subject to approximation error by being too large, or round-off error by being too small.

f(x_i, \boldsymbol \beta)=f^k(x_i, \boldsymbol \beta) +\sum_j J_{ij} \Delta \beta_j + \frac{1}{2}\sum_j\sum_k \Delta\beta_j \Delta\beta_k H_{jk_{(i)}},\ H_{jk_{(i)}}=\frac{\partial^2 f(x_i, \boldsymbol \beta)}{\partial \beta_j \partial \beta_k }

The matrix, H is known as the Hessian matrix. Although this model has better convergence properties near to the minimum, it is much worse when the parameters are far from their optimal values. Calculation of the Hessian adds to the complexity of the algorithm. This method is not in general use.

  • Davidon-Fletcher-Powell method. This method, a form of pseudo-Newton method, is similar to the one above but calculates the Hessian by successive approximation, to avoid having to use analytical expressions for the second derivatives.
  • Steepest descent. Although a reduction in the sum of squares is guaranteed when the shift vector points in the direction of steepest descent, this method often performs poorly. When the parameter values are far from optimal the direction of the steepest descent vector, which is normal (perpendicular) to the contours of the objective function, is very different from the direction of the Gauss-Newton vector. This makes divergence much more likely, especially as the minimum along the direction of steepest descent may correspond to a small fraction of the length of the steepest descent vector. When the contours of the objective function are very eccentric, due to there being high correlation between parameters. the steepest descent iterations, with shift-cutting, follow a slow, zig-zag trajectory towards the minimum.

[edit] Direct search methods

Direct search methods depend on evaluations of the objective function at a variety of parameter values and do not use derivatives at all. They offer alternatives to the use of numerical derivatives in the Gauss-Newton method. However, only the conjugate gradient method has the quadratic convergence property that the Gauss-Newton method has. .

  • Alternating variable search.[3] Each parameter is varied in turn by adding a fixed or variable increment to it and retaining the value that brings about a reduction in the sum of squares. The method is simple and effective when the parameters are not highly correlated. It has very poor convergence properties, but may be useful for finding initial parameter estimates.
  • Conjugate gradient search. This is a powerful method with good convergence properties.[8]
  • Nelder-Mead (Simplex) search A simplex in this context is a polytope of n + 1 vertices in n dimensions; a triangle on a plane, a tetrahedron in three-dimensional space and so forth. Each vertex corresponds to a value of the objective function for a particular set of parameters. The shape and size of the simplex is adjusted by varying the parameters in such a way that the value of the objective function at the highest vertex always decreases. Although the sum of squares usually decreases rapidly at first, convergence properties are poor.

More detailed descriptions of these, and other, methods are available, in Numerical Recipes, together with computer code in various languages.

[edit] See also

[edit] References

  1. ^ This implies that the observations are uncorrelated. If the observations are correlated, the expression
    S=\sum_k \sum_j r_k W_{kj} r_j\,
    applies. In this case the weight matrix should ideally be equal to the inverse of the variance-covariance matrix of the observations.
  2. ^ a b C.L. Lawson and R.J. Hanson, Solving Least Squares Problems, Prentice-Hall,1974
  3. ^ a b M.J. Box, D. Davies and W.H. Swann, Non-Linear optimisation Techniques, Oliver & Boyd, 1969
  4. ^ This technique was proposed independently by Levenberg (1944), Girard (1958), Wynne (1959), Morrison (1960) and Marquardt (1963). Marquardt's name alone is used for it in much of the scientific literature.
  5. ^ R. Fletcher, UKAEA Report AERE-R 6799, H.M. Stationery Office, 1971
  6. ^ P. Gans, Data Fitting in the Chemical Sciences, Wiley, 1992, p71. \frac{\partial S}{\partial \beta} is a quintic in β; it has another root at β = -1, a local maximum in S, and two complex roots.
  7. ^ In the absence of round-off error and of experimental error in the independent variable the normal equations matrix would be singular
  8. ^ M.J.D. Powell, Computer Journal, (1964), 7, 155.