# Gauss–Newton algorithm

Fitting of a noisy curve by an asymmetrical peak model, using the Gauss–Newton algorithm with variable damping factor α.
Top: raw data and model.
Bottom: evolution of the normalised sum of the squares of the errors.

The Gauss–Newton algorithm is used to solve non-linear least squares problems. It is a modification of Newton's method for finding a minimum of a function. Unlike Newton's method, the Gauss–Newton algorithm can only be used to minimize a sum of squared function values, but it has the advantage that second derivatives, which can be challenging to compute, are not required.

Non-linear least squares problems arise, for instance, in non-linear regression, where parameters in a model are sought such that the model is in good agreement with available observations.

The method is named after the mathematicians Carl Friedrich Gauss and Isaac Newton.

## DescriptionEdit

Given m functions r = (r1, …, rm) (often called residuals) of n variables β = (β1, …, βn), with m ≥ n, the Gauss–Newton algorithm iteratively finds the value of the variables that minimizes the sum of squares[1]

${\displaystyle S({\boldsymbol {\beta }})=\sum _{i=1}^{m}r_{i}^{2}({\boldsymbol {\beta }}).}$

Starting with an initial guess ${\displaystyle {\boldsymbol {\beta }}^{(0)}}$  for the minimum, the method proceeds by the iterations

${\displaystyle {\boldsymbol {\beta }}^{(s+1)}={\boldsymbol {\beta }}^{(s)}-\left(\mathbf {J_{r}} ^{\mathsf {T}}\mathbf {J_{r}} \right)^{-1}\mathbf {J_{r}} ^{\mathsf {T}}\mathbf {r} ({\boldsymbol {\beta }}^{(s)}),}$

where, if r and β are column vectors, the entries of the Jacobian matrix are

${\displaystyle (\mathbf {J_{r}} )_{ij}={\frac {\partial r_{i}({\boldsymbol {\beta }}^{(s)})}{\partial \beta _{j}}},}$

and the symbol ${\displaystyle ^{\mathsf {T}}}$  denotes the matrix transpose.

If m = n, the iteration simplifies to

${\displaystyle {\boldsymbol {\beta }}^{(s+1)}={\boldsymbol {\beta }}^{(s)}-\left(\mathbf {J_{r}} \right)^{-1}\mathbf {r} ({\boldsymbol {\beta }}^{(s)}),}$

which is a direct generalization of Newton's method in one dimension.

In data fitting, where the goal is to find the parameters β such that a given model function y = f(x, β) best fits some data points (xi, yi), the functions ri are the residuals:

${\displaystyle r_{i}({\boldsymbol {\beta }})=y_{i}-f(x_{i},{\boldsymbol {\beta }}).}$

Then, the Gauss–Newton method can be expressed in terms of the Jacobian Jf of the function f as

${\displaystyle {\boldsymbol {\beta }}^{(s+1)}={\boldsymbol {\beta }}^{(s)}+\left(\mathbf {J_{f}} ^{\mathsf {T}}\mathbf {J_{f}} \right)^{-1}\mathbf {J_{f}} ^{\mathsf {T}}\mathbf {r} ({\boldsymbol {\beta }}^{(s)}).}$

Note that ${\displaystyle \left(\mathbf {J_{f}} ^{\mathsf {T}}\mathbf {J_{f}} \right)^{-1}\mathbf {J_{f}} ^{\mathsf {T}}}$  is the pseudoinverse of ${\displaystyle \mathbf {J_{f}} }$ .

## NotesEdit

The assumption m ≥ n in the algorithm statement is necessary, as otherwise the matrix JrTJr is not invertible and the normal equations cannot be solved (at least uniquely).

The Gauss–Newton algorithm can be derived by linearly approximating the vector of functions ri. Using Taylor's theorem, we can write at every iteration:

${\displaystyle \mathbf {r} ({\boldsymbol {\beta }})\approx \mathbf {r} ({\boldsymbol {\beta }}^{(s)})+\mathbf {J_{r}} ({\boldsymbol {\beta }}^{(s)})\Delta }$

with ${\displaystyle \Delta ={\boldsymbol {\beta }}-{\boldsymbol {\beta }}^{(s)}}$ . The task of finding Δ minimizing the sum of squares of the right-hand side, i.e.,

${\displaystyle \min \left\|\mathbf {r} ({\boldsymbol {\beta }}^{(s)})+\mathbf {J_{r}} ({\boldsymbol {\beta }}^{(s)})\Delta \right\|_{2}^{2},}$

is a linear least-squares problem, which can be solved explicitly, yielding the normal equations in the algorithm.

The normal equations are n simultaneous linear equations in the unknown increments Δ. They may be solved in one step, using Cholesky decomposition, or, better, the QR factorization of Jr. For large systems, an iterative method, such as the conjugate gradient method, may be more efficient. If there is a linear dependence between columns of Jr, the iterations will fail, as JrTJr becomes singular.

## ExampleEdit

Calculated curve obtained with ${\displaystyle {\hat {\beta }}_{1}=0.362}$  and ${\displaystyle {\hat {\beta }}_{2}=0.556}$  (in blue) versus the observed data (in red).

In this example, the Gauss–Newton algorithm will be used to fit a model to some data by minimizing the sum of squares of errors between the data and model's predictions.

In a biology experiment studying the relation between substrate concentration [S] and reaction rate in an enzyme-mediated reaction, the data in the following table were obtained.

 i [S] rate 1 2 3 4 5 6 7 0.038 0.194 0.425 0.626 1.253 2.5 3.74 0.05 0.127 0.094 0.2122 0.2729 0.2665 0.3317

It is desired to find a curve (model function) of the form

${\displaystyle {\text{rate}}={\frac {V_{\text{max}}[S]}{K_{M}+[S]}}}$

that fits best the data in the least-squares sense, with the parameters ${\displaystyle V_{\text{max}}}$  and ${\displaystyle K_{M}}$  to be determined.

Denote by ${\displaystyle x_{i}}$  and ${\displaystyle y_{i}}$  the value of [S] and the rate from the table, ${\displaystyle i=1,\dots ,7}$ . Let ${\displaystyle \beta _{1}=V_{\text{max}}}$  and ${\displaystyle \beta _{2}=K_{M}}$ . We will find ${\displaystyle \beta _{1}}$  and ${\displaystyle \beta _{2}}$  such that the sum of squares of the residuals

${\displaystyle r_{i}=y_{i}-{\frac {\beta _{1}x_{i}}{\beta _{2}+x_{i}}}\quad (i=1,\dots ,7)}$

is minimized.

The Jacobian ${\displaystyle \mathbf {J_{r}} }$  of the vector of residuals ${\displaystyle r_{i}}$  with respect to the unknowns ${\displaystyle \beta _{j}}$  is a ${\displaystyle 7\times 2}$  matrix with the ${\displaystyle i}$ -th row having the entries

${\displaystyle {\frac {\partial r_{i}}{\partial \beta _{1}}}=-{\frac {x_{i}}{\beta _{2}+x_{i}}}{\frac {\partial r_{i}}{\partial \beta _{2}}}={\frac {\beta _{1}x_{i}}{(\beta _{2}+x_{i})^{2}}}.}$

Starting with the initial estimates of ${\displaystyle \beta _{1}=0.9}$  and ${\displaystyle \beta _{2}=0.2}$ , after five iterations of the Gauss–Newton algorithm the optimal values ${\displaystyle {\hat {\beta }}_{1}=0.362}$  and ${\displaystyle {\hat {\beta }}_{2}=0.556}$  are obtained. The sum of squares of residuals decreased from the initial value of 1.445 to 0.00784 after the fifth iteration. The plot in the figure on the right shows the curve determined by the model for the optimal parameters with the observed data.

## Convergence propertiesEdit

It can be shown[2] that the increment Δ is a descent direction for S, and, if the algorithm converges, then the limit is a stationary point of S. However, convergence is not guaranteed, not even local convergence as in Newton's method, or convergence under the usual Wolfe conditions.[3]

The rate of convergence of the Gauss–Newton algorithm can approach quadratic.[4] The algorithm may converge slowly or not at all if the initial guess is far from the minimum or the matrix ${\displaystyle \mathbf {J_{r}^{\mathsf {T}}J_{r}} }$  is ill-conditioned. For example, consider the problem with ${\displaystyle m=2}$  equations and ${\displaystyle n=1}$  variable, given by

{\displaystyle {\begin{aligned}r_{1}(\beta )&=\beta +1,\\r_{2}(\beta )&=\lambda \beta ^{2}+\beta -1.\end{aligned}}}

The optimum is at ${\displaystyle \beta =0}$ . (Actually the optimum is at ${\displaystyle \beta =-1}$  for ${\displaystyle \lambda =2}$ , because ${\displaystyle S(0)=1^{2}+(-1)^{2}=2}$ , but ${\displaystyle S(-1)=0}$ .) If ${\displaystyle \lambda =0}$ , then the problem is in fact linear and the method finds the optimum in one iteration. If |λ| < 1, then the method converges linearly and the error decreases asymptotically with a factor |λ| at every iteration. However, if |λ| > 1, then the method does not even converge locally.[5]

## Derivation from Newton's methodEdit

In what follows, the Gauss–Newton algorithm will be derived from Newton's method for function optimization via an approximation. As a consequence, the rate of convergence of the Gauss–Newton algorithm can be quadratic under certain regularity conditions. In general (under weaker conditions), the convergence rate is linear.[6]

The recurrence relation for Newton's method for minimizing a function S of parameters ${\displaystyle {\boldsymbol {\beta }}}$  is

${\displaystyle {\boldsymbol {\beta }}^{(s+1)}={\boldsymbol {\beta }}^{(s)}-\mathbf {H} ^{-1}\mathbf {g} ,}$

where g denotes the gradient vector of S, and H denotes the Hessian matrix of S. Since ${\displaystyle S=\sum _{i=1}^{m}r_{i}^{2}}$ , the gradient is given by

${\displaystyle g_{j}=2\sum _{i=1}^{m}r_{i}{\frac {\partial r_{i}}{\partial \beta _{j}}}.}$

Elements of the Hessian are calculated by differentiating the gradient elements, ${\displaystyle g_{j}}$ , with respect to ${\displaystyle \beta _{k}}$ :

${\displaystyle H_{jk}=2\sum _{i=1}^{m}\left({\frac {\partial r_{i}}{\partial \beta _{j}}}{\frac {\partial r_{i}}{\partial \beta _{k}}}+r_{i}{\frac {\partial ^{2}r_{i}}{\partial \beta _{j}\partial \beta _{k}}}\right).}$

The Gauss–Newton method is obtained by ignoring the second-order derivative terms (the second term in this expression). That is, the Hessian is approximated by

${\displaystyle H_{jk}\approx 2\sum _{i=1}^{m}J_{ij}J_{ik},}$

where ${\displaystyle J_{ij}={\frac {\partial r_{i}}{\partial \beta _{j}}}}$  are entries of the Jacobian Jr. The gradient and the approximate Hessian can be written in matrix notation as

${\displaystyle \mathbf {g} =2\mathbf {J} _{\mathbf {r} }^{\mathsf {T}}\mathbf {r} ,\quad \mathbf {H} \approx 2\mathbf {J} _{\mathbf {r} }^{\mathsf {T}}\mathbf {J_{r}} .}$

These expressions are substituted into the recurrence relation above to obtain the operational equations

${\displaystyle {\boldsymbol {\beta }}^{(s+1)}={\boldsymbol {\beta }}^{(s)}+\Delta ;\quad \Delta =-\left(\mathbf {J_{r}} ^{\mathsf {T}}\mathbf {J_{r}} \right)^{-1}\mathbf {J_{r}} ^{\mathsf {T}}\mathbf {r} .}$

Convergence of the Gauss–Newton method is not guaranteed in all instances. The approximation

${\displaystyle \left|r_{i}{\frac {\partial ^{2}r_{i}}{\partial \beta _{j}\partial \beta _{k}}}\right|\ll \left|{\frac {\partial r_{i}}{\partial \beta _{j}}}{\frac {\partial r_{i}}{\partial \beta _{k}}}\right|}$

that needs to hold to be able to ignore the second-order derivative terms may be valid in two cases, for which convergence is to be expected:[7]

1. The function values ${\displaystyle r_{i}}$  are small in magnitude, at least around the minimum.
2. The functions are only "mildly" nonlinear, so that ${\displaystyle {\frac {\partial ^{2}r_{i}}{\partial \beta _{j}\partial \beta _{k}}}}$  is relatively small in magnitude.

## Improved versionsEdit

With the Gauss–Newton method the sum of squares of the residuals S may not decrease at every iteration. However, since Δ is a descent direction, unless ${\displaystyle S({\boldsymbol {\beta }}^{s})}$  is a stationary point, it holds that ${\displaystyle S({\boldsymbol {\beta }}^{s}+\alpha \Delta )  for all sufficiently small ${\displaystyle \alpha >0}$ . Thus, if divergence occurs, one solution is to employ a fraction ${\displaystyle \alpha }$  of the increment vector Δ in the updating formula:

${\displaystyle {\boldsymbol {\beta }}^{s+1}={\boldsymbol {\beta }}^{s}+\alpha \Delta .}$ .

In other words, the increment vector is too long, but it points in "downhill", so going just a part of the way will decrease the objective function S. An optimal value for ${\displaystyle \alpha }$  can be found by using a line search algorithm, that is, the magnitude of ${\displaystyle \alpha }$  is determined by finding the value that minimizes S, usually using a direct search method in the interval ${\displaystyle 0<\alpha <1}$ .

In cases where the direction of the shift vector is such that the optimal fraction α is close to zero, an alternative method for handling divergence is the use of the Levenberg–Marquardt algorithm, also known as the "trust region method".[1] The normal equations are modified in such a way that the increment vector is rotated towards the direction of steepest descent,

${\displaystyle \left(\mathbf {J^{\mathrm {T} }J+\lambda D} \right)\Delta =-\mathbf {J} ^{\mathrm {T} }\mathbf {r} ,}$

where D is a positive diagonal matrix. Note that when D is the identity matrix I and ${\displaystyle \lambda \to +\infty }$ , then ${\displaystyle \lambda \Delta =\lambda \left(\mathbf {J^{\mathrm {T} }J} +\lambda \mathbf {I} \right)^{-1}\left(-\mathbf {J} ^{\mathrm {T} }\mathbf {r} \right)=\left(\mathbf {I} -\mathbf {J^{\mathrm {T} }J} /\lambda +\cdots \right)\left(-\mathbf {J} ^{\mathrm {T} }\mathbf {r} \right)\to -\mathbf {J} ^{\mathrm {T} }\mathbf {r} }$ , therefore the direction of Δ approaches the direction of the negative gradient ${\displaystyle -\mathbf {J} ^{\mathrm {T} }\mathbf {r} }$ .

The so-called Marquardt parameter ${\displaystyle \lambda }$  may also be optimized by a line search, but this is inefficient, as the shift vector must be recalculated every time ${\displaystyle \lambda }$  is changed. A more efficient strategy is this: When divergence occurs, increase the Marquardt parameter until there is a decrease in S. Then retain the value from one iteration to the next, but decrease it if possible until a cut-off value is reached, when the Marquardt parameter can be set to zero; the minimization of S then becomes a standard Gauss–Newton minimization.

## Large-scale optimizationEdit

For large-scale optimization, the Gauss–Newton method is of special interest because it is often (though certainly not always) true that the matrix ${\displaystyle \mathbf {J} _{\mathbf {r} }}$  is more sparse than the approximate Hessian ${\displaystyle \mathbf {J} _{\mathbf {r} }^{\mathsf {T}}\mathbf {J_{r}} }$ . In such cases, the step calculation itself will typically need to be done with an approximate iterative method appropriate for large and sparse problems, such as the conjugate gradient method.

In order to make this kind of approach work, one needs at least an efficient method for computing the product

${\displaystyle \mathbf {J} _{\mathbf {r} }^{\mathsf {T}}\mathbf {J_{r}} \mathbf {p} }$

for some vector p. With sparse matrix storage, it is in general practical to store the rows of ${\displaystyle \mathbf {J} _{\mathbf {r} }}$  in a compressed form (e.g., without zero entries), making a direct computation of the above product tricky due to the transposition. However, if one defines ci as row i of the matrix ${\displaystyle \mathbf {J} _{\mathbf {r} }}$ , the following simple relation holds:

${\displaystyle \mathbf {J} _{\mathbf {r} }^{\mathsf {T}}\mathbf {J_{r}} \mathbf {p} =\sum _{i}\mathbf {c} _{i}(\mathbf {c} _{i}\cdot \mathbf {p} ),}$

so that every row contributes additively and independently to the product. In addition to respecting a practical sparse storage structure, this expression is well suited for parallel computations. Note that every row ci is the gradient of the corresponding residual ri; with this in mind, the formula above emphasizes the fact that residuals contribute to the problem independently of each other.

## Related algorithmsEdit

In a quasi-Newton method, such as that due to Davidon, Fletcher and Powell or Broyden–Fletcher–Goldfarb–Shanno (BFGS method) an estimate of the full Hessian ${\displaystyle {\frac {\partial ^{2}S}{\partial \beta _{j}\partial \beta _{k}}}}$  is built up numerically using first derivatives ${\displaystyle {\frac {\partial r_{i}}{\partial \beta _{j}}}}$  only so that after n refinement cycles the method closely approximates to Newton's method in performance. Note that quasi-Newton methods can minimize general real-valued functions, whereas Gauss–Newton, Levenberg–Marquardt, etc. fits only to nonlinear least-squares problems.

Another method for solving minimization problems using only first derivatives is gradient descent. However, this method does not take into account the second derivatives even approximately. Consequently, it is highly inefficient for many functions, especially if the parameters have strong interactions.

## NotesEdit

1. ^ a b Björck (1996)
2. ^ Björck (1996), p. 260.
3. ^ Mascarenhas (2013), "The divergence of the BFGS and Gauss Newton Methods", Mathematical Programming, 147 (1): 253–276, arXiv:, doi:10.1007/s10107-013-0720-6
4. ^ Björck (1996), p. 341, 342.
5. ^ Fletcher (1987), p. 113.
6. ^ http://www.henley.ac.uk/web/FILES/maths/09-04.pdf
7. ^ Nocedal (1999), p. 259.