naginterfaces.library.opt.check_​deriv

naginterfaces.library.opt.check_deriv(funct, x, data=None)[source]

check_deriv checks that a function for evaluating an objective function and its first derivatives produces derivative values which are consistent with the function values calculated.

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

https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/e04/e04hcf.html

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

must evaluate the function and its first derivatives at a given point. (The minimization functions mentioned in Notes gives you the option of resetting arguments of to cause the minimization process to terminate immediately. check_deriv will also terminate immediately, without finishing the checking process, if the argument in question is reset.)

Parameters
iflagint

Will be set to .

xcfloat, ndarray, shape

The point at which and its derivatives are required.

dataarbitrary, optional, modifiable in place

User-communication data for callback functions.

Returns
iflagint

If you reset to a negative number in and return control to check_deriv, check_deriv will terminate immediately with set to your setting of .

fcfloat

Unless resets , must be set to the value of the 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 .

xfloat, array-like, shape

, for , must be set to 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 preferable that no two elements of should be the same.

dataarbitrary, optional

User-communication data for callback functions.

Returns
ffloat

Unless you set negative in the first call of , contains the value of the objective function at the point given by you in .

gfloat, ndarray, shape

Unless you set negative in the first call of , contains the value of the derivative at the point given in , as calculated by , for .

Raises
NagValueError
(errno )

On entry, .

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 several variables may require you to supply a function to evaluate the objective function and its first derivatives. check_deriv is designed to check the derivatives calculated by such functions. As well as the function to be checked ( ), you must supply a point at which the check will be made. Note that check_deriv checks functions of the form required for bounds_mod_deriv_comp() and bounds_mod_deriv2_comp().

check_deriv first calls to evaluate and its first derivatives , for at . The components of the user-supplied derivatives along two orthogonal directions (defined by unit vectors and , say) are then calculated; these will be and respectively. The same components are also estimated by finite differences, giving quantities

where is a small positive scalar. If the relative difference between and or between and is judged too large, an error indicator is set.