# naginterfaces.library.opt.lsq_​check_​hessian¶

naginterfaces.library.opt.lsq_check_hessian(m, lsqfun, lsqhes, x, lb, data=None, spiked_sorder='C')[source]

lsq_check_hessian checks that a user-supplied function for evaluating the second derivative term of the Hessian matrix of a sum of squares is consistent with a user-supplied function for calculating the corresponding first derivatives.

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

https://www.nag.com/numeric/nl/nagdoc_29/flhtml/e04/e04ybf.html

Parameters
mint

The number of residuals, , and the number of variables, .

lsqfuncallable (iflag, fvec, fjac) = lsqfun(iflag, m, xc, data=None)

must calculate the vector of values and their first derivatives at any point . (lsq_uncon_mod_deriv2_comp() gives you the option of resetting arguments of to cause the minimization process to terminate immediately. lsq_check_hessian will also terminate immediately, without finishing the checking process, if the argument in question is reset.)

Parameters
iflagint

To , will be set to .

mint

The numbers of residuals.

xcfloat, ndarray, shape

The point at which the values of the and the are required.

dataarbitrary, optional, modifiable in place

User-communication data for callback functions.

Returns
iflagint

If you reset to some negative number in and return control to lsq_check_hessian, the function will terminate immediately with set to your setting of .

fvecfloat, array-like, shape

Unless is reset to a negative number, must contain the value of at the point , for .

fjacfloat, array-like, shape

Unless is reset to a negative number, must contain the value of at the point , for , for .

lsqhescallable (iflag, b) = lsqhes(iflag, fvec, xc, lb, data=None)

must calculate the elements of the symmetric matrix

at any point , where is the Hessian matrix of . (As with , an argument can be set to cause immediate termination.)

Parameters
iflagint

Is set to a non-negative number.

fvecfloat, ndarray, shape

The value of the residual at the point , for , so that the values of the can be used in the calculation of the elements of .

xcfloat, ndarray, shape

The point at which the elements of are to be evaluated.

lbint

Gives the length of the array .

dataarbitrary, optional, modifiable in place

User-communication data for callback functions.

Returns
iflagint

If resets to some negative number, lsq_check_hessian will terminate immediately, with set to your setting of .

bfloat, array-like, shape

Unless is reset to a negative number must contain the lower triangle of the matrix , evaluated at the point in , stored by rows. (The upper triangle is not needed because the matrix is symmetric.) More precisely, must contain evaluated at the point , for , for .

xfloat, array-like, shape

, for , must be set to the coordinates of a suitable point at which to check the 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. For a similar reason, it is preferable that no two elements of should have the same value.

lbint

The dimension of the array .

dataarbitrary, optional

User-communication data for callback functions.

spiked_sorderstr, optional

If in is spiked (i.e., has unit extent in all but one dimension, or has size ), selects the storage order to associate with it in the NAG Engine:

spiked_sorder =

row-major storage will be used;

spiked_sorder =

column-major storage will be used.

Returns
fvecfloat, ndarray, shape

Unless you set negative in the first call of , contains the value of at the point supplied by you in , for .

fjacfloat, 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 , for .

bfloat, ndarray, shape

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

Raises
NagValueError
(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, and .

Constraint: .

Warns
NagAlgorithmicWarning
(errno )

User requested termination by setting negative in or .

(errno )

It is very likely that you have made an error in setting up in .

Notes

No equivalent traditional C interface for this routine exists in the NAG Library.

Functions for minimizing a sum of squares of nonlinear functions (or ‘residuals’), , for and , may require you to supply a function to evaluate the quantities

for and . lsq_check_hessian is designed to check the calculated by such functions. As well as the function to be checked (), you must supply a function () to evaluate the and their first derivatives, and a point at which the checks will be made. Note that lsq_check_hessian checks functions of the form required by lsq_uncon_mod_deriv2_comp(). lsq_check_hessian is essentially identical to CHKLSH in the NPL Algorithms Library.

lsq_check_hessian first calls functions and to evaluate the first derivatives and the at . Let denote the matrix of first derivatives of the residuals. The Hessian matrix of the sum of squares,

is calculated and 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, giving

respectively, where denotes the gradient vector of the sum of squares 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.