NAG Library Routine Document
E04FCF
1 Purpose
E04FCF is a comprehensive algorithm for finding an unconstrained minimum of a sum of squares of nonlinear functions in variables . No derivatives are required.
The routine is intended for functions which have continuous first and second derivatives (although it will usually work even if the derivatives have occasional discontinuities).
2 Specification
SUBROUTINE E04FCF ( |
M, N, LSQFUN, LSQMON, IPRINT, MAXCAL, ETA, XTOL, STEPMX, X, FSUMSQ, FVEC, FJAC, LDFJAC, S, V, LDV, NITER, NF, IW, LIW, W, LW, IFAIL) |
INTEGER |
M, N, IPRINT, MAXCAL, LDFJAC, LDV, NITER, NF, IW(LIW), LIW, LW, IFAIL |
REAL (KIND=nag_wp) |
ETA, XTOL, STEPMX, X(N), FSUMSQ, FVEC(M), FJAC(LDFJAC,N), S(N), V(LDV,N), W(LW) |
EXTERNAL |
LSQFUN, LSQMON |
|
3 Description
E04FCF is essentially identical to the subroutine LSQNDN in the NPL Algorithms Library. It is applicable to problems of the form
where
and
. (The functions
are often referred to as ‘residuals’.)
You must supply
LSQFUN to calculate the values of the
at any point
.
From a starting point
supplied by you, the routine generates a sequence of points
, which is intended to converge to a local minimum of
. The sequence of points is given by
where the vector
is a direction of search, and
is chosen such that
is approximately a minimum with respect to
.
The vector used depends upon the reduction in the sum of squares obtained during the last iteration. If the sum of squares was sufficiently reduced, then is an approximation to the Gauss–Newton direction; otherwise additional function evaluations are made so as to enable to be a more accurate approximation to the Newton direction.
The method is designed to ensure that steady progress is made whatever the starting point, and to have the rapid ultimate convergence of Newton's method.
4 References
Gill P E and Murray W (1978) Algorithms for the solution of the nonlinear least-squares problem SIAM J. Numer. Anal. 15 977–992
5 Parameters
- 1: M – INTEGERInput
- 2: N – INTEGERInput
On entry: the number of residuals, , and the number of variables, .
Constraint:
.
- 3: LSQFUN – SUBROUTINE, supplied by the user.External Procedure
LSQFUN must calculate the vector of values
at any point
. (However, if you do not wish to calculate the residuals at a particular
, there is the option of setting a parameter to cause E04FCF to terminate immediately.)
The specification of
LSQFUN is:
INTEGER |
IFLAG, M, N, IW(LIW), LIW, LW |
REAL (KIND=nag_wp) |
XC(N), FVEC(M), W(LW) |
|
- 1: IFLAG – INTEGERInput/Output
On entry: has a non-negative value.
On exit: if
LSQFUN resets
IFLAG to some negative number, E04FCF will terminate immediately, with
IFAIL set to your setting of
IFLAG.
- 2: M – INTEGERInput
On entry: , the numbers of residuals.
- 3: N – INTEGERInput
On entry: , the numbers of variables.
- 4: XC(N) – REAL (KIND=nag_wp) arrayInput
On entry: the point at which the values of the are required.
- 5: FVEC(M) – REAL (KIND=nag_wp) arrayOutput
On exit: unless
IFLAG is reset to a negative number,
must contain the value of
at the point
, for
.
- 6: IW(LIW) – INTEGER arrayWorkspace
- 7: LIW – INTEGERInput
- 8: W(LW) – REAL (KIND=nag_wp) arrayWorkspace
- 9: LW – INTEGERInput
LSQFUN is called with these parameters as in the call to E04FCF, so you can pass quantities to
LSQFUN from the subroutine which calls E04FCF by using partitions of
IW and
W beyond those used as workspace by E04FCF. However, because of the danger of mistakes in partitioning, it is recommended that this facility be used very selectively, e.g., for stable applications packages which need to pass their own variable dimension workspace to
LSQFUN. It is
recommended that the normal method for passing information from your subroutine to
LSQFUN should be via COMMON global variables. In any case, you
must not change LIW,
LW or the elements of
IW and
W used as workspace by E04FCF.
LSQFUN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which E04FCF is called. Parameters denoted as
Input must
not be changed by this procedure.
Note: LSQFUN should be tested separately before being used in conjunction with E04FCF.
- 4: LSQMON – SUBROUTINE, supplied by the NAG Library or the user.External Procedure
If
, you must supply
LSQMON which is suitable for monitoring the minimization process.
LSQMON must not change the values of any of its parameters.
If
, the dummy routine E04FDZ can be used as
LSQMON.
The specification of
LSQMON is:
SUBROUTINE LSQMON ( |
M, N, XC, FVEC, FJAC, LDFJAC, S, IGRADE, NITER, NF, IW, LIW, W, LW) |
INTEGER |
M, N, LDFJAC, IGRADE, NITER, NF, IW(LIW), LIW, LW |
REAL (KIND=nag_wp) |
XC(N), FVEC(M), FJAC(LDFJAC,N), S(N), W(LW) |
|
Important: the dimension declaration for
FJAC must contain the variable
LDFJAC, not an integer constant.
- 1: M – INTEGERInput
On entry: , the numbers of residuals.
- 2: N – INTEGERInput
On entry: , the numbers of variables.
- 3: XC(N) – REAL (KIND=nag_wp) arrayInput
On entry: the coordinates of the current point .
- 4: FVEC(M) – REAL (KIND=nag_wp) arrayInput
On entry: the values of the residuals at the current point .
- 5: FJAC(LDFJAC,N) – REAL (KIND=nag_wp) arrayInput
On entry: contains the value of at the current point , for and .
- 6: LDFJAC – INTEGERInput
On entry: the first dimension of the array
FJAC as declared in the (sub)program from which E04FCF is called.
- 7: S(N) – REAL (KIND=nag_wp) arrayInput
On entry: the singular values of the current approximation to the Jacobian matrix. Thus
S may be useful as information about the structure of your problem.
- 8: IGRADE – INTEGERInput
On entry: E04FCF estimates the dimension of the subspace for which the Jacobian matrix can be used as a valid approximation to the curvature (see
Gill and Murray (1978)). This estimate is called the grade of the Jacobian matrix, and
IGRADE gives its current value.
- 9: NITER – INTEGERInput
On entry: the number of iterations which have been performed in E04FCF.
- 10: NF – INTEGERInput
On entry: the number of times that
LSQFUN has been called so far. (However, for intermediate calls of
LSQMON,
NF is calculated on the assumption that the latest linear search has been successful. If this is not the case, then the
evaluations allowed for approximating the Jacobian at the new point will not in fact have been made.
NF will be accurate at the final call of
LSQMON.)
- 11: IW(LIW) – INTEGER arrayWorkspace
- 12: LIW – INTEGERInput
- 13: W(LW) – REAL (KIND=nag_wp) arrayWorkspace
- 14: LW – INTEGERInput
These parameters correspond to the parameters
IW,
LIW,
W and
LW of E04FCF. They are included in
LSQMON's parameter list primarily for when E04FCF is called by other Library routines.
LSQMON must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which E04FCF is called. Parameters denoted as
Input must
not be changed by this procedure.
Note: you should normally print the sum of squares of residuals, so as to be able to examine the sequence of values of
mentioned in
Section 7. It is usually helpful to print
XC, the estimated gradient of the sum of squares,
NITER and
NF.
- 5: IPRINT – INTEGERInput
On entry: the frequency with which
LSQMON is to be called.
If
,
LSQMON is called once every
IPRINT iterations and just before exit from E04FCF.
If
,
LSQMON is just called at the final point.
If
,
LSQMON is not called at all.
IPRINT should normally be set to a small positive number.
Suggested value:
.
- 6: MAXCAL – INTEGERInput
On entry: the limit you set on the number of times that
LSQFUN may be called by E04FCF. There will be an error exit (see
Section 6) after
MAXCAL calls of
LSQFUN.
Suggested value:
.
Constraint:
.
- 7: ETA – REAL (KIND=nag_wp)Input
Every iteration of E04FCF involves a linear minimization, i.e., minimization of with respect to .
On entry: specifies how accurately the linear minimizations are to be performed. The minimum with respect to
will be located more accurately for small values of
ETA (say,
) than for large values (say,
). Although accurate linear minimizations will generally reduce the number of iterations performed by E04FCF, they will increase the number of calls of
LSQFUN made each iteration. On balance it is usually more efficient to perform a low accuracy minimization.
Suggested value:
( if ).
Constraint:
.
- 8: XTOL – REAL (KIND=nag_wp)Input
On entry: the accuracy in
to which the solution is required.
If
is the true value of
at the minimum, then
, the estimated position before a normal exit, is such that
where
. For example, if the elements of
are not much larger than
in modulus and if
, then
is usually accurate to about five decimal places. (For further details see
Section 7.)
Suggested value:
if
and the variables are scaled roughly as described in
Section 8 and
is the
machine precision, then a setting of order
will usually be appropriate. If
XTOL is set to
or some positive value less than
, E04FCF will use
instead of
XTOL, since
is probably the smallest reasonable setting.
Constraint:
.
- 9: STEPMX – REAL (KIND=nag_wp)Input
On entry: an estimate of the Euclidean distance between the solution and the starting point supplied by you. (For maximum efficiency, a slight overestimate is preferable.) E04FCF will ensure that, for each iteration,
where
is the iteration number. Thus, if the problem has more than one solution, E04FCF is most likely to find the one nearest to the starting point. On difficult problems, a realistic choice can prevent the sequence
entering a region where the problem is ill-behaved and can help avoid overflow in the evaluation of
. However, an underestimate of
STEPMX can lead to inefficiency.
Suggested value:
.
Constraint:
.
- 10: X(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: must be set to a guess at the th component of the position of the minimum, for .
On exit: the final point . Thus, if on exit, is the th component of the estimated position of the minimum.
- 11: FSUMSQ – REAL (KIND=nag_wp)Output
On exit: the value of
, the sum of squares of the residuals
, at the final point given in
X.
- 12: FVEC(M) – REAL (KIND=nag_wp) arrayOutput
On exit: the value of the residual
at the final point given in
X, for
.
- 13: FJAC(LDFJAC,N) – REAL (KIND=nag_wp) arrayOutput
On exit: the estimate of the first derivative
at the final point given in
X, for
and
.
- 14: LDFJAC – INTEGERInput
On entry: the first dimension of the array
FJAC as declared in the (sub)program from which E04FCF is called.
Constraint:
.
- 15: S(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the singular values of the estimated Jacobian matrix at the final point. Thus
S may be useful as information about the structure of your problem.
- 16: V(LDV,N) – REAL (KIND=nag_wp) arrayOutput
On exit: the matrix
associated with the singular value decomposition
of the estimated Jacobian matrix at the final point, stored by columns. This matrix may be useful for statistical purposes, since it is the matrix of orthonormalized eigenvectors of
.
- 17: LDV – INTEGERInput
On entry: the first dimension of the array
V as declared in the (sub)program from which E04FCF is called.
Constraint:
.
- 18: NITER – INTEGEROutput
On exit: the number of iterations which have been performed in E04FCF.
- 19: NF – INTEGEROutput
On exit: the number of times that the residuals have been evaluated (i.e., number of calls of
LSQFUN).
- 20: IW(LIW) – INTEGER arrayCommunication Array
- 21: LIW – INTEGERInput
On entry: the dimension of the array
IW as declared in the (sub)program from which E04FCF is called.
Constraint:
.
- 22: W(LW) – REAL (KIND=nag_wp) arrayCommunication Array
- 23: LW – INTEGERInput
On entry: the dimension of the array
W as declared in the (sub)program from which E04FCF is called.
Constraints:
- if , ;
- if , .
- 24: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if
on exit, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Note: E04FCF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
A negative value of
IFAIL indicates an exit from E04FCF because you have set
IFLAG negative in
LSQFUN. The value of
IFAIL will be the same as your setting of
IFLAG.
On entry, | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | , when , |
or | , when . |
When this exit occurs, no values will have been assigned to
FSUMSQ, or to the elements of
FVEC,
FJAC,
S or
V.
-
There have been
MAXCAL calls of
LSQFUN. If steady reductions in the sum of squares,
, were monitored up to the point where this exit occurred, then the exit probably occurred simply because
MAXCAL was set too small, so the calculations should be restarted from the final point held in
X. This exit may also indicate that
has no minimum.
The conditions for a minimum have not all been satisfied, but a lower point could not be found. This could be because
XTOL has been set so small that rounding errors in the evaluation of the residuals make attainment of the convergence conditions impossible.
The method for computing the singular value decomposition of the estimated Jacobian matrix has failed to converge in a reasonable number of sub-iterations. It may be worth applying E04FCF again starting with an initial approximation which is not too close to the point at which the failure occurred.
The values
,
or
may also be caused by mistakes in
LSQFUN, by the formulation of the problem or by an awkward function. If there are no such mistakes it is worth restarting the calculations from a different starting point (not the point at which the failure occurred) in order to avoid the region which caused the failure.
7 Accuracy
A successful exit (
) is made from E04FCF when (B1, B2 and B3) or B4 or B5 hold, where
and where
and
are as defined in
Section 5, and
and
are the values of
and its vector of estimated first derivatives at
. If
then the vector in
X on exit,
, is almost certainly an estimate of
, the position of the minimum to the accuracy specified by
XTOL.
If
, then
may still be a good estimate of
, but to verify this you should make the following checks. If
(a) |
the sequence converges to at a superlinear or a fast linear rate, and |
(b) |
, where denotes transpose, then it is almost certain that is a close approximation to the minimum. When (b) is true, then usually is a close approximation to . The values of can be calculated in LSQMON, and the vector can be calculated from the contents of FVEC and FJAC on exit from E04FCF. |
Further suggestions about confirmation of a computed solution are given in the
E04 Chapter Introduction.
The number of iterations required depends on the number of variables, the number of residuals, the behaviour of
, the accuracy demanded and the distance of the starting point from the solution. The number of multiplications performed per iteration of E04FCF varies, but for
is approximately
. In addition, each iteration makes at least
calls of
LSQFUN. So, unless the residuals can be evaluated very quickly, the run time will be dominated by the time spent in
LSQFUN.
Ideally, the problem should be scaled so that, at the solution, and the corresponding values of the are each in the range , and so that at points one unit away from the solution, differs from its value at the solution by approximately one unit. This will usually imply that the Hessian matrix of at the solution is well-conditioned. It is unlikely that you will be able to follow these recommendations very closely, but it is worth trying (by guesswork), as sensible scaling will reduce the difficulty of the minimization problem, so that E04FCF will take less computer time.
When the sum of squares represents the goodness-of-fit of a nonlinear model to observed data, elements of the variance-covariance matrix of the estimated regression coefficients can be computed by a subsequent call to
E04YCF, using information returned in the arrays
S and
V. See
E04YCF for further details.
9 Example
This example finds least squares estimates of
and
in the model
using the
sets of data given in the following table.
The program uses
as the initial guess at the position of the minimum.
9.1 Program Text
Program Text (e04fcfe.f90)
9.2 Program Data
Program Data (e04fcfe.d)
9.3 Program Results
Program Results (e04fcfe.r)