e04lbc is a comprehensive modified-Newton algorithm for finding:
–an unconstrained minimum of a function of several variables
–a minimum of a function of several variables subject to fixed upper and/or lower bounds on the variables.
First and second derivatives are required. e04lbc is intended for objective functions which have continuous first and second derivatives (although it will usually work even if the derivatives have occasional discontinuities).
The function may be called by the names: e04lbc, nag_opt_bounds_mod_deriv2_comp or nag_opt_bounds_2nd_deriv.
3Description
e04lbc is applicable to problems of the form:
Special provision is made for unconstrained minimization (i.e., problems which actually have no bounds on the ), problems which have only non-negativity bounds, and problems in which and . It is possible to specify that a particular should be held constant. You must supply a starting point, a function objfun to calculate the value of and its first derivatives at any point , and a function hessfun to calculate the second derivatives .
A typical iteration starts at the current point where (say) variables are free from both their bounds. The vector of first derivatives of with respect to the free variables, , and the matrix of second derivatives with respect to the free variables, , are obtained. (These both have dimension .) The equations
are solved to give a search direction . (The matrix is chosen so that is positive definite.) is then expanded to an -vector by the insertion of appropriate zero elements; is found such that is approximately a minimum (subject to the fixed bounds) with respect to , and is replaced by . (If a saddle point is found, a special search is carried out so as to move away from the saddle point.) If any variable actually reaches a bound, it is fixed and is reduced for the next iteration.
There are two sets of convergence criteria – a weaker and a stronger. Whenever the weaker criteria are satisfied, the Lagrange-multipliers are estimated for all active constraints. If any Lagrange-multiplier estimate is significantly negative, then one of the variables associated with a negative Lagrange-multiplier estimate is released from its bound and the next search direction is computed in the extended subspace (i.e., is increased). Otherwise, minimization continues in the current subspace until the stronger criteria are satisfied. If at this point there are no negative or near-zero Lagrange-multiplier estimates, the process is terminated.
If you specify that the problem is unconstrained, e04lbc sets the to and the to . Thus, provided that the problem has been sensibly scaled, no bounds will be encountered during the minimization process and e04lbc will act as an unconstrained minimization algorithm.
4References
Gill P E and Murray W (1973) Safeguarded steplength algorithms for optimization using descent methods NPL Report NAC 37 National Physical Laboratory
Gill P E and Murray W (1974) Newton-type methods for unconstrained and linearly constrained optimization Math. Programming7 311–350
Gill P E and Murray W (1976) Minimization subject to bounds on the variables NPL Report NAC 72 National Physical Laboratory
5Arguments
1: – IntegerInput
On entry: the number of independent variables.
Constraint:
.
2: – function, supplied by the userExternal Function
objfun must evaluate the function and its first derivatives at any point . (However, if you do not wish to calculate or its first derivatives at a particular , there is the option of setting an argument to cause e04lbc to terminate immediately.)
On entry: the point at which the value of , or and , are required.
3: – double *Output
On exit: objfun must set objf to the value of the objective function at the current point . If it is not possible to evaluate then objfun should assign a negative value to ; e04lbc will then terminate.
4: – doubleOutput
On exit: objfun must set to the value of the first derivative at the current point , for . If it is not possible to evaluate the first derivatives then objfun should assign a negative value to ; e04lbc will then terminate.
5: – Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to objfun.
flag – IntegerOutput
On exit: if objfun resets to some negative number then e04lbc will terminate immediately with the error indicator NE_USER_STOP. If fail is supplied to e04lbc, will be set to your setting of .
first – Nag_BooleanInput
On entry: will be set to Nag_TRUE on the first call to objfun and Nag_FALSE for all subsequent calls.
nf – IntegerInput
On entry: the number of evaluations of the objective function; this value will be equal to the number of calls made to objfun (including the current one).
user – double *
iuser – Integer *
p – Pointer
The type Pointer will be void * with a C compiler that defines void * and char * otherwise.
Before calling e04lbc these pointers may be allocated memory and initialized with various quantities for use by objfun when called from e04lbc.
Note:objfun should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by e04lbc. If your code inadvertently does return any NaNs or infinities, e04lbc is likely to produce unexpected results.
Note:objfun should be tested separately before being used in conjunction with e04lbc. The array x must not be changed by objfun.
3: – function, supplied by the userExternal Function
hessfun must calculate the second derivatives of at any point . (As with objfun there is the option of causing e04lbc to terminate immediately.)
On entry: the point at which the second derivatives of are required.
3: – doubleOutput
On exit: hessfun must place the strict lower triangle of the second derivative matrix of (evaluated at the point ) in h, stored by rows, i.e., set
(The upper triangle is not required because the matrix is symmetric.) If it is not possible to evaluate the elements of h then hessfun should assign a negative value to ; e04lbc will then terminate.
4: – doubleInput/Output
On entry: the value of at the point , for . These values may be useful in the evaluation of the second derivatives.
On exit: unless is reset to a negative number hessfun must place the diagonal elements of the second derivative matrix of (evaluated at the point ) in hd, i.e., set
If it is not possible to evaluate the elements of hd then hessfun should assign a negative value to ; e04lbc will then terminate.
5: – Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to objfun.
flag – IntegerOutput
On exit: if hessfun resets to some negative number then e04lbc will terminate immediately with the error indicator NE_USER_STOP. If fail is supplied to e04lbc will be set to your setting of .
first – Nag_BooleanInput
On entry: will be set to Nag_TRUE on the first call to hessfun and Nag_FALSE for all subsequent calls.
nf – IntegerInput
On entry: the number of calculations of the objective function; this value will be equal to the number of calls made to hessfun including the current one.
user – double *
iuser – Integer *
p – Pointer
The type Pointer will be void * with a C compiler that defines void * and char * otherwise.
Before calling e04lbc these pointers may be allocated memory and initialized with various quantities for use by hessfun when called from e04lbc.
Note:hessfun should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by e04lbc. If your code inadvertently does return any NaNs or infinities, e04lbc is likely to produce unexpected results.
Note:hessfun should be tested separately before being used in conjunction with e04lbc. The array x must not be changed by hessfun.
4: – Nag_BoundTypeInput
On entry: indicates whether the problem is unconstrained or bounded and, if it is bounded, whether the facility for dealing with bounds of special forms is to be used. bound should be set to one of the following values:
If the variables are bounded and you will be supplying all the and individually.
If the problem is unconstrained.
If the variables are bounded, but all the bounds are of the form .
If all the variables are bounded, and and .
Constraint:
, , or .
5: – doubleInput/Output
On entry: the lower bounds .
If , you must set to , for . (If a lower bound is not required for any , the corresponding should be set to a large negative number, e.g., .)
If , you must set to ; e04lbc will then set the remaining elements of bl equal to .
On exit: the upper bounds actually used by e04lbc, e.g., if , .
7: – doubleInput/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.
8: – double *Output
On exit: the function value at the final point given in x.
9: – doubleOutput
On exit: the first derivative vector corresponding to the final point in x. The elements of g corresponding to free variables should normally be close to zero.
10: – Nag_E04_Opt *Input/Output
On entry/exit: a pointer to a structure of type Nag_E04_Opt whose members are optional parameters for e04lbc. These structure members offer the means of adjusting some of the argument values of the algorithm and on output will supply further details of the results. A description of the members of options is given below in Section 11.
If any of these optional parameters are required then the structure options should be declared and initialized by a call to e04xxc and supplied as an argument to e04lbc. However, if the optional parameters are not required the NAG defined null pointer, E04_DEFAULT, can be used in the function call.
11: – Nag_Comm *Input/Output
Note:comm is a NAG defined type (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
On entry/exit: structure containing pointers for communication to user-supplied functions; see the description of objfun and hessfun for details. If you do not need to make use of this communication feature the null pointer NAGCOMM_NULL may be used in the call to e04lbc; comm will then be declared internally for use in calls to user-supplied functions.
12: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
An exit of NW_TOO_MANY_ITER, NW_LAGRANGE_MULT_ZERO and NW_COND_MIN may also be caused by mistakes in objfun, 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.
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_INVALID_INT_RANGE_1
Value given to is not valid. Correct range is .
NE_INVALID_REAL_RANGE_EF
Value given to is not valid. Correct range is .
NE_INVALID_REAL_RANGE_FF
Value given to is not valid. Correct range is .
NE_NOT_APPEND_FILE
Cannot open file for appending.
NE_NOT_CLOSE_FILE
Cannot close file .
NE_OPT_NOT_INIT
Options structure not initialized.
NE_USER_STOP
User requested termination, user flag value .
This exit occurs if you set to a negative value in objfun or hessfun. If fail is supplied, the value of will be the same as your setting of .
NE_WRITE_ERROR
Error occurred when writing to file .
NW_COND_MIN
The conditions for a minimum have not all been satisfied, but a lower point could not be found.
Provided that, on exit, the first derivatives of with respect to the free variables are sufficiently small, and that the estimated condition number of the second derivative matrix is not too large, this error exit may simply mean that, although it has not been possible to satisfy the specified requirements, the algorithm has in fact found the minimum as far as the accuracy of the machine permits. This could be because has been set so small that rounding error in objfun makes attainment of the convergence conditions impossible.
If the estimated condition number of the second derivative matrix at the final point is large, it could be that the final point is a minimum but that the smallest eigenvalue of the second derivative matrix is so close to zero that it is not possible to recognize the point as a minimum.
NW_LAGRANGE_MULT_ZERO
All the Lagrange-multiplier estimates which are not indisputably positive lie close to zero.
However, it is impossible either to continue minimizing on the current subspace or to find a feasible lower point by releasing and perturbing any of the fixed variables. You should investigate as for NW_COND_MIN.
NW_TOO_MANY_ITER
The maximum number of iterations, , have been performed.
If steady reductions in , were monitored up to the point where this exit occurred, then the exit probably occurred simply because 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.
7Accuracy
A successful exit is made from e04lbc when is positive definite and when (B1, B2 and B3) or B4 hold, where
.
(Quantities with superscript are the values at the th iteration of the quantities mentioned in Section 3; is the machine precision, denotes the Euclidean norm and is described in Section 11.)
If , then the vector in x on exit, , is almost certainly an estimate of the position of the minimum, , to the accuracy specified by .
If or NW_LAGRANGE_MULT_ZERO, may still be a good estimate of , but the following checks should be made. Let the largest of the first elements of the optional parameter be , let the smallest be , and define . The scalar is usually a good estimate of the condition number of the projected Hessian matrix at . If
(a)the sequence converges to at a superlinear or fast linear rate,
(b), and
(c),
then it is almost certain that is a close approximation to the position of a minimum. When (b) is true, then usually is a close approximation to . The quantities needed for these checks are all available in the results printout from e04lbc; in particular the final value of Cond H gives .
Further suggestions about confirmation of a computed solution are given in the E04 Chapter Introduction.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
e04lbc is not threaded in any implementation.
9Further Comments
9.1Timing
The number of iterations required depends on the number of variables, the behaviour of , the accuracy demanded and the distance of the starting point from the solution. The number of multiplications performed in an iteration of e04lbc is . In addition, each iteration makes one call of hessfun and at least one call of objfun. So, unless and its derivatives can be evaluated very quickly, the run time will be dominated by the time spent in objfun.
9.2Scaling
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 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 e04lbc will take less computer time.
9.3Unconstrained Minimization
If a problem is genuinely unconstrained and has been scaled sensibly, the following points apply:
(a) will always be ,
(b)the optional parameters and will be factors of the full approximate second derivative matrix with elements stored in the natural order,
(c)the elements of g should all be close to zero at the final point,
(d)the Status values given in the printout from e04lbc, and in the optional parameter on exit are unlikely to be of interest (unless they are negative, which would indicate that the modulus of one of the has reached for some reason),
(e)Norm g simply gives the norm of the first derivative vector.
10Example
This example minimizes the function
subject to the bounds
starting from the initial guess .
The options structure is declared and initialized by e04xxc. One option value is read from a data file by use of e04xyc. The memory freeing function e04xzc is used to free the memory assigned to the pointers in the option structure. You must not use the standard C function free() for this purpose.
A number of optional input and output arguments to e04lbc are available through the structure argument options, type Nag_E04_Opt. An argument may be selected by assigning an appropriate value to the relevant structure member; those arguments not selected will be assigned default values. If no use is to be made of any of the optional parameters you should use the NAG defined null pointer, E04_DEFAULT, in place of options when calling e04lbc; the default settings will then be used for all arguments.
Before assigning values to options directly the structure must be initialized by a call to the function e04xxc. Values may then be assigned to the structure members in the normal C manner.
After return from e04lbc, the options structure may only be re-used for future calls of e04lbc if the dimensions of the new problem are the same. Otherwise, the structure must be cleared by a call of e04xzc) and re-initialized by a call of e04xxc before future calls. Failure to do this will result in unpredictable behaviour.
Option settings may also be read from a text file using the function e04xyc in which case initialization of the options structure will be performed automatically if not already done. Any subsequent direct assignment to the options structure must not be preceded by initialization.
If assignment of functions and memory to pointers in the options structure is required, then this must be done directly in the calling program; they cannot be assigned using e04xyc.
11.1Optional Parameter Checklist and Default Values
For easy reference, the following list shows the members of options which are valid for e04lbc together with their default values where relevant. The number is a generic notation for machine precision (see X02AJC).
On entry: if a check of the derivatives defined by objfun and hessfun will be made at the starting point x. A starting point of or should be avoided if this test is to be meaningful.
max_iter – Integer
Default
On entry: the limit on the number of iterations allowed before termination.
Constraint:
.
optim_tol – double
Default
On entry: the accuracy in to which the solution is required. If is the true value of at the minimum, then , the estimated position prior to a normal exit, is such that
,
where . For example, if the elements of are not much larger than in modulus and if is set to , then is usually accurate to about five decimal places. (For further details see Section 9.) If the problem is scaled roughly as described in Section 9 and is the machine precision, then is probably the smallest reasonable choice for . (This is because, normally, to machine accuracy, where is any column of the identity matrix.)
Constraint:
.
linesearch_tol – double
Default if , and otherwise
On entry: every iteration of e04lbc involves a linear minimization (i.e., minimization of with respect to ). specifies how accurately these linear minimizations are to be performed. The minimum with respect to will be located more accurately for small values of (say 0.01) than for large values (say 0.9).
Although accurate linear minimizations will generally reduce the number of iterations performed by e04lbc, they will increase the number of function evaluations required for each iteration. On balance, it is usually more efficient to perform a low accuracy linear minimization.
A smaller value such as may be worthwhile:
(a)if objfun takes so little computer time that it is worth using extra calls of objfun to reduce the number of iterations and associated matrix calculations
(b)if calls to hessfun are expensive compared with calls to objfun.
(c)if is a penalty or barrier function arising from a constrained minimization problem (since such problems are very difficult to solve).
If , the default for (if the problem is effectively one-dimensional then should be set to even though ; i.e., if for all except one of the variables the lower and upper bounds are equal).
Constraint:
.
step_max – double
Default
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.) e04lbc will ensure that, for each iteration,
,
where is the iteration number. Thus, if the problem has more than one solution, e04lbc is most likely to find the one nearest the starting point. On difficult problems, a realistic choice can prevent the sequence of entering a region where the problem is ill-behaved and can also help to avoid possible overflow in the evaluation of . However, an underestimate of can lead to inefficiency.
Constraint:
.
state – Integer *
Default memory
On exit: contains information about which variables are on their bounds and which are free at the final point given in x. If is:
(a)fixed on its upper bound, is ;
(b)fixed on its lower bound, is ;
(c)effectively a constant (i.e., ), is ;
(d)free, gives its position in the sequence of free variables.
hesl – double *
Default memory
hesd – double *
Default memory
On exit: during the determination of a direction (see Section 3), is decomposed into the product , where is a unit lower triangular matrix and D is a diagonal matrix. (The matrices , , and are all of dimension , where is the number of variables free from their bounds. consists of those rows and columns of the full second derivative matrix which relate to free variables. is chosen so that is positive definite.)
and are used to store the factors and . The elements of the strict lower triangle of are stored row by row in the first positions of . The diagonal elements of are stored in the first positions of .
In the last factorization before a normal exit, the matrix will be zero, so that and will contain, on exit, the factors of the final second derivative matrix . The elements of are useful for deciding whether to accept the result produced by e04lbc (see Section 9).
iter – Integer
On exit: the number of iterations which have been performed in e04lbc.
nf – Integer
On exit: the number of times the residuals have been evaluated (i.e., number of calls of objfun).
11.3Description of Printed Output
The level of printed output can be controlled with the structure members and (see Section 11.2). If then the argument values to e04lbc are listed, whereas the printout of results is governed by the value of . The default of provides a single line of output at each iteration and the final result. This section describes all of the possible levels of results printout available from e04lbc.
When or the following line of output is produced on completion of each iteration.
the Euclidean norm of the projected gradient vector, .
Norm x
the Euclidean norm of .
Norm(x(k-1)-x(k))
the Euclidean norm of .
Step
the step taken along the computed search direction .
Cond H
the ratio of the largest to the smallest element of the diagonal factor of the projected Hessian matrix. This quantity is usually a good estimate of the condition number of the projected Hessian matrix. (If no variables are currently free, this value will be zero.)
PosDef
indicates whether the second derivative matrix for the current subspace, , is positive definite (Yes) or not (No).
When , or this single line of output is also produced for the final solution.
When more detailed results are given at each iteration. Additional values output are
x
the current point .
g
the current projected gradient vector, .
Status
the current state of the variable with respect to its bound(s).
If , or the final result is printed out. This consists of:
x
the final point, .
g
the final projected gradient vector, .
Status
the final state of the variable with respect to its bound(s).
If then printout will be suppressed; you can print the final solution when e04lbc returns to the calling program.
11.3.1Output of results via a user-defined printing function
You may also specify your own print function for output of iteration results and the final solution by use of the function pointer, which has prototype
The rest of this section can be skipped if the default printing facilities provide the required functionality.
When a user-defined function is assigned to this will be called in preference to the internal print function of e04lbc. Calls to the user-defined function are again controlled by means of the member. Information is provided through st and comm, the two structure arguments to .
If then the results on completion of an iteration of e04lbc are contained in the members of st. If then the final results from e04lbc, including details of the final iteration, are contained in the members of st. In both cases, the same members of st are set, as follows:
iter – Integer
The current iteration count, , if ; the final iteration count, , if .
n – Integer
The number of variables.
x – double *
The coordinates of the point .
f – double *
The value of the objective function at .
g – double *
The value of at , .
gpj_norm – double
The Euclidean norm of the projected gradient at .
step – double
The step taken along the search direction .
cond – double
The estimate of the condition number of the projected Hessian matrix, see Section 11.3.
xk_norm – double
The Euclidean norm of .
state – Integer *
The status of variables , for , with respect to their bounds. See Section 11.2 for a description of the possible status values.
posdef – Nag_Boolean
Will be Nag_TRUE if the second derivative matrix for the current subspace is positive definite, and Nag_FALSE otherwise.
Will be Nag_TRUE when the print function is called with the results of the current iteration.
sol_prt – Nag_Boolean
Will be Nag_TRUE when the print function is called with the final result.
user – double *
iuser – Integer *
p – Pointer
Pointers for communication of user information. If used they must be allocated memory either before entry to e04lbc or during a call to objfun or . The type Pointer will be void * with a C compiler that defines void * and char * otherwise.