e04yb Method
関数リスト一覧   NagLibrary Namespaceへ  ライブラリイントロダクション  本ヘルプドキュメントのchm形式版

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

Syntax

C#
public static void e04yb(
	int m,
	int n,
	E04..::.E04YB_LSQFUN lsqfun,
	E04..::.E04YB_LSQHES lsqhes,
	double[] x,
	double[] fvec,
	double[,] fjac,
	double[] b,
	out int ifail
)
Visual Basic (Declaration)
Public Shared Sub e04yb ( _
	m As Integer, _
	n As Integer, _
	lsqfun As E04..::.E04YB_LSQFUN, _
	lsqhes As E04..::.E04YB_LSQHES, _
	x As Double(), _
	fvec As Double(), _
	fjac As Double(,), _
	b As Double(), _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void e04yb(
	int m, 
	int n, 
	E04..::.E04YB_LSQFUN^ lsqfun, 
	E04..::.E04YB_LSQHES^ lsqhes, 
	array<double>^ x, 
	array<double>^ fvec, 
	array<double,2>^ fjac, 
	array<double>^ b, 
	[OutAttribute] int% ifail
)
F#
static member e04yb : 
        m:int * 
        n:int * 
        lsqfun:E04..::.E04YB_LSQFUN * 
        lsqhes:E04..::.E04YB_LSQHES * 
        x:float[] * 
        fvec:float[] * 
        fjac:float[,] * 
        b:float[] * 
        ifail:int byref -> unit 

Parameters

m
Type: System..::.Int32
On entry: the number m of residuals, fix, and the number n of variables, xj.
Constraint: 1nm.
n
Type: System..::.Int32
On entry: the number m of residuals, fix, and the number n of variables, xj.
Constraint: 1nm.
lsqfun
Type: NagLibrary..::.E04..::.E04YB_LSQFUN
lsqfun must calculate the vector of values fix and their first derivatives fi xj  at any point x. (e04he gives you the option of resetting parameters of lsqfun to cause the minimization process to terminate immediately. e04yb will also terminate immediately, without finishing the checking process, if the parameter in question is reset.)

A delegate of type E04YB_LSQFUN.

Note:  e04ya should be used to check the first derivatives calculated by lsqfun before e04yb is used to check the bjk since e04yb assumes that the first derivatives are correct.
lsqhes
Type: NagLibrary..::.E04..::.E04YB_LSQHES
lsqhes must calculate the elements of the symmetric matrix
Bx=i=1mfixGix,
at any point x, where Gix is the Hessian matrix of fix. (As with lsqfun, a parameter can be set to cause immediate termination.)

A delegate of type E04YB_LSQHES.

x
Type: array< System..::.Double >[]()[]
An array of size [n]
On entry: x[j-1], for j=1,2,,n, must be set to the coordinates of a suitable point at which to check the bjk calculated by lsqhes. ‘Obvious’ settings, such as 0 or 1, 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 x should have the same value.
fvec
Type: array< System..::.Double >[]()[]
An array of size [m]
On exit: unless you set iflag negative in the first call of lsqfun, fvec[i-1] contains the value of fi at the point supplied by you in x, for i=1,2,,m.
fjac
Type: array< System..::.Double ,2>[,](,)[,]
An array of size [ldfjac, n]
Note: ldfjac must satisfy the constraint: ldfjacm
On exit: unless you set iflag negative in the first call of lsqfun, fjac[i-1,j-1] contains the value of the first derivative fi xj  at the point given in x, as calculated by lsqfun, for i=1,2,,m and j=1,2,,n.
b
Type: array< System..::.Double >[]()[]
An array of size [lb]
Note: lb must satisfy the constraint: lbn+1×n/2
On exit: unless you set iflag negative in lsqhes, b[j×j-1/2+k-1] contains the value of bjk at the point given in x as calculated by lsqhes, for j=1,2,,n and k=1,2,,j.
ifail
Type: System..::.Int32 %
On exit: ifail=0 unless the method detects an error (see [Error Indicators and Warnings]).

Description

Methods for minimizing a sum of squares of m nonlinear functions (or ‘residuals’), fix1,x2,,xn, for i=1,2,,m and mn, may require you to supply a method to evaluate the quantities
bjk=i=1mfi 2fi xjxk
for j=1,2,,n and k=1,2,,j.
e04yb is designed to check the bjk calculated by such user-supplied delegates. As well as the method to be checked (lsqhes), you must supply a method (lsqfun) to evaluate the fi and their first derivatives, and a point x=x1,x2,,xnT at which the checks will be made. Note that e04yb checks methods of the form required by e04he. e04yb is essentially identical to CHKLSH in the NPL Algorithms Library.
e04yb first calls user-supplied delegates lsqfun and lsqhes to evaluate the first derivatives and the bjk at x. Let J denote the m by n matrix of first derivatives of the residuals. The Hessian matrix of the sum of squares,
G=JTJ+B,
is calculated and projected onto two orthogonal vectors y and z to give the scalars yTGy and zTGz respectively. The same projections of the Hessian matrix are also estimated by finite differences, giving
p=yTgx+hy-yTgx/h  and q=zTgx+hz-zTgx/h
respectively, where g denotes the gradient vector of the sum of squares at the point in brackets and h is a small positive scalar. If the relative difference between p and yTGy or between q and zTGz is judged too large, an error indicator is set.

References

Error Indicators and Warnings

Note: e04yb may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
ifail<0
A negative value of ifail indicates an exit from e04yb because you have set iflag negative in user-supplied delegates lsqfun or lsqhes. The setting of ifail will be the same as your setting of iflag. The check on lsqhes will not have been completed.
ifail=1
On entry,m<n,
orn<1,
ifail=2
ifail=-4000
ifail=-8000
ifail=-6000

Accuracy

ifail is set to 2 if
yTGy-phyTGy+1.0 or zTGz-qhzTGz+1.0
where h is set equal to ε (ε being the machine precision as given by x02aj) and other quantities are defined as in [Description].

Further Comments

e04yb calls lsqhes once and lsqfun three times.

Example

Suppose that it is intended to use e04he to find least-squares estimates of x1,x2 and x3 in the model
y = x1 + t1 x2 t2+ x3 t3
using the 15 sets of data given in the following table.
y t1 t2 t3 0.14 1.0 15.0 1.0 0.18 2.0 14.0 2.0 0.22 3.0 13.0 3.0 0.25 4.0 12.0 4.0 0.29 5.0 11.0 5.0 0.32 6.0 10.0 6.0 0.35 7.0 9.0 7.0 0.39 8.0 8.0 8.0 0.37 9.0 7.0 7.0 0.58 10.0 6.0 6.0 0.73 11.0 5.0 5.0 0.96 12.0 4.0 4.0 1.34 13.0 3.0 3.0 2.10 14.0 2.0 2.0 4.39 15.0 1.0 1.0
This example program could be used to check the bjk calculated by lsqhes required. (The call of e04yb is preceded by a call of e04ya to check lsqfun which calculates the first derivatives.)

Example program (C#): e04ybe.cs

Example program data: e04ybe.d

Example program results: e04ybe.r

See Also