E04DGF/E04DGA (PDF version)
E04 Chapter Contents
E04 Chapter Introduction
NAG Library Manual

NAG Library Routine Document


Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.
Note: this routine uses optional parameters to define choices in the problem specification and in the details of the algorithm. If you wish to use default settings for all of the optional parameters, you need only read Sections 1 to 9 of this document. If, however, you wish to reset some or all of the settings please refer to Section 10 for a detailed description of the algorithm and to Section 11 for a detailed description of the specification of the optional parameters.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

E04DGF/E04DGA minimizes an unconstrained nonlinear function of several variables using a pre-conditioned, limited memory quasi-Newton conjugate gradient method. First derivatives (or an ‘acceptable’ finite difference approximation to them) are required. It is intended for use on large scale problems.
E04DGA is a version of E04DGF that has additional parameters in order to make it safe for use in multithreaded applications (see Section 5). The initialization routine E04WBF must have been called before calling E04DGA.

2  Specification

2.1  Specification for E04DGF

REAL (KIND=nag_wp)  OBJF, OBJGRD(N), X(N), WORK(13*N), RUSER(*)

2.2  Specification for E04DGA

REAL (KIND=nag_wp)  OBJF, OBJGRD(N), X(N), WORK(13*N), RUSER(*), RWSAV(475)
Before calling E04DGA, or either of the option setting routines E04DJA or E04DKA, routine E04WBF must be called. The specification for E04WBF is:
E04WBF should be called with RNAME='E04DGA'. LCWSAV, LLWSAV, LIWSAV and LRWSAV, the declared lengths of CWSAV, LWSAV, IWSAV and RWSAV respectively, must satisfy:
The contents of the arrays CWSAV, LWSAV, IWSAV and RWSAVmust not be altered between calling routines E04DGA, E04DJA, E04DKA and E04WBF.

3  Description

E04DGF/E04DGA is designed to solve unconstrained minimization problems of the form
minimize xRn Fx  subject to  -x,
where x is an n-element vector.
You must supply an initial estimate of the solution.
For maximum reliability, it is preferable to provide all first partial derivatives. If all of the derivatives cannot be provided, you are recommended to obtain approximate values (using finite differences) by calling E04XAF/E04XAA from within OBJFUN. This is illustrated in Section 9 in E04DJF/E04DJA.
The method used by E04DGF/E04DGA is described in Section 10.

4  References

Gill P E and Murray W (1979) Conjugate-gradient methods for large-scale nonlinear optimization Technical Report SOL 79-15 Department of Operations Research, Stanford University
Gill P E, Murray W and Wright M H (1981) Practical Optimization Academic Press

5  Parameters

1:     N – INTEGERInput
On entry: n, the number of variables.
Constraint: N>0.
2:     OBJFUN – SUBROUTINE, supplied by the user.External Procedure
OBJFUN must calculate the objective function Fx and possibly its gradient as well for a specified n-element vector x.
The specification of OBJFUN is:
1:     MODE – INTEGERInput/Output
On entry: indicates which values must be assigned during each call of OBJFUN. Only the following values need be assigned:
On exit: may be set to a negative value if you wish to terminate the solution to the current problem, and in this case E04DGF/E04DGA will terminate with IFAIL set to MODE.
2:     N – INTEGERInput
On entry: n, the number of variables.
3:     X(N) – REAL (KIND=nag_wp) arrayInput
On entry: x, the vector of variables at which the objective function and its gradient are to be evaluated.
4:     OBJF – REAL (KIND=nag_wp)Output
On exit: the value of the objective function at x.
5:     OBJGRD(N) – REAL (KIND=nag_wp) arrayOutput
On exit: if MODE=2, OBJGRDi must contain the value of F xi  evaluated at x, for i=1,2,,n.
6:     NSTATE – INTEGERInput
On entry: will be 1 on the first call of OBJFUN by E04DGF/E04DGA, and 0 for all subsequent calls. Thus, you may wish to test, NSTATE within OBJFUN in order to perform certain calculations once only. For example, you may read data or initialize COMMON blocksglobal variables when NSTATE=1.
7:     IUSER(*) – INTEGER arrayUser Workspace
8:     RUSER(*) – REAL (KIND=nag_wp) arrayUser Workspace
OBJFUN is called with the parameters IUSER and RUSER as supplied to E04DGF/E04DGA. You are free to use the arrays IUSER and RUSER to supply information to OBJFUN as an alternative to using COMMON global variables.
OBJFUN must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which E04DGF/E04DGA is called. Parameters denoted as Input must not be changed by this procedure.
Note:  OBJFUN should be tested separately before being used in conjunction with E04DGF/E04DGA. See also the description of the optional parameter Verify.
3:     ITER – INTEGEROutput
On exit: the total number of iterations performed.
4:     OBJF – REAL (KIND=nag_wp)Output
On exit: the value of the objective function at the final iterate.
5:     OBJGRD(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the gradient of the objective function at the final iterate (or its finite difference approximation).
6:     X(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: an initial estimate of the solution.
On exit: the final estimate of the solution.
7:     IWORK(N+1) – INTEGER arrayWorkspace
8:     WORK(13×N) – REAL (KIND=nag_wp) arrayWorkspace
9:     IUSER(*) – INTEGER arrayUser Workspace
10:   RUSER(*) – REAL (KIND=nag_wp) arrayUser Workspace
IUSER and RUSER are not used by E04DGF/E04DGA, but are passed directly to OBJFUN and may be used to pass information to this routine as an alternative to using COMMON global variables.
11:   IFAIL – INTEGERInput/Output
Note: for E04DGA, IFAIL does not occur in this position in the parameter list. See the additional parameters described below.
On entry: IFAIL must be set to 0, -1​ or ​1. 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 -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if IFAIL0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).
E04DGF/E04DGA returns with IFAIL=0 if the following three conditions are satisfied:
(i) Fk-1-Fk<τF1+Fk
(ii) xk-1-xk<τF1+xk
(iii) gkτF31+Fk or gk<εA
where τF is the value of the optional parameter Optimality Tolerance (default value=ε0.8) and εA is the absolute error associated with computing the objective function.
For a full discussion on termination criteria see Chapter 8 of Gill et al. (1981).
Note: the following are additional parameters for specific use with E04DGA. Users of E04DGF therefore need not read the remainder of this description.
11:   LWSAV(120) – LOGICAL arrayCommunication Array
12:   IWSAV(610) – INTEGER arrayCommunication Array
13:   RWSAV(475) – REAL (KIND=nag_wp) arrayCommunication Array
The arrays LWSAV, IWSAV and RWSAV must not be altered between calls to any of the routines E04DGA, E04DJA, E04DKA or E04WBF.
14:   IFAIL – INTEGERInput/Output
Note: see the parameter description for IFAIL above.

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: E04DGF/E04DGA 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 E04DGF/E04DGA because you set MODE<0 in OBJFUN. The value of IFAIL will be the same as your setting of MODE.
Not used by this routine.
Not used by this routine.
The limiting number of iterations (as determined by the optional parameter Iteration Limit (default value=max50,5n) has been reached.
If the algorithm appears to be making satisfactory progress, then optional parameter Iteration Limit may be too small. If so, increase its value and rerun E04DGF/E04DGA. If the algorithm seems to be making little or no progress, then you should check for incorrect gradients as described under IFAIL=7.
The computed upper bound on the step length taken during the linesearch was too small. A rerun with an increased value of the optional parameter Maximum Step Length (ρ say) may be successful unless ρ1020 (the default value), in which case the current point cannot be improved upon.
Not used by this routine.
The conditions for an acceptable solution (see parameter IFAIL in Section 5) have not all been met, but a lower point could not be found.
If OBJFUN computes the objective function and its gradient correctly, then this may occur because an overly stringent accuracy has been requested, i.e., the value of the optional parameter Optimality Tolerance (default value=ε0.8) is too small or if αk0. In this case you should apply the three tests described under IFAIL=0 to determine whether or not the final solution is acceptable. For a discussion of attainable accuracy see Gill et al. (1981).
If many iterations have occurred in which essentially no progress has been made or E04DGF/E04DGA has failed to move from the initial point, OBJFUN may be incorrect. You should refer to the comments below under IFAIL=7 and check the gradients using the optional parameter Verify (default value=0). Unfortunately, there may be small errors in the objective gradients that cannot be detected by the verification process. Finite difference approximations to first derivatives are catastrophically affected by even small inaccuracies.
The user-supplied derivatives of the objective function appear to be incorrect.
Large errors were found in the derivatives of the objective function. This value of IFAIL will occur if the verification process indicated that at least one gradient element had no correct figures. You should refer to the printed output to determine which elements are suspected to be in error.
As a first step, you should check that the code for the objective values is correct – for example, by computing the function at a point where the correct value is known. However, care should be taken that the chosen point fully tests the evaluation of the function. It is remarkable how often the values x=0 or x=1 are used to test function evaluation procedures, and how often the special properties of these numbers make the test meaningless.
Special care should be used in this test if computation of the objective function involves subsidiary data communicated in COMMON storage. Although the first evaluation of the function may be correct, subsequent calculations may be in error because some of the subsidiary data has accidentally been overwritten.
Errors in programming the function may be quite subtle in that the function value is almost correct. For example, the function may not be accurate to full precision because of the inaccurate calculation of a subsidiary quantity, or the limited accuracy of data upon which the function depends. A common error on machines where numerical calculations are usually performed in double precision is to include even one single precision constant in the calculation of the function; since some compilers do not convert such constants to double precision, half the correct figures may be lost by such a seemingly trivial error.
The gradient g= F x  at the starting point x0 is ‘too small’. More precisely, the value of gx0T gx0  is less than εr1+Fx0, where εr is the value of the optional parameter Function Precision (default value=ε0.9).
The problem should be rerun from a different starting point.
An input parameter is invalid.

7  Accuracy

On successful exit (IFAIL=0) the accuracy of the solution will be as defined by the optional parameter Optimality Tolerance (default value=ε0.8).

8  Further Comments

To evaluate an ‘acceptable’ set of finite difference intervals using E04XAF/E04XAA requires 2 function evaluations per variable for a well-scaled problem and up to 6 function evaluations per variable for a badly scaled problem.

8.1  Description of Printed Output

This section describes the intermediate printout and final printout produced by E04DGF/E04DGA. You can control the level of printed output (see the description of the optional parameter Print Level). Note that the intermediate printout and final printout are produced only if Print Level10 (the default for E04DGF, by default no output is produced by E04DGA).
The following line of summary output (<80 characters) is produced at every iteration. In all cases, the values of the quantities are those in effect on completion of the given iteration.
Itn is the iteration count.
Step is the step αk taken along the computed search direction. On reasonably well-behaved problems, the unit step (i.e., αk=1) will be taken as the solution is approached.
Nfun is the cumulated number of evaluations of the objective function needed for the linesearch. Evaluations needed for the verification of the gradients by finite differences are not included. Nfun is printed as a guide to the amount of work required for the linesearch. E04DGF/E04DGA will perform at most 11 function evaluations per iteration.
Objective is the value of the objective function at xk.
Norm G is the Euclidean norm of the gradient of the objective function at xk.
Norm X is the Euclidean norm of xk.
Norm (X(k-1)-X(k)) is the Euclidean norm of xk-1-xk.
The following describes the printout for each variable.
Variable gives the name (Varbl) and index j, for j=1,2,,n of the variable.
Value is the value of the variable at the final iteration.
Gradient Value is the value of the gradient of the objective function with respect to the jth variable at the final iteration.
Numerical values are output with a fixed number of digits; they are not guaranteed to be accurate to this precision.

9  Example

This example finds a minimum of the function
The initial point is
x0 = -1.0,1.0T ,
and Fx0=1.8394 (to five figures).
The optimal solution is
x* = 0.5,-1.0T ,
and Fx*=0.
The document for E04DJF/E04DJA includes an example program to solve the same problem using some of the optional parameters described in Section 11.

9.1  Program Text

Note: the following programs illustrate the use of E04DGF and E04DGA.

Program Text (e04dgfe.f90)

Program Text (e04dgae.f90)

9.2  Program Data

Program Data (e04dgfe.d)

Program Data (e04dgae.d)

9.3  Program Results

Program Results (e04dgfe.r)

Program Results (e04dgae.r)

Note: the remainder of this document is intended for more advanced users. Section 10 contains a detailed description of the algorithm which may be needed in order to understand Section 11. Section 11 describes the optional parameters which may be set by calls to E04DJF/E04DJA and/or E04DKF/E04DKA.

10  Algorithmic Details

This section contains a description of the method used by E04DGF/E04DGA.
E04DGF/E04DGA uses a pre-conditioned conjugate gradient method and is based upon algorithm PLMA as described in Section 4.8.3 of Gill and Murray (1979) and Gill et al. (1981).
The algorithm proceeds as follows:
Let x0 be a given starting point and let k denote the current iteration, starting with k=0. The iteration requires gk, the gradient vector evaluated at xk, the kth estimate of the minimum. At each iteration a vector pk (known as the direction of search) is computed and the new estimate xk+1 is given by xk+αkpk where αk (the step length) minimizes the function Fxk+αkpk with respect to the scalar αk. A choice of initial step α0 is taken as
α0 = min1, 2 × Fk-Fest / gkT gk
where Fest is a user-supplied estimate of the function value at the solution. If Fest is not specified, the software always chooses the unit step length for α0. Subsequent step length estimates are computed using cubic interpolation with safeguards.
A quasi-Newton method can be used to compute the search direction pk by updating the inverse of the approximate Hessian Hk and computing
pk+1=-Hk+1gk+1. (1)
The updating formula for the approximate inverse is given by
Hk+1 = Hk - 1 ykT sk Hk yk skT + sk ykT Hk + 1 ykT sk 1 + ykT Hk yk ykT sk sk skT , (2)
where yk=gk-1-gk and sk=xk+1-xk=αkpk.
The method used to obtain the search direction is based upon computing pk+1 as -Hk+1gk+1 where Hk+1 is a matrix obtained by updating the identity matrix with a limited number of quasi-Newton corrections. The storage of an n by n matrix is avoided by storing only the vectors that define the rank two corrections – hence the term ‘limited-memory’ quasi-Newton method. The precise method depends upon the number of updating vectors stored. For example, the direction obtained with the ‘one-step’ limited memory update is given by (1) using (2) with Hk equal to the identity matrix, viz.
pk+1 = - gk+1 + 1 ykT sk skT gk+1 yk + ykT gk+1 sk - skT gk+1 ykT sk 1 + ykT yk ykT sk sk .
Using a limited-memory quasi-Newton formula, such as the one above, guarantees pk+1 to be a descent direction if all the inner products ykT sk  are positive for all vectors yk and sk used in the updating formula.

11  Optional Parameters

Several optional parameters in E04DGF/E04DGA define choices in the problem specification or the algorithm logic. In order to reduce the number of formal parameters of E04DGF/E04DGA these optional parameters have associated default values that are appropriate for most problems. Therefore, you need only specify those optional parameters whose values are to be different from their default values.
The remainder of this section can be skipped if you wish to use the default values for all optional parameters.
The following is a list of the optional parameters available. A full description of each optional parameter is provided in Section 11.1.
Optional parameters may be specified by calling one, or both, of the routines E04DJF/E04DJA and E04DKF/E04DKA before a call to E04DGF/E04DGA.
E04DJF/E04DJA reads options from an external options file, with Begin and End as the first and last lines respectively and each intermediate line defining a single optional parameter. For example,
   Print Level = 1
The call
can then be used to read the file on unit IOPTNS. INFORM will be zero on successful exit. E04DJF/E04DJA should be consulted for a full description of this method of supplying optional parameters.
E04DKF/E04DKA can be called to supply options directly, one call being necessary for each optional parameter. For example,
 CALL E04DKF ('Print Level = 1')
E04DKF/E04DKA should be consulted for a full description of this method of supplying optional parameters.
All optional parameters not specified by you are set to their default values. Optional parameters specified by you are unaltered by E04DGF/E04DGA (unless they define invalid values) and so remain in effect for subsequent calls unless altered by you.

11.1  Description of the Optional Parameters

For each option, we give a summary line, a description of the optional parameter and details of constraints.
The summary line contains:
Keywords and character values are case and white space insensitive.
This special keyword may be used to reset all optional parameters to their default values.
Estimated Optimal Function Valuer
This value of r specifies the user-supplied guess of the optimum objective function value Fest. This value is used to calculate an initial step length α0 (see Section 10). If the value of r is not specified (the default), then this has the effect of setting α0 to unity. It should be noted that for badly scaled functions a unit step along the steepest descent direction will often compute the objective function at very large values of x.
Function PrecisionrDefault =ε0.9
The parameter defines εr, which is intended to be a measure of the accuracy with which the problem function Fx can be computed. If r<ε or r1, the default value is used.
The value of εr should reflect the relative precision of 1+Fx; i.e., εr acts as a relative precision when F is large, and as an absolute precision when F is small. For example, if Fx is typically of order 1000 and the first six significant digits are known to be correct, an appropriate value for εr would be 10-6. In contrast, if Fx is typically of order 10-4 and the first six significant digits are known to be correct, an appropriate value for εr would be 10-10. The choice of εr can be quite complicated for badly scaled problems; see Chapter 8 of Gill et al. (1981) for a discussion of scaling techniques. The default value is appropriate for most simple functions that are computed with full accuracy. However when the accuracy of the computed function values is known to be significantly worse than full precision, the value of εr should be large enough so that no attempt will be made to distinguish between function values that differ by less than the error inherent in the calculation.
Iteration LimitiDefault =max50,5n
The value of i specifies the maximum number of iterations allowed before termination. If i<0, the default value is used.
Problems whose Hessian matrices at the solution contain sets of clustered eigenvalues are likely to be minimized in significantly fewer than n iterations. Problems without this property may require anything between n and 5n iterations, with approximately 2n iterations being a common figure for moderately difficult problems.
Linesearch TolerancerDefault =0.9
The value r controls the accuracy with which the step α taken during each iteration approximates a minimum of the function along the search direction (the smaller the value of r, the more accurate the linesearch). The default value r=0.9 requests an inaccurate search, and is appropriate for most problems. A more accurate search may be appropriate when it is desirable to reduce the number of iterations – for example, if the objective function is cheap to evaluate. If r<0 or r1, the default value is used.
ListDefault for E04DGF=List
NolistDefault for E04DGA=Nolist
Normally each optional parameter specification is printed as it is supplied. Optional parameter Nolist may be used to suppress the printing and optional parameter List may be used to restore printing.
Maximum Step LengthrDefault =1020
If r>0, the maximum allowable step length for the linesearch is taken as min1X02AMF,rpk . If r0, the default value is used.
Optimality TolerancerDefault =εR0.8
The parameter r specifies the accuracy to which you wish the final iterate to approximate a solution of the problem. Broadly speaking, r indicates the number of correct figures desired in the objective function at the solution. For example, if r is 10-6 and termination occurs with IFAIL=0 (see Section 5), then the final point satisfies the termination criteria, where τF represents Optimality Tolerance. If r<εr or r1, the default value is used.
Print LeveliDefault for E04DGF =10
Default for E04DGA =0
The value i controls the amount of printout produced by E04DGF/E04DGA, as indicated below. A detailed description of the printout is given in Section 8.1 (summary output at each iteration and the final solution).
i Output
00 No output.
01 The final solution only.
05 One line of summary output (<80 characters; see Section 8.1) for each iteration (no printout of the final solution).
10 The final solution and one line of summary output for each iteration.
Start Objective Check at Variablei1Default =1
Stop Objective Check at Variablei2Default =n
These keywords take effect only if Verify Level>0. They may be used to control the verification of gradient elements computed by OBJFUN. For example, if the first 30 elements of the objective gradient appeared to be correct in an earlier run, so that only element 31 remains questionable, it is reasonable to specify Start Objective Check at Variable=31. If the first 30 variables appear linearly in the objective, so that the corresponding gradient elements are constant, the above choice would also be appropriate.
If i10 or i1>max1,minn,i2, the default value is used. If i20 or i2>n, the default value is used.
Verify LeveliDefault =0
Verify Gradients
Verify Objective Gradients
These keywords refer to finite difference checks on the gradient elements computed by OBJFUN. Gradients are verified at the user-supplied initial estimate of the solution. The possible choices for i are as follows:
i Meaning
-1 No checks are performed.
-0 Only a ‘cheap’ test will be performed, requiring one call to OBJFUN.
-1 In addition to the ‘cheap’ test, individual gradient elements will also be checked using a reliable (but more expensive) test.
For example, the objective gradient will be verified if Verify, Verify=YES, Verify Gradients, Verify Objective Gradients or Verify Level=1 is specified.

E04DGF/E04DGA (PDF version)
E04 Chapter Contents
E04 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012