e04kd 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 derivatives are required. The method is intended for functions which have continuous first and second derivatives (although it will usually work even if the derivatives have occasional discontinuities).
public static void e04kd( int n, E04..::..E04KD_FUNCT funct, E04..::..E04KD_MONIT monit, int iprint, int maxcal, double eta, double xtol, double delta, double stepmx, int ibound, double bl, double bu, double x, double hesl, double hesd, int istate, out double f, double g, out int ifail )
Public Shared Sub e04kd ( _ n As Integer, _ funct As E04..::..E04KD_FUNCT, _ monit As E04..::..E04KD_MONIT, _ iprint As Integer, _ maxcal As Integer, _ eta As Double, _ xtol As Double, _ delta As Double, _ stepmx As Double, _ ibound As Integer, _ bl As Double(), _ bu As Double(), _ x As Double(), _ hesl As Double(), _ hesd As Double(), _ istate As Integer(), _ <OutAttribute> ByRef f As Double, _ g As Double(), _ <OutAttribute> ByRef ifail As Integer _ )
public: static void e04kd( int n, E04..::..E04KD_FUNCT^ funct, E04..::..E04KD_MONIT^ monit, int iprint, int maxcal, double eta, double xtol, double delta, double stepmx, int ibound, array<double>^ bl, array<double>^ bu, array<double>^ x, array<double>^ hesl, array<double>^ hesd, array<int>^ istate, [OutAttribute] double% f, array<double>^ g, [OutAttribute] int% ifail )
static member e04kd : n : int * funct : E04..::..E04KD_FUNCT * monit : E04..::..E04KD_MONIT * iprint : int * maxcal : int * eta : float * xtol : float * delta : float * stepmx : float * ibound : int * bl : float * bu : float * x : float * hesl : float * hesd : float * istate : int * f : float byref * g : float * ifail : int byref -> unit
- Type: System..::..Int32On entry: the number of independent variables.Constraint: .
- Type: NagLibrary..::..E04..::..E04KD_FUNCTfunct must evaluate the function and its first derivatives at a specified point. (However, if you do not wish to calculate or its first derivatives at a particular , there is the option of setting a parameter to cause e04kd to terminate immediately.)
A delegate of type E04KD_FUNCT.
- Type: NagLibrary..::..E04..::..E04KD_MONITIf , you must supply monit which is suitable for monitoring the minimization process. monit must not change the values of any of its parameters.If , a monit with the correct parameter list must still be supplied, although it will not be called.
A delegate of type E04KD_MONIT.
- Type: System..::..Int32On entry: the frequency with which monit is to be called.
iprint should normally be set to a small positive number.Suggested value: .
- monit is called once every iprint iterations and just before exit from e04kd.
- monit is just called at the final point.
- monit is not called at all.
- Type: System..::..Int32On entry: the maximum permitted number of evaluations of , i.e., the maximum permitted number of calls of funct with iflag set to . It should be borne in mind that, in addition to the calls of funct which are limited directly by maxcal, there will be calls of funct (with iflag set to ) to evaluate only first derivatives.Suggested value: .Constraint: .
- Type: System..::..DoubleOn entry: every iteration of e04kd involves a linear minimization (i.e., minimization of with respect to ). eta specifies how accurately these linear minimizations are to be performed. The minimum with respect to will be located more accurately for small values of eta (say, ) than large values (say, ).Although accurate linear minimizations will generally reduce the number of iterations (and hence the number of calls of funct to estimate the second derivatives), they will tend to increase the number of calls of funct needed for each linear minimization. On balance, it is usually more efficient to perform a low accuracy linear minimization when is small and a high accuracy minimization when is large.Suggested values:
If , eta should be set to (also when the problem is effectively one-dimensional even though ; i.e., if for all except one of the variables the lower and upper bounds are equal).Constraint: .
- if ;
- if ;
- if .
- Type: System..::..DoubleOn 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 xtol is set to , then is usually accurate to about five decimal places. (For further details see [Accuracy].)If the problem is scaled as described in [Scaling] and is the machine precision, then is probably the smallest reasonable choice for xtol. This is because, normally, to machine accuracy, , for any where is the th column of the identity matrix. If you set xtol to (or any positive value less than ), e04kd will use instead of xtol.Suggested value: .Constraint: .
- Type: System..::..DoubleOn entry: the differencing interval to be used for approximating the second derivatives of . Thus, for the finite difference approximations, the first derivatives of are evaluated at points which are delta apart. If is the machine precision, then will usually be a suitable setting for delta. If you set delta to (or to any positive value less than ), e04kd will automatically use as the differencing interval.Suggested value: .Constraint: .
- Type: System..::..DoubleOn 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.)e04kd will ensure that, for each iteration,where is the iteration number. Thus, if the problem has more than one solution, e04kd is most likely to find the one nearest to 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 stepmx can lead to inefficiency.Suggested value: .Constraint: .
- Type: System..::..Int32On entry: indicates whether the problem is unconstrained or bounded. If there are bounds on the variables, ibound can be used to indicate whether the facility for dealing with bounds of special forms is to be used. It must be set to one of the following values:
- If the variables are bounded and you are 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 .
- If the problem is unconstrained. (The option is provided for consistency with other methods. In e04kd it produces the same effect as )
- Type: array<System..::..Double>()On entry: the fixed lower bounds .If ibound is set to , you must set to , for . (If a lower bound is not specified for any , the corresponding should be set to a large negative number, e.g., .)On exit: the lower bounds actually used by e04kd, e.g., if , .
- Type: array<System..::..Double>()On entry: the fixed upper bounds .If ibound is set to , you must set to , for . (If an upper bound is not specified for any variable, the corresponding should be set to a large positive number, e.g., .)On exit: the upper bounds actually used by e04kd, e.g., if , .
- Type: array<System..::..Double>()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.
- Type: array<System..::..Double>()An array of size [lh]On exit: during the determination of a direction (see [Description]), is decomposed into the product , where is a unit lower triangular matrix and 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 estimated second derivative matrix which relate to free variables. is chosen so that is positive definite.)hesl and hesd 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 hesl. The diagonal elements of are stored in the first positions of hesd. In the last factorization before a normal exit, the matrix will be zero, so that hesl and hesd will contain, on exit, the factors of the final estimated second derivative matrix . The elements of hesd are useful for deciding whether to accept the results produced by e04kd (see [Accuracy]).
- Type: array<System..::..Double>()On exit: during the determination of a direction (see [Description]), is decomposed into the product , where is a unit lower triangular matrix and 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 estimated second derivative matrix which relate to free variables. is chosen so that is positive definite.)hesl and hesd 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 hesl. The diagonal elements of are stored in the first positions of hesd. In the last factorization before a normal exit, the matrix will be zero, so that hesl and hesd will contain, on exit, the factors of the final estimated second derivative matrix . The elements of hesd are useful for deciding whether to accept the results produced by e04kd (see [Accuracy]).
- Type: array<System..::..Int32>()On exit: information about which variables are currently on their bounds and which are free. If is:
- – equal to , is fixed on its upper bound;
- – equal to , is fixed on its lower bound;
- – equal to , is effectively a constant (i.e., );
- – positive, gives the position of in the sequence of free variables.
- Type: array<System..::..Double>()
e04kd 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, and a funct to calculate the value of and its first derivatives at any point .
A typical iteration starts at the current point where (say) variables are free from their bounds. The vector , whose elements are the derivatives of with respect to the free variables, is known. The matrix of second derivatives with respect to the free variables, , is estimated by finite differences. (Note that and are both of 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 the 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 convergence criteria are satisfied. If at this point there are no negative or near-zero Lagrange multiplier estimates, the process is terminated.
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. Programming 7 311–350
Gill P E and Murray W (1976) Minimization subject to bounds on the variables NPL Report NAC 72 National Physical Laboratory
Note: e04kd may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (IW, LIW, W, LW) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
On entry, , or , or , or , or , or , or , or , or , or for some if , or if , or ,
- There have been maxcal function evaluations. If steady reductions in 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 met, 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. Such a situation can arise, for instance, if xtol has been set so small that rounding errors in the evaluation of or its derivatives make it impossible to satisfy the convergence conditions.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 Hessian matrix is so close to zero that it is not possible to recognize the point as a minimum.
- All the Lagrange multiplier estimates which are not indisputably positive lie relatively close to zero, but 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 .
The values , or may also be caused by mistakes in funct, 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.
A successful exit () is made from e04kd 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 [Description], is the machine precision and denotes the Euclidean norm.)
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 or , may still be a good estimate of , but the following checks should be made. Let the largest of the first elements of hesd 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
then it is almost certain that is a close approximation to the position of a minimum. When (ii) is true, then usually is a close approximation to . The quantities needed for these checks are all available via monit; in particular the value of cond in the last call of monit before exit gives .
|(i)||the sequence converges to at a superlinear or fast linear rate,|
Further suggestions about confirmation of a computed solution are given in the E04 class.
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 e04kd is . In addition, each iteration makes calls of funct (with iflag set to ) in approximating the projected Hessian matrix, and at least one other call of funct (with iflag set to ). So, unless and its first derivatives can be evaluated very quickly, the run time will be dominated by the time spent in funct.
Ideally, the problem should be scaled so that, at the solution, and the corresponding values of 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 e04kd will take less computer time.
If a problem is genuinely unconstrained and has been scaled sensibly, the following points apply:
|(a)||will always be ,|
|(b)||hesl and hesd will be factors of the full estimated second derivative matrix with elements stored in the natural order,|
|(c)||the elements of should all be close to zero at the final point,|
|(d)||the values of the given by monit and on exit from e04kd 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)||monit's parameter gpjnrm simply gives the norm of the first derivative vector.|