NAG CL Interface
e04rmc (handle_​set_​nlnls)

Settings help

CL Name Style:


1 Purpose

e04rmc is a part of the NAG optimization modelling suite and defines the residual functions for nonlinear regression problems (such as nonlinear least squares and general nonlinear data fitting) with the given number of residuals and, optionally, the sparsity structure of their first derivatives.

2 Specification

#include <nag.h>
void  e04rmc (void *handle, Integer nres, Integer isparse, Integer nnzrd, const Integer irowrd[], const Integer icolrd[], NagError *fail)
The function may be called by the names: e04rmc or nag_opt_handle_set_nlnls.

3 Description

After the handle has been initialized (e.g., e04rac has been called), e04rmc may be used to define the residual functions in the objective function of nonlinear least squares or general nonlinear data fitting problems. If the objective function has already been defined, it will be overwritten. It will typically be used in data fitting or calibration problems of the form
minimize xn f(x)= j=1 mr χ (rj(x))    subject to lxxux ,     
where x is an n-dimensional variable vector, rj(x) are nonlinear residuals (see Section 2.2.3 in the E04 Chapter Introduction), and χ is a type of loss function. For example, the model of a least squares problem can be written as
minimize xn f(x)= j=1 mr rj (x) 2    subject to lxxux ,     
The values of the residuals, and possibly their derivatives, will be communicated to the solver by a user-supplied function. e04rmc also allows the structured first derivative matrix
[ rj(x) xi ] i=1,,n , ​ j=1,,mr  
to be declared as being dense or sparse. If declared as sparse, its sparsity structure must be specified by e04rmc. If e04rmc is called with mr=0, any existing objective function is removed, no new one is added and the problem will be solved as a feasible point problem. Note that it is possible to temporarily disable and enable individual residuals in the model by e04tcc and e04tbc, respectively.
See Section 4.1 in the E04 Chapter Introduction for more details about the NAG optimization modelling suite.

4 References

None.

5 Arguments

1: handle void * Input
On entry: the handle to the problem. It needs to be initialized (e.g., by e04rac) and must not be changed between calls to the NAG optimization modelling suite.
2: nres Integer Input
On entry: mr, the number of residuals in the objective function.
If nres=0, no objective function will be defined and irowrd and icolrd will not be referenced and may be NULL.
Constraint: nres0.
3: isparse Integer Input
On entry: is a flag indicating if the nonzero structure of the first derivative matrix is dense or sparse.
isparse=0
The first derivative matrix is considered dense and irowrd and icolrd will not be referenced and may be specified as NULL. The ordering is assumed to be column-wise, namely the function will behave as if nnzrd=n×mr and the vectors irowrd and icolrd filled as:
  • irowrd=(1,2,,n,1,2,,n,,1,2,,n);
  • icolrd=(1,1,,1,2,2,,2,,mr,mr,,mr).
isparse=1
The sparsity structure of the first derivative matrix will be supplied by nnzrd, irowrd and icolrd.
Constraint: isparse=0 or 1.
4: nnzrd Integer Input
On entry: the number of nonzeros in the first derivative matrix.
Constraint: if isparse=1 and nres>0, nnzrd>0.
5: irowrd[nnzrd] const Integer Input
6: icolrd[nnzrd] const Integer Input
On entry: arrays irowrd and icolrd store the sparsity structure (pattern) of the first derivative matrix as nnzrd nonzeros in coordinate storage (CS) format (see Section 2.1.1 in the F11 Chapter Introduction). The matrix has dimensions n×mr. irowrd specifies one-based row indices and icolrd specifies one-based column indices. No particular order of elements is expected, but elements should not repeat and the same order should be used when the first derivative matrix is evaluated for the solver.
Constraints:
  • 1irowrd[l-1]n, for l=1,2,,nnzrd;
  • 1icolrd[l-1]nres, for l=1,2,,nnzrd.
7: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_HANDLE
The supplied handle does not define a valid handle to the data structure for the NAG optimization modelling suite. It has not been properly initialized or it has been corrupted.
NE_INT
On entry, isparse=value.
Constraint: isparse=0 or 1.
On entry, nnzrd=value.
Constraint: nnzrd>0.
On entry, nres=value.
Constraint: nres0.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_INVALID_CS
On entry, i=value, icolrd[i-1]=value and nres=value.
Constraint: 1icolrd[i-1]nres.
On entry, i=value, irowrd[i-1]=value and n=value.
Constraint: 1irowrd[i-1]n.
On entry, more than one element of first derivative matrix has row index value and column index value.
Constraint: each element of first derivative matrix must have a unique row and column index.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_PHASE
The problem cannot be modified right now, the solver is running.

7 Accuracy

Not applicable.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
e04rmc is not threaded in any implementation.

9 Further Comments

9.1 Internal Changes

Internal changes have been made to this function as follows:
For details of all known issues which have been reported for the NAG Library please refer to the Known Issues.

10 Example

In this example, we demonstrate how to declare a least squares problem through e04rmc and solve it with e04ffc on a very simple example. Here n=2, mr=3 and the residuals are computed by:
r1(x) = x(1)+ x(2)- 0.9 r2(x) = 2x(1)+ x(2)- 1.9 r3(x) = 3x(1)+ x(2)- 3.0  
The expected result is:
x=(0.95,0.10)  
with an objective value of 0.015.
See also the examples in Section 10 in e04ffc and e04kfc.

10.1 Program Text

Program Text (e04rmce.c)

10.2 Program Data

None.

10.3 Program Results

Program Results (e04rmce.r)