NAG AD Library
e04fc (lsq_uncon_mod_func_comp)

Settings help

AD Name Style:


AD Specification Language:

1 Purpose

e04fc is the AD Library version of the primal routine e04fcf. Based (in the C++ interface) on overload resolution, e04fc can be used for primal, tangent and adjoint evaluation. It supports tangents and adjoints of first and second order.

2 Specification

Fortran Interface
Subroutine e04fc_AD_f ( ad_handle, m, n, lsqfun, lsqmon, iprint, maxcal, eta, xtol, stepmx, x, fsumsq, fvec, fjac, ldfjac, s, v, ldv, niter, nf, iuser, ruser, ifail)
Integer, Intent (In) :: m, n, iprint, maxcal, ldfjac, ldv
Integer, Intent (Inout) :: iuser(*), ifail
Integer, Intent (Out) :: niter, nf
ADTYPE, Intent (In) :: eta, xtol, stepmx
ADTYPE, Intent (Inout) :: x(n), fjac(ldfjac,n), v(ldv,n), ruser(*)
ADTYPE, Intent (Out) :: fsumsq, fvec(m), s(n)
Type (c_ptr), Intent (Inout) :: ad_handle
External :: lsqfun, lsqmon
Corresponding to the overloaded C++ function, the Fortran interface provides five routines with names reflecting the type used for active real arguments. The actual subroutine and type names are formed by replacing AD and ADTYPE in the above as follows:
when ADTYPE is Real(kind=nag_wp) then AD is p0w
when ADTYPE is Type(nagad_a1w_w_rtype) then AD is a1w
when ADTYPE is Type(nagad_t1w_w_rtype) then AD is t1w
when ADTYPE is Type(nagad_a1t1w_w_rtype) then AD is a1t1w
when ADTYPE is Type(nagad_t2w_w_rtype) then AD is t2w
C++ Header Interface
#include <dco.hpp>
#include <nagad.h>
namespace nag {
namespace ad {
void e04fc ( void *&ad_handle, const Integer &m, const Integer &n,
void (NAG_CALL lsqfun)(void *&ad_handle, Integer &iflag, const Integer &m, const Integer &n, const ADTYPE xc[], ADTYPE fvec[], Integer iuser[], ADTYPE ruser[]),
void (NAG_CALL lsqmon)(void *&ad_handle, const Integer &m, const Integer &n, const ADTYPE xc[], const ADTYPE fvec[], const ADTYPE fjac[], const Integer &ldfjac, const ADTYPE s[], const Integer &igrade, const Integer &niter, const Integer &nf, Integer iuser[], ADTYPE ruser[]),
const Integer &iprint, const Integer &maxcal, const ADTYPE &eta, const ADTYPE &xtol, const ADTYPE &stepmx, ADTYPE x[], ADTYPE &fsumsq, ADTYPE fvec[], ADTYPE fjac[], const Integer &ldfjac, ADTYPE s[], ADTYPE v[], const Integer &ldv, Integer &niter, Integer &nf, const Integer &liuser, Integer iuser[], const Integer &lruser, ADTYPE ruser[], Integer &ifail)
}
}
The function is overloaded on ADTYPE which represents the type of active arguments. ADTYPE may be any of the following types:
double,
dco::ga1s<double>::type,
dco::gt1s<double>::type,
dco::gt1s<dco::gt1s<double>::type>::type,
dco::ga1s<dco::gt1s<double>::type>::type,
Note: this function can be used with AD tools other than dco/c++. For details, please contact NAG.

3 Description

e04fc is the AD Library version of the primal routine e04fcf.
e04fcf is a comprehensive algorithm for finding an unconstrained minimum of a sum of squares of m nonlinear functions in n variables (mn). No derivatives are required.
The routine is intended for functions which have continuous first and second derivatives (although it will usually work even if the derivatives have occasional discontinuities). For further information see Section 3 in the documentation for e04fcf.

4 References

Gill P E and Murray W (1978) Algorithms for the solution of the nonlinear least squares problem SIAM J. Numer. Anal. 15 977–992

5 Arguments

In addition to the arguments present in the interface of the primal routine, e04fc includes some arguments specific to AD.
A brief summary of the AD specific arguments is given below. For the remainder, links are provided to the corresponding argument from the primal routine. A tooltip popup for all arguments can be found by hovering over the argument name in Section 2 and in this section.
1: ad_handle – Pointer to AD Data Input/Output
On entry: a handle to the AD configuration data object, as created by x10aa.
2: m – Integer Input
3: n – Integer Input
4: lsqfun – Subroutine External Procedure
The specification of lsqfun is:
Fortran Interface
Subroutine lsqfun ( ad_handle, iflag, m, n, xc, fvec, iuser, ruser)
Integer, Intent (In) :: m, n
Integer, Intent (Inout) :: iflag, iuser(*)
ADTYPE, Intent (In) :: xc(n)
ADTYPE, Intent (Inout) :: ruser(*)
ADTYPE, Intent (Out) :: fvec(m)
Type (c_ptr), Intent (Inout) :: ad_handle
C++ Header Interface
void lsqfun ( void *&ad_handle, Integer &iflag, const Integer &m, const Integer &n, const ADTYPE xc[], ADTYPE fvec[], Integer iuser[], ADTYPE ruser[])
1: ad_handle – Pointer to AD Data Input/Output
On entry: a handle to the AD configuration data object.
2: iflag – Integer Input/Output
3: m – Integer Input
4: n – Integer Input
5: xcADTYPE array Input
6: fvecADTYPE array Output
7: iuser(*) – Integer array User Workspace
8: ruser(*)ADTYPE array User Workspace
5: lsqmon – Subroutine External Procedure
If a null pointer is used as the argument, then a NAG supplied routine will be used as the argument for this parameter (C++ only). For the Fortran interface, the NAG supplied routine e04fd_AD_z may be used as the actual argument for this parameter.
The specification of lsqmon is:
Fortran Interface
Subroutine lsqmon ( ad_handle, m, n, xc, fvec, fjac, ldfjac, s, igrade, niter, nf, iuser, ruser)
Integer, Intent (In) :: m, n, ldfjac, igrade, niter, nf
Integer, Intent (Inout) :: iuser(*)
ADTYPE, Intent (In) :: xc(n), fvec(m), fjac(ldfjac,n), s(n)
ADTYPE, Intent (Inout) :: ruser(*)
Type (c_ptr), Intent (Inout) :: ad_handle
C++ Header Interface
void lsqmon ( void *&ad_handle, const Integer &m, const Integer &n, const ADTYPE xc[], const ADTYPE fvec[], const ADTYPE fjac[], const Integer &ldfjac, const ADTYPE s[], const Integer &igrade, const Integer &niter, const Integer &nf, Integer iuser[], ADTYPE ruser[])
1: ad_handle – Pointer to AD Data Input/Output
On entry: a handle to the AD configuration data object.
2: m – Integer Input
3: n – Integer Input
4: xcADTYPE array Input
5: fvecADTYPE array Input
6: fjacADTYPE array Input
7: ldfjac – Integer Input
8: sADTYPE array Input
9: igrade – Integer Input
10: niter – Integer Input
11: nf – Integer Input
12: iuser(*) – Integer array User Workspace
13: ruser(*)ADTYPE array User Workspace
6: iprint – Integer Input
7: maxcal – Integer Input
8: etaADTYPE Input
9: xtolADTYPE Input
10: stepmxADTYPE Input
11: x(n) – ADTYPE array Input/Output
12: fsumsqADTYPE Output
13: fvec(m) – ADTYPE array Output
14: fjac(ldfjac, n) – ADTYPE array Output
15: ldfjac – Integer Input
16: s(n) – ADTYPE array Output
17: v(ldv, n) – ADTYPE array Output
18: ldv – Integer Input
19: niter – Integer Output
20: nf – Integer Output
21: liuser Input
User workspace dimension (C++ only), see x10af to specify the dimension from Fortran.
22: iuser(*) – Integer array User Workspace
User workspace.
23: lruser Input
User workspace dimension (C++ only), see x10ae to specify the dimension from Fortran.
24: ruser(*) – ADTYPE array User Workspace
User workspace.
25: ifail – Integer Input/Output

6 Error Indicators and Warnings

e04fc preserves all error codes from e04fcf and in addition can return:
ifail=-89
An unexpected AD error has been triggered by this routine. Please contact NAG.
See Section 4.8.2 in the NAG AD Library Introduction for further information.
ifail=-199
The routine was called using a mode that has not yet been implemented.
ifail=-443
On entry: ad_handle is nullptr.
This check is only made if the overloaded C++ interface is used with arguments not of type double.
ifail=-444
A C++ exception was thrown.
The error message will show the details of the C++ exception text.
ifail=-899
Dynamic memory allocation failed for AD.
See Section 4.8.1 in the NAG AD Library Introduction for further information.

7 Accuracy

Not applicable.

8 Parallelism and Performance

e04fc is not threaded in any implementation.

9 Further Comments

None.

10 Example

The following examples are variants of the example for e04fcf, modified to demonstrate calling the NAG AD Library.
Description of the primal example.
This example finds least squares estimates of x1,x2 and x3 in the model
y=x1+t1x2t2+x3t3  
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  
The program uses (0.5,1.0,1.5) as the initial guess at the position of the minimum.

10.1 Adjoint modes

Language Source File Data Results
Fortran e04fc_a1w_fe.f90 e04fc_a1w_fe.d e04fc_a1w_fe.r
C++ e04fc_a1_algo_dcoe.cpp None e04fc_a1_algo_dcoe.r
C++ e04fc_a1t1_algo_dcoe.cpp None e04fc_a1t1_algo_dcoe.r

10.2 Tangent modes

Language Source File Data Results
Fortran e04fc_t1w_fe.f90 e04fc_t1w_fe.d e04fc_t1w_fe.r
C++ e04fc_t1_dcoe.cpp None e04fc_t1_dcoe.r
C++ e04fc_t2_dcoe.cpp None e04fc_t2_dcoe.r

10.3 Passive mode

Language Source File Data Results
Fortran e04fc_p0w_fe.f90 e04fc_p0w_fe.d e04fc_p0w_fe.r
C++ e04fc_passive_dcoe.cpp None e04fc_passive_dcoe.r