naginterfaces.library.opt.check_deriv2¶
- naginterfaces.library.opt.check_deriv2(funct, h, x, lh, data=None)[source]¶
check_deriv2
checks that a function for calculating second derivatives of an objective function is consistent with a function for calculating the corresponding first derivatives.For full information please refer to the NAG Library document for e04hd
https://support.nag.com/numeric/nl/nagdoc_30.2/flhtml/e04/e04hdf.html
- Parameters
- functcallable (iflag, fc, gc) = funct(iflag, xc, data=None)
must evaluate the function and its first derivatives at a given point. (
bounds_mod_deriv2_comp()
gives you the option of resetting arguments of to cause the minimization process to terminate immediately.check_deriv2
will also terminate immediately, without finishing the checking process, if the argument in question is reset.)- Parameters
- iflagint
To , will be set to .
- xcfloat, ndarray, shape
The point at which the function and first derivatives are required.
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- iflagint
If you set to some negative number in and return control to
check_deriv2
,check_deriv2
will terminate immediately with set to your setting of .- fcfloat
Unless resets , must be set to the value of the objective function at the current point .
- gcfloat, array-like, shape
Unless resets , must be set to the value of the first derivative at the point , for .
- hcallable (iflag, fhesl, fhesd) = h(iflag, xc, lh, fhesd, data=None)
must evaluate the second derivatives of the function at a given point. (As with , an argument can be set to cause immediate termination.)
- Parameters
- iflagint
Is set to a non-negative number.
- xcfloat, ndarray, shape
The point at which the second derivatives of are required.
- lhint
The length of the array .
- fhesdfloat, ndarray, shape
Contains the value of at the point , for . Functions written to take advantage of a similar feature of
bounds_mod_deriv2_comp()
can be tested as they stand bycheck_deriv2
.- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- iflagint
If resets to a negative number,
check_deriv2
will terminate immediately with set to your setting of .- fheslfloat, array-like, shape
Unless is reset, must place the strict lower triangle of the second derivative matrix of (evaluated at the point ) in , stored by rows, i.e., must be set to the value of at the point , for , for . (The upper triangle is not required because the matrix is symmetric.)
- fhesdfloat, array-like, shape
Unless is reset, must place the diagonal elements of the second derivative matrix of (evaluated at the point ) in , i.e., must be set to the value of at the point , for .
- xfloat, array-like, shape
, for , must contain the coordinates of a suitable point at which to check the derivatives calculated by . ‘Obvious’ settings, such as or , should not be used since, at such particular points, incorrect terms may take correct values (particularly zero), so that errors could go undetected. Similarly, it is advisable that no two elements of should be the same.
- lhint
The dimension of the array .
- dataarbitrary, optional
User-communication data for callback functions.
- Returns
- gfloat, ndarray, shape
Unless you set negative in the first call of , contains the value of the first derivative at the point given in , as calculated by , for .
- heslfloat, ndarray, shape
Unless you set negative in , contains the strict lower triangle of the second derivative matrix of , as evaluated by at the point given in , stored by rows.
- hesdfloat, ndarray, shape
Unless you set negative in , contains the diagonal elements of the second derivative matrix of , as evaluated by at the point given in .
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- Warns
- NagAlgorithmicWarning
- (errno )
User requested termination by setting negative in .
- (errno )
Large errors were found in the derivatives of computed by .
- Notes
In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.
Functions for minimizing a function of the variables may require you to provide a function to evaluate the second derivatives of .
check_deriv2
is designed to check the second derivatives calculated by such functions. As well as the function to be checked (), you must supply a function () to evaluate the first derivatives, and a point at which the checks will be made. Note thatcheck_deriv2
checks functions of the form required forbounds_mod_deriv2_comp()
.check_deriv2
first calls functions and to evaluate the first and second derivatives of at . The user-supplied Hessian matrix (, say) is projected onto two orthogonal vectors and to give the scalars and respectively. The same projections of the Hessian matrix are also estimated by finite differences, givingrespectively, where denotes the vector of first derivatives at the point in brackets and is a small positive scalar. If the relative difference between and or between and is judged too large, an error indicator is set.