This manual relates to an old release of the Library.
The documentation for the current release is also available on this site.

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

C++ Interface
#include <dco.hpp>
#include <nagad.h>
namespace nag {
namespace ad {
template <typename LSQFUN_T, typename LSQMON_T>
void e04fc ( handle_t &ad_handle, const Integer &m, const Integer &n, LSQFUN_T &&lsqfun, LSQMON_T &&lsqmon, 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, 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_handlenag::ad::handle_t Input/Output
On entry: a configuration object that holds information on the differentiation strategy. Details on setting the AD strategy are described in AD handle object in the NAG AD Library Introduction.
2: m – Integer Input
3: n – Integer Input
4: lsqfun – Callable Input
lsqfun needs to be callable with the specification listed below. This can be a C++ lambda, a functor or a (static member) function pointer. If using a lambda, parameters can be captured safely by reference. No copies of the callable are made internally.
The specification of lsqfun is:
C++ Interface
auto lsqfun = [&]( const handle_t &ad_handle, Integer &iflag, const Integer &m, const Integer &n, const ADTYPE xc[], ADTYPE fvec[])
1: ad_handlenag::ad::handle_t Input/Output
On entry: a handle to the AD handle object.
2: iflag – Integer Input/Output
3: m – Integer Input
4: n – Integer Input
5: xcADTYPE array Input
6: fvecADTYPE array Output
5: lsqmon – Callable Input
lsqmon needs to be callable with the specification listed below. This can be a C++ lambda, a functor or a (static member) function pointer. If using a lambda, parameters can be captured safely by reference. No copies of the callable are made internally.
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).
The specification of lsqmon is:
C++ Interface
auto lsqmon = [&]( const handle_t &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)
1: ad_handlenag::ad::handle_t Input/Output
On entry: a handle to the AD handle 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
6: iprint – Integer Input
7: maxcal – Integer Input
8: etaADTYPE Input
9: xtolADTYPE Input
10: stepmxADTYPE Input
11: x(n) – ADTYPE array Input/Output
Please consult Overwriting of Inputs in the NAG AD Library Introduction.
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: 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 Error Handling in the NAG AD Library Introduction for further information.
ifail=-199
The routine was called using a strategy that has not yet been implemented.
See AD Strategies in the NAG AD Library Introduction for further information.
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 Error Handling 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
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
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
C++ e04fc_passive_dcoe.cpp None e04fc_passive_dcoe.r