# naginterfaces.library.opt.bounds_​mod_​deriv2_​comp¶

naginterfaces.library.opt.bounds_mod_deriv2_comp(funct, h, monit, ibound, bl, bu, x, lh, iprint=1, maxcal=None, eta=None, xtol=0.0, stepmx=100000.0, data=None, io_manager=None)[source]

bounds_mod_deriv2_comp 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. The function is intended for functions which have continuous first and second derivatives (although it will usually work even if the derivatives have occasional discontinuities).

For full information please refer to the NAG Library document for e04lb

https://www.nag.com/numeric/nl/nagdoc_28.7/flhtml/e04/e04lbf.html

Parameters
functcallable (fc, gc) = funct(xc, data=None)

must evaluate the function and its first derivatives at any point .

Parameters
xcfloat, ndarray, shape

The point at which and the are required.

dataarbitrary, optional, modifiable in place

User-communication data for callback functions.

Returns
fcfloat

must set to the value of the objective function at the current point .

gcfloat, array-like, shape

must set to the value of the first derivative at the point , for .

hcallable (fhesl, fhesd) = h(xc, lh, fhesd, data=None)

must calculate the second derivatives of at any point . (As with , there is the option of causing bounds_mod_deriv2_comp to terminate immediately.)

Parameters
xcfloat, ndarray, shape

The point at which the second derivatives of are required.

lhint

The length of the array .

fhesdfloat, ndarray, shape

The value of at the point , for .

These values may be useful in the evaluation of the second derivatives.

dataarbitrary, optional, modifiable in place

User-communication data for callback functions.

Returns
fheslfloat, array-like, shape

must place the strict lower triangle of the second derivative matrix of (evaluated at the point ) in , stored by rows, i.e., set , for , for . (The upper triangle is not required because the matrix is symmetric.)

fhesdfloat, array-like, shape

must place the diagonal elements of the second derivative matrix of (evaluated at the point ) in , i.e., set , .

monitcallable monit(xc, fc, gc, istate, gpjnrm, cond, posdef, niter, nf, data=None)

If , you must supply which is suitable for monitoring the minimization process. must not change the values of any of its arguments.

If , a with the correct argument list should still be supplied, although it will not be called.

Parameters
xcfloat, ndarray, shape

The coordinates of the current point .

fcfloat

The value of at the current point .

gcfloat, ndarray, shape

The value of at the current point , for .

istateint, ndarray, shape

Information about which variables are currently fixed on their bounds and which are free.

If is negative, is currently:

• fixed on its upper bound if ;

• fixed on its lower bound if ;

• effectively a constant (i.e., ) if .

If is positive, its value gives the position of in the sequence of free variables.

gpjnrmfloat

The Euclidean norm of the projected gradient vector .

condfloat

The ratio of the largest to the smallest elements of the diagonal factor of the projected Hessian matrix (see specification of ). This quantity is usually a good estimate of the condition number of the projected Hessian matrix. (If no variables are currently free, is set to zero.)

posdefbool

Is set or according to whether the second derivative matrix for the current subspace, , is positive definite or not.

niterint

The number of iterations (as outlined in Notes) which have been performed by bounds_mod_deriv2_comp so far.

nfint

The number of times that has been called so far. Thus is the number of function and gradient evaluations made so far.

dataarbitrary, optional, modifiable in place

User-communication data for callback functions.

iboundint

Specifies whether the problem is unconstrained or bounded. If there are bounds on the variables, 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 purely for consistency with other functions. In bounds_mod_deriv2_comp it produces the same effect as .)

blfloat, array-like, shape

The fixed lower bounds .

If 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., .)

If is set to , you must set to ; bounds_mod_deriv2_comp will then set the remaining elements of equal to .

If is set to , or , will be initialized by bounds_mod_deriv2_comp.

bufloat, array-like, shape

The fixed upper bounds .

If 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., .)

If is set to , you must set to ; bounds_mod_deriv2_comp will then set the remaining elements of equal to .

If is set to , or , will then be initialized by bounds_mod_deriv2_comp.

xfloat, array-like, shape

must be set to a guess at the th component of the position of the minimum, for .

lhint

The dimension of the array .

iprintint, optional

The frequency with which is to be called.

is called once every iterations and just before exit from bounds_mod_deriv2_comp.

is just called at the final point.

is not called at all.

should normally be set to a small positive number.

maxcalNone or int, optional

Note: if this argument is None then a default value will be used, determined as follows: .

The maximum permitted number of evaluations of , i.e., the maximum permitted number of calls of .

etaNone or float, optional

Note: if this argument is None then a default value will be used, determined as follows: if : ; otherwise: .

Every iteration of bounds_mod_deriv2_comp 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, ) than for large values (say, ).

Although accurate linear minimizations will generally reduce the number of iterations of bounds_mod_deriv2_comp, this usually results in an increase in the number of function and gradient evaluations required for each iteration.

On balance, it is usually more efficient to perform a low accuracy linear minimization.

xtolfloat, optional

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 is set to , then is usually accurate to about five decimal places. (For further details see Accuracy.)

If the problem is scaled roughly as described in Further Comments 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.)

If you set to (or any positive value less than ), bounds_mod_deriv2_comp will use instead of .

stepmxfloat, optional

An estimate of the Euclidean distance between the solution and the starting point supplied by you. (For maximum efficiency a slight overestimate is preferable.)

bounds_mod_deriv2_comp will ensure that, for each iteration,

where is the iteration number.

Thus, if the problem has more than one solution, bounds_mod_deriv2_comp 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 can lead to inefficiency.

dataarbitrary, optional

User-communication data for callback functions.

io_managerFileObjManager, optional

Manager for I/O in this routine.

Returns
blfloat, ndarray, shape

The lower bounds actually used by bounds_mod_deriv2_comp, e.g., if , .

bufloat, ndarray, shape

The upper bounds actually used by bounds_mod_deriv2_comp, e.g., if , .

xfloat, ndarray, shape

The final point . Thus, if no exception or warning is raised on exit, is the th component of the estimated position of the minimum.

heslfloat, ndarray, shape

During the determination of a direction (see Notes), 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.)

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 estimated second derivative matrix .

The elements of are useful for deciding whether to accept the results produced by bounds_mod_deriv2_comp (see Accuracy).

hesdfloat, ndarray, shape

During the determination of a direction (see Notes), 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 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 bounds_mod_deriv2_comp (see Accuracy).

istateint, ndarray, shape

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.

ffloat

The function value at the final point given in .

gfloat, ndarray, shape

The first derivative vector corresponding to the final point given in . The components of corresponding to free variables should normally be close to zero.

Raises
NagValueError
(errno )

On entry, and for some .

(errno )

On entry, and .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

Warns
NagAlgorithmicWarning
(errno )

There have been function evaluations.

(errno )

The conditions for a minimum have not all been satisfied, but a lower point could not be found.

(errno )

No further progress can be made.

NagCallbackTerminateWarning
(errno )

User requested termination by setting negative in or .

Notes

bounds_mod_deriv2_comp 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 to calculate the value of and its first derivatives at any point , and a 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, bounds_mod_deriv2_comp 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 bounds_mod_deriv2_comp will act as an unconstrained minimization algorithm.

References

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