NAG CL Interface
e04gnc (handle_​solve_​nldf)

Note: this function uses optional parameters to define choices in the problem specification and in the details of the algorithm. If you wish to use default settings for all of the optional parameters, you need only read Sections 1 to 10 of this document. If, however, you wish to reset some or all of the settings please refer to Section 11 for a detailed description of the algorithm and to Section 12 for a detailed description of the specification of the optional parameters.
Settings help

CL Name Style:


1 Purpose

e04gnc is a solver from the NAG optimization modelling suite for general nonlinear data-fitting problems with constraints. Various loss and regularization functions are supported.

2 Specification

#include <nag.h>
void  e04gnc (void *handle,
void (*lsqfun)(Integer nvar, const double x[], Integer nres, double rx[], Integer *inform, Nag_Comm *comm),
void (*lsqgrd)(Integer nvar, const double x[], Integer nres, Integer nnzrd, double rdx[], Integer *inform, Nag_Comm *comm),
void (*confun)(Integer nvar, const double x[], Integer ncnln, double gx[], Integer *inform, Nag_Comm *comm),
void (*congrd)(Integer nvar, const double x[], Integer nnzgd, double gdx[], Integer *inform, Nag_Comm *comm),
void (*monit)(Integer nvar, const double x[], Integer *inform, const double rinfo[], const double stats[], Nag_Comm *comm),
Integer nvar, double x[], Integer nres, double rx[], double rinfo[], double stats[], Nag_Comm *comm, NagError *fail)
The function may be called by the names: e04gnc or nag_opt_handle_solve_nldf.

3 Description

e04gnc solves a data-fitting problem of the form
minimize xnvar f(x)= i=1 nres χ (ri(x)) + ρ i=1 nvar ψ (xi) subject to lg g(x) ug , 12 xT Qix + piTx + si 0 ,   1 i mQ , lB Bx uB , lx x ux , (1)
where
Here, where ϕ (ti;x) is the predicted value of the ith data point, given x. For the ith data point, yi and ti are the observed values of the independent and dependant variables respectively.
The available loss and regularization function types are summarized in Table 1, where d is the function parameter and I(L) denotes an indicator function taking the value 1 if the logical expression L is true and 0 otherwise. Loss function and regularization types can be specified by optional parameters NLDF Loss Function Type and Reg Term Type, respectively. For example, set NLDF Loss Function Type=LINF and Reg Term Type=L2 to use l-norm loss function with l2-norm (Ridge) regularization. See Section 11 for more details on the loss functions.
Table 1
Choices for the loss and regularization function types.
Loss function χ(ri) NLDF Loss Function Type
l2-norm ri2 L2
l1-norm |ri| L1
l-norm max 1j nres |rj|/ nres LINF
Huber (see (7)) { 0.5 * ri2 if ​ |ri| < d d * (|ri|-0.5*d) otherwise HUBER
Cauchy (see (4)) ln(1+ (ri/d) 2 ) CAUCHY
Atan arctan( r i 2 ) ATAN
SmoothL1 (see (8)) { 0.5 * ri2 / d if ​ |ri| < d |ri| - 0.5 * d otherwise SMOOTHL1
Quantile (see (9)) ri * (d- I (ri<0) ) QUANTILE
Regularization ψ(xi) Reg Term Type
Lasso (l1-norm) |xi| L1
Ridge (l2-norm) xi2 L2
Elastic net α|xi|+βxi2 ELASTIC NET
e04gnc serves as a solver for problems stored as a handle. The handle points to an internal data structure which defines the problem and serves as a means of communication for functions in the NAG optimization modelling suite. After the handle has been initialized (e.g., e04rac has been called), e04rmc can be used to add a model and define its residual sparsity structure. e04rsc and e04rtc may be used to set or modify quadratic constraints. Linear constraints lB, B, uB are handled by e04rjc. Variable box bounds lx and ux can be specified with e04rhc, and e04rkc can set or modify nonlinear constraints. Once the problem is fully described, the handle may be passed to the solver e04gnc. When the handle is no longer needed, e04rzc should be called to destroy it and deallocate the memory held within. See Section 4.1 in the E04 Chapter Introduction for more details about the NAG optimization modelling suite.
Nonlinear Programming (NLP) solvers e04kfc and e04stc are used as solver engines by e04gnc, which defines the selected loss function and regularization, then transforms the problem into standard form that the NLP solvers allow. For best performance, when the objective function f(x) is differentiable and without any constraint other than simple bound constraints, e04kfc is used. For non-differentiable objective functions or cases where constraints other than simple variable bounds are present, e04stc is used. See Section 11 in e04kfc and e04stc for more details on algorithmic details.
The algorithm behaviour can be modified by various optional parameters (see Section 12) which can be set by e04zmc and e04zpc anytime between the initialization of the handle by e.g., e04rac and a call to the solver. Once the solver has finished, options may be modified for the next solve. The solver may be called repeatedly with various starting points and/or optional parameters. Option getter e04znc can be called to retrieve the current value of any option.

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 to hold a problem formulation compatible with e04gnc. It must not be changed between calls to the NAG optimization modelling suite.
2: lsqfun function, supplied by the user External Function
lsqfun must evaluate the value of the nonlinear residuals, ri(x)yi-ϕ(ti;x) ,i=1,,nres , at a specified point x.
The specification of lsqfun is:
void  lsqfun (Integer nvar, const double x[], Integer nres, double rx[], Integer *inform, Nag_Comm *comm)
1: nvar Integer Input
On entry: nvar, the current number of decision variables, x, in the model.
2: x[nvar] const double Input
On entry: x, the vector of variable values at which the residuals, ri, are to be evaluated.
3: nres Integer Input
On entry: nres, the current number of residuals in the model.
4: rx[nres] double Output
On exit: the value of the residual vector, r(x), evaluated at x.
5: inform Integer * Input/Output
On entry: a non-negative value.
On exit: may be used to indicate that some residuals could not be computed at the requested point. This can be done by setting inform to a negative value. The solver will attempt a rescue procedure and request an alternative point. If the rescue procedure fails, the solver will exit with fail.code= NE_USER_NAN.
6: comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to lsqfun.
userdouble *
iuserInteger *
pPointer 
The type Pointer will be void *. Before calling e04gnc you may allocate memory and initialize these pointers with various quantities for use by lsqfun when called from e04gnc (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
3: lsqgrd function, supplied by the user External Function
lsqgrd evaluates the residual gradients, ri(x), at a specified point x.
The specification of lsqgrd is:
void  lsqgrd (Integer nvar, const double x[], Integer nres, Integer nnzrd, double rdx[], Integer *inform, Nag_Comm *comm)
1: nvar Integer Input
On entry: nvar, the current number of decision variables, x, in the model.
2: x[nvar] const double Input
On entry: x, the vector of variable values at which the residual gradients, ri(x), are to be evaluated.
3: nres Integer Input
On entry: nres, the current number of residuals in the model.
4: nnzrd Integer Input
On entry: the number of nonzeros in the first derivative matrix. If isparse =0 in the call to e04rmc (recommended use for e04gnc) then nnzrd=nvar*nres.
5: rdx[dim] double Input/Output
On entry: the elements should only be assigned and not referenced.
On exit: the vector containing the nonzero residual gradients evaluated at x,
r(x) = [r1(x),r2(x),,r nres (x)],  
where
ri(x)= [ ri(x) x1 ,, ri(x) x nvar ]T.  
The elements must be stored in the same order as the defined sparsity pattern provided in the call to e04rmc.
6: inform Integer * Input/Output
On entry: a non-negative value.
On exit: may be used to indicate that the residual gradients could not be computed at the requested point. This can be done by setting inform to a negative value. The solver will attempt a rescue procedure and request an alternative point. If the rescue procedure fails, the solver will exit with fail.code= NE_USER_NAN.
7: comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to lsqgrd.
userdouble *
iuserInteger *
pPointer 
The type Pointer will be void *. Before calling e04gnc you may allocate memory and initialize these pointers with various quantities for use by lsqgrd when called from e04gnc (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
4: confun function, supplied by the user External Function
confun must calculate the values of the mg-element vector g i(x) of nonlinear constraint functions at a specified value of the nvar-element vector of x variables. If there are no nonlinear constraints then confun will never be called by e04gnc and may be specified as NULLFN.
The specification of confun is:
void  confun (Integer nvar, const double x[], Integer ncnln, double gx[], Integer *inform, Nag_Comm *comm)
1: nvar Integer Input
On entry: nvar, the current number of decision variables, x, in the model.
2: x[nvar] const double Input
On entry: the vector x of variable values at which the constraint functions are to be evaluated.
3: ncnln Integer Input
On entry: mg, the number of nonlinear constraints, as specified in an earlier call to e04rkc.
4: gx[dim] double Output
On exit: the mg values of the nonlinear constraint functions at x.
5: inform Integer * Input/Output
On entry: a non-negative value.
On exit: must be set to a value describing the action to be taken by the solver on return from confun. Specifically, if the value is negative, then the value of gx will be discarded and the solver will either attempt to find a different trial point or terminate immediately with fail.code= NE_USER_NAN; otherwise, the solver will proceed normally.
6: comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to confun.
userdouble *
iuserInteger *
pPointer 
The type Pointer will be void *. Before calling e04gnc you may allocate memory and initialize these pointers with various quantities for use by confun when called from e04gnc (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
Note: confun should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by e04gnc. If your code inadvertently does return any NaNs or infinities, e04gnc is likely to produce unexpected results.
5: congrd function, supplied by the user External Function
congrd must calculate the nonzero values of the sparse Jacobian of the nonlinear constraint functions, gi x , at a specified value of the nvar-element vector of x variables. If there are no nonlinear constraints, congrd will never be called by e04gnc and may be specified as NULLFN.
The specification of congrd is:
void  congrd (Integer nvar, const double x[], Integer nnzgd, double gdx[], Integer *inform, Nag_Comm *comm)
1: nvar Integer Input
On entry: nvar, the current number of decision variables, x, in the model.
2: x[nvar] const double Input
On entry: the vector x of variable values at which the Jacobian of the constraint functions is to be evaluated.
3: nnzgd Integer Input
On entry: is the number of nonzero elements in the sparse Jacobian of the constraint functions, as was set in a previous call to e04rkc.
4: gdx[dim] double Input/Output
On entry: the elements should only be assigned and not referenced.
On exit: the nonzero values of the Jacobian of the nonlinear constraints, in the order specified by irowgd and icolgd in an earlier call to e04rkc. gdx[i-1] will be the gradient gj xk , where j=irowgd[i-1] and k=icolgd[i-1].
5: inform Integer * Input/Output
On entry: a non-negative value.
On exit: must be set to a value describing the action to be taken by the solver on return from congrd. Specifically, if the value is negative the solution of the current problem will terminate immediately with fail.code= NE_USER_NAN; otherwise, computations will continue.
6: comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to congrd.
userdouble *
iuserInteger *
pPointer 
The type Pointer will be void *. Before calling e04gnc you may allocate memory and initialize these pointers with various quantities for use by congrd when called from e04gnc (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
Note: congrd should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by e04gnc. If your code inadvertently does return any NaNs or infinities, e04gnc is likely to produce unexpected results.
6: monit function, supplied by the user External Function
monit is provided to enable monitoring of the progress of the optimization and, if necessary, to halt the optimization process.
If no monitoring is required, monit may be specified as NULLFN.
monit is called at the end of every ith step where i is controlled by the optional parameter NLDF Monitor Frequency (if the value is 0, monit is not called).
The specification of monit is:
void  monit (Integer nvar, const double x[], Integer *inform, const double rinfo[], const double stats[], Nag_Comm *comm)
1: nvar Integer Input
On entry: nvar, the current number of decision variables, x, in the model.
2: x[nvar] const double Input
On entry: the current best point.
3: inform Integer * Input/Output
On entry: a non-negative value.
On exit: may be used to request the solver to stop immediately by setting inform to a non-zero value in which case it will terminate with fail.code= NE_USER_STOP; otherwise, the solver will proceed normally.
4: rinfo[100] const double Input
On entry: best objective value computed and various indicators (the values are as described in the main argument rinfo).
5: stats[100] const double Input
On entry: solver statistics at monitoring steps or at the end of the current iteration (the values are as described in the main argument stats).
6: comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to monit.
userdouble *
iuserInteger *
pPointer 
The type Pointer will be void *. Before calling e04gnc you may allocate memory and initialize these pointers with various quantities for use by monit when called from e04gnc (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
7: nvar Integer Input
On entry: nvar, the current number of decision variables, x, in the model.
8: x[nvar] double Input/Output
On entry: x0, the initial estimates of the variables, x.
On exit: the final values of the variables, x.
9: nres Integer Input
On entry: nres, the current number of residuals in the model.
10: rx[nres] double Output
On exit: the values of the residuals at the final point given in x.
11: rinfo[100] double Output
On exit: objective value and various indicators at monitoring steps or at the end of the final iteration. The measures are:
0 Objective function value, f(x) in (1).
1 Loss function value, i=1 nres χ (ri(x)) in (1).
2 Regularization term value, i=1 nvar ψ (xi) in (1).
3 Solution optimality measure.
4-99 Reserved for future use.
12: stats[100] double Output
On exit: solver statistics at monitoring steps or at the end of the final iteration:
0 Number of iterations performed.
1 Total time in seconds spent in the solver. It includes time spent in user-supplied subroutines.
2-99 Reserved for future use.
13: comm Nag_Comm *
The NAG communication argument (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
14: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
e04gnc returns with fail.code= NE_NOERROR if the iterates have converged to a point x that satisfies the convergence criteria described in Section 7.

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_FAILED_START
The current starting point is unusable.
Either inform was set to a negative value within the user-supplied functions lsqfun, lsqgrd, or an Infinity or NaN was detected in values returned from them.
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_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_MAYBE_INFEASIBLE
The solver detected an infeasible problem. This indicates that the problem may be infeasible or at least that the algorithm is stuck at a locally infeasible point. If you believe that the problem is feasible, it might help to start the solver from a different point.
NE_NO_IMPROVEMENT
The solver was terminated because no further progress could be achieved.
This can indicate that the solver is calculating very small step sizes and is making very little progress. It could also indicate that the problem has been solved to the best numerical accuracy possible given the current scaling.
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_NOT_IMPLEMENTED
e04gnc is not available in this implementation.
NE_NULL_ARGUMENT
The problem requires the confun values. Please provide a proper confun function.
The problem requires the congrd derivatives. Please provide a proper congrd function.
NE_PHASE
The problem is already being solved.
NE_REF_MATCH
On entry, nres=value, expected value=value.
Constraint: nres must match the current number of residuals defined in the handle.
On entry, nvar=value, expected value=value.
Constraint: nvar must match the current number of variables of the model in the handle.
NE_SETUP_ERROR
This solver does not support the model defined in the handle.
NE_SUBPROBLEM
The solver terminated after an error in the step computation. This message is printed if the solver is unable to compute a search direction, despite several attempts to modify the iteration matrix.
The solver terminated after failure during line search. This could happen if the transformed problem is highly degenerate, does not satisfy the constraint qualification, or if the user-supplied code provides incorrect derivative information.
The solver terminated with not enough degrees of freedom. This indicates that the problem, as specified, has too few degrees of freedom. This can happen if there are too many equality constraints, or if there are too many fixed variables.
NE_TIME_LIMIT
The solver terminated after the maximum time allowed was exhausted.
Maximum number of seconds exceeded. Use optional parameter Time Limit to change the limit.
NE_TOO_MANY_ITER
Maximum number of iterations reached.
NE_USER_NAN
Invalid number detected in user function. Either inform was set to a negative value within the user-supplied functions lsqfun, lsqgrd, confun, congrd, or an Infinity or NaN was detected in values returned from them.
NE_USER_STOP
User requested termination during a monitoring step. inform was set to a negative value in monit.
NW_NOT_CONVERGED
Problem was solved to an acceptable level; full accuracy was not achieved.
This indicates that the algorithm detected a sequence of very small reductions in the objective function value and is unable to reach a point satisfying the requested optimality tolerance. This may happen if the desired tolerances are too small for the current problem, or if the input data is badly scaled.

7 Accuracy

The accuracy of the solution is determined by optional parameters NLDF Stop Tolerance.
In the case where both loss function and regularization are differentiable, and with only simple bound constraints, if fail.code= NE_NOERROR on exit, the returned point satisfies the first-order optimality conditions defined by (6) and (7) in e04kfc to the requested accuracy. If the loss or regularization functions are non-differentiable, or the model defines linear, quadratic or general nonlinear constraint, the model is transformed and solved by e04stc. In this case, if fail.code= NE_NOERROR on exit, the returned point satisfies the Karush–Kuhn–Tucker (KKT) condition defined by (10) in e04stc to the requested accuracy.

8 Parallelism and Performance

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

9 Further Comments

9.1 Description of the Printed Output

The solver can print information to give an overview of the problem and the progress of the computation. The output may be sent to two independent file ID which are set by optional parameters Print File and Monitoring File. Optional parameters Print Level, Print Options, Monitoring Level and Print Solution determine the exposed level of detail. This allows, for example, a detailed log file to be generated while the condensed information is displayed on the screen.
By default (Print File=6, Print Level=2), the following sections are printed to the standard output:
Header
The header is a message indicating the start of the solver. It should look like:
-------------------------------
 E04GN, Nonlinear Data-Fitting
-------------------------------
Optional parameters list
If Print Options=YES, a list of the optional parameters and their values is printed before the problem statistics. The list shows all options of the solver, each displayed on one line. Each line contains the option name, its current value and an indicator for how it was set. The options unchanged from their defaults are noted by ‘d’ and the ones you have set are noted by ‘U’. Note that the output format is compatible with the file format expected by e04zpc. The output looks similar to:
Begin of Options
    Nldf Loss Function Type       =            Smoothl1     * U
    Nldf Huber Function Width     =         1.00000E+00     * d
    Nldf Cauchy Function Sharpness=         1.00000E+00     * d
    Nldf Smoothl1 Function Width  =         1.00000E+00     * d
    Nldf Quantile Parameter       =         5.00000E-01     * d
    Nldf Iteration Limit          =            10000000     * d
    Nldf Stop Tolerance           =         1.00000E-06     * d
    Nldf Monitor Frequency        =                   0     * d
    Nldf Elastic Net Alpha        =         5.00000E-01     * d
    Nldf Elastic Net Beta         =         5.00000E-01     * d
End of Options
Problem statistics
If Print Level2, statistics on the problem are printed, for example:
Problem Statistics
  No of variables                  6
    linear                         2
    nonlinear                      4
    free (unconstrained)           4
    bounded                        2
  No of lin. constraints           1
    nonzeroes                      2
  No of quad.constraints           0
  No of nln. constraints           4
    nonzeroes                      3
  Loss function             SmoothL1
    No of residuals               24
  Regularization             L1 Norm
Iteration log
If Print Level2, the solver will print a summary line for each step. If no regularization function is specified, the output shows the iteration number, the current loss function value and the optimality measure. The output looks as follows:
--------------------------
 it|   lossfun  |  optim
--------------------------
  1  1.05863E+02  3.25E+02
  2  3.51671E+01  9.03E+01
  3  2.79091E+01  4.95E+01
  4  2.63484E+01  1.43E+01
  5  2.30795E+01  2.59E+01
If you specify a regularization type via Reg Term Type, two more columns will be printed out showing the regularization function value and the objective function value f(x) defined in (1). It might look as follows:
----------------------------------------------------
 it|   objfun   |   lossfun  |     reg    |  optim
----------------------------------------------------
  1  2.11489E+01  2.02833E+01  8.65649E-01  1.27E+02
  2  2.28405E+01  2.21698E+01  6.70710E-01  9.47E+01
  3  2.30351E+01  2.23599E+01  6.75246E-01  1.62E+01
  4  2.22836E+01  2.15675E+01  7.16133E-01  1.32E+01
  5  2.22676E+01  2.15522E+01  7.15411E-01  3.80E+00
  6  2.21776E+01  2.14746E+01  7.02983E-01  3.92E-01
  7  2.22075E+01  2.15060E+01  7.01510E-01  6.08E-01
Summary
Once the solver finishes, a summary is produced:
 ----------------------------------------------------
 Status: converged, an optimal solution found
 ----------------------------------------------------
 Final objective value                2.216883E+01
 Final loss function value            2.146563E+01
 Final regularization value           7.031993E-01
 Solver stopping precision            1.068791E-08
 Iterations                                     16
Optionally, if Stats Time=YES, the timings are printed:
 Total time                               0.19 sec
Solution
If Print Solution=YES, the values of the primal variables are printed. It might look as follows:
 Primal variables:
   idx   Lower bound       Value       Upper bound
     1  -1.00000E+00    9.69201E-02         inf
     2   0.00000E+00    7.95110E-01    1.00000E+00

9.2 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

This example demonstrates how to define and solve a nonlinear regression problem using both least squares and robust regression. The regression problem consists of nres=24 observations, (t,y), to be fitted over the nvar=2 parameter model
y= ϕ (t;x) + ε = t x1 sin(-tx2) + ε ,  
and the residuals for the regression are
ri (x) = yi - ϕ (ti,x) i = 1 : nres ,  
where
t = ( 1.00,0 2.00,0 3.00,0 4.00,0 5.00,0 6.00,0 7.00,0 8.00,0 9.00,0 10.00, ( 11.00,0 12.00,0 13.00,0 14.00,0 15.00,0 16.00,0 17.00,0 18.00,0 19.00,0 20.00,0 ( 21.00,0 22.00,0 23.00,0 24.00 ) ; y = ( 0.0523,0 0.1442,0 0.0422,0 1.8106,0 0.3271,0 0.4684,0 0.4593,0 −0.0169,0 −0.7811,0 −1.1356,0 ( −0.5343,0 −3.0043,0 1.1832,0 1.5153,0 0.7120,0 −2.2923,0 −1.4871,0 −1.7083,0 −0.9936,0 −5.2873,0 ( 1.7555,0 2.0642,0 0.9499,0 −0.6234).  
The data above is generated by setting x1=0.1 and x2=0.8 with added random noise. Data point (ti,yi) for i=4 ,12 ,16 ,20 are set to be outliers.
The following bounds and general linear constraints are defined on the variables
-1.0 x1 0.0 x2 1.0, 0.2 x1 + x2 1.0  
Setting the initial guess to be x0=(0.3,0.7), the problem is first solved using least squares loss function and the expected solution is x*=(0.0944,0.7740). Then the loss function type is switched to SmoothL1 and the problem is solved again. The expected solution is x*=(0.0969,0.7951), which is an improvement over least squares fit for outlier handling.

10.1 Program Text

Program Text (e04gnce.c)

10.2 Program Data

None.

10.3 Program Results

Program Results (e04gnce.r)
GnuplotProduced by GNUPLOT 5.4 patchlevel 6 -6 -5 -4 -3 -2 -1 0 1 2 3 0 5 10 15 20 25 y(t) t Data points Data points Least squares Least squares SmoothL1 SmoothL1 Example Program Nonlinear Regression Using Least Squares and SmoothL1 Loss Functions to a Set of 24 Data Points

11 Algorithmic Details

e04gnc will use the provided model, model derivative, and data to internally construct an optimization problem, and pass it off to the appropriate nonlinear programming solver. Depending on the choice of loss and regularization functions, as well as the types of constraints present, either a first-order active set method solver (e.g., e04kfc) or a general nonlinear programming solver (e.g., e04stc) will be called to maximize performance.

11.1 Loss Function and Regularization Types

Loss function and regularization types can be specified by optional parameters NLDF Loss Function Type and Reg Term Type, respectively. The definitions of the available loss and regularization functions are:

11.2 Optimization Problem Transformations

e04gnc uses auxiliary variables and constraints to implement non-differentiable loss functions (L1, Quantile, Linf) and regularization functions (L1, Elastic net). For any method that uses loss function derivatives to compute a search direction, a loss function which is not differentiable will cause problems, especially if it is non-differentiable at its minima. To solve this, we transform a model with non-differentiable loss or regularization functions into a new model with differentiable constraints and a differentiable objective function.
Consider the case where we select L1 loss and turn off regularization:
minimize xnvar i=1 nres |ri(x)| .  
This is equivalent to the problem:
minimize xnvar , zi i=1 nres zi subject to -zi ri(x) zi ,   for ​ i = 1 ,, nres ,  
where the zi>0 are nres new auxiliary variables.
Each zi serves as an upper bound to |ri(x)|, so that a minimum of i=1 nres zi in the search space comprising x and zi, is also a minimum of i=1 nres |ri(x)| .
Similarly for Quantile loss with no regularization, we transform the problem:
minimize xnvar i=1 nres ri(x) · (dqnt-I(ri(x)<0))  
into the equivalent model:
minimize xnvar , zi i=1 nres zi subject to -zi / (1-dqnt) ri(x) zi / dqnt ,   for ​ i = 1,,nres .  
For Linf loss with no regularization, we transform the model:
minimize xnvar maxi |ri(x)|  
into the model:
minimize xnvar , z z subject to -z ri(x) z ,   for ​ i = 1 ,, nres .  
If regularization is present, we transform it separately from the loss function if the regularization is non-differentiable. For example, the problem
minimize xnvar i=1 nres |ri(x)| + ρ i=1 nvar |xi|  
is transformed to:
minimize xnvar , zi , vi i=1 nres zi + ρ i=1 nvar vi subject to -zi ri (x) zi ,   for ​ i = 1 ,, nres , -vi xi vi ,   for ​ i = 1 ,, nvar ,  
where the vi are the auxiliary variables for the regularization.

12 Optional Parameters

Several optional parameters in e04gnc define choices in the problem specification or the algorithm logic. In order to reduce the number of formal arguments of e04gnc, these optional parameters have associated default values that are appropriate for most problems. Therefore, you need only specify those optional parameters whose values are to be different from their default values.
The remainder of this section can be skipped if you wish to use the default values for all optional parameters.
The optional parameters can be changed by calling e04zmc anytime between the initialization of the handle and the call to the solver. Modification of the optional parameters during intermediate monitoring stops is not allowed. Once the solver finishes, the optional parameters can be altered again for the next solve.
The option values may be retrieved by e04znc.
The following is a list of the optional parameters available. A full description of each optional parameter is provided in Section 12.1.

12.1 Description of the Optional Parameters

For each option, we give a summary line, a description of the optional parameter and details of constraints.
The summary line contains:
All options accept the value DEFAULT to return single options to their default states.
Keywords and character values are case and white space insensitive.
Defaults
This special keyword may be used to reset all optional parameters to their default values. Any value given with this keyword will be ignored.
NLDF Iteration LimitiDefault =10000000
The maximum number of iterations to be performed by e04gnc. If this limit is reached, then the solver will terminate with fail.code= NE_TOO_MANY_ITER.
Constraint: NLDF Iteration Limit1.
NLDF Monitor FrequencyiDefault =0
If NLDF Monitor Frequency>0, the user-supplied function monit will be called at the end of every ith step for monitoring purposes.
Constraint: NLDF Monitor Frequency0.
NLDF Stop TolerancerDefault = max(10−6,ε)
This parameter sets the value of εtol which specifies the tolerance for the optimality measure.
When both loss function and regularization are differentiable, and with only simple bound constraints, the optimality measures are defined by (6) and (7) in e04kfc and NLDF Stop Tolerance is passed to the solver e04kfc as FOAS Stop Tolerance.
When any of the loss function or regularization is non-differentiable, or there presents linear, quadratic or general nonlinear constraint, the optimality measure is defined by (10) in e04stc and NLDF Stop Tolerance is passed to the solver e04stc as Stop Tolerance 1.
Constraint: 0εtol<1.
NLDF Loss Function TypeaDefault =L2
This parameter sets the loss function type used in the objective function.
Constraint: NLDF Loss Function Type=HUBER, L2, CAUCHY, ATAN, SMOOTHL1, LINF, L1 or QUANTILE.
Reg Term TypeaDefault =OFF
This parameter sets the regularization function type used in the objective function.
Note:  if there is no residual in the model, regularization will be turned off.
Constraint: Reg Term Type=OFF, L2, L1 or ELASTIC NET.
NLDF Huber Function WidthrDefault =1.0
Sets the parameter dhub defined in the Huber loss function (7).
Constraint: NLDF Huber Function Width>0.
NLDF Cauchy Function SharpnessrDefault =1.0
Sets the parameter dcau defined in the Cauchy loss function (4).
Constraint: NLDF Cauchy Function Sharpness>0.
NLDF SmoothL1 Function WidthrDefault =1.0
Sets the parameter dsl1 defined in the SmoothL1 loss function (8).
Constraint: NLDF SmoothL1 Function Width>0.
NLDF Quantile ParameterrDefault =0.5
Sets the parameter dqnt defined in the Quantile loss function (9).
Constraint: 0<NLDF Quantile Parameter<1.
Reg CoefficientrDefault =1.0
Sets the regularization coefficient ρ in the definition of the objective function (1). Note:  if set to 0, regularization will be turned off.
Constraint: Reg Coefficient0.
NLDF Elastic Net AlpharDefault =0.5
Sets the regularization coefficient α in the definition of the elastic net regularization function (10).
Note:  if set to 0, the regularization function reduces to the l2-norm. In this case, only the regularization coefficient Reg Coefficient is used, and the value of NLDF Elastic Net Beta is ignored.
Constraint: NLDF Elastic Net Alpha0.
NLDF Elastic Net BetarDefault =0.5
Sets the regularization coefficient β in the definition of the elastic net regularization function (10).
Note:  if set to 0, the regularization function reduces to the l1-norm. In this case, only the regularization coefficient Reg Coefficient is used, and the value of NLDF Elastic Net Alpha is ignored.
Constraint: NLDF Elastic Net Beta0.
Infinite Bound SizerDefault =1020
This defines the ‘infinite’ bound bigbnd in the definition of the problem constraints. Any upper bound greater than or equal to bigbnd will be regarded as + (and similarly any lower bound less than or equal to -bigbnd will be regarded as -). Note that a modification of this optional parameter does not influence constraints which have already been defined; only the constraints formulated after the change will be affected.
Constraint: Infinite Bound Size1000.
Monitoring FileiDefault =−1
(See Section 3.1.1 in the Introduction to the NAG Library CL Interface for further information on NAG data types.)
If i0, the Nag_FileID number (as returned from x04acc) for the secondary (monitoring) output. If Monitoring File=−1, no secondary output is provided. The information output to this file ID is controlled by Monitoring Level.
Constraint: Monitoring File−1.
Monitoring LeveliDefault =4
This parameter sets the amount of information detail that will be printed by the solver to the secondary output. The meaning of the levels is the same as for Print Level.
Constraint: 0Monitoring Level5.
Print FileiDefault =Nag_FileID number associated with stdout
(See Section 3.1.1 in the Introduction to the NAG Library CL Interface for further information on NAG data types.)
If i0, the Nag_FileID number (as returned from x04acc, stdout as the default) for the primary output of the solver. If Print File=−1, the primary output is completely turned off independently of other settings. The information output to this unit is controlled by Print Level.
Constraint: Print File−1.
Print LeveliDefault =2
This parameter defines how detailed information should be printed by the solver to the primary and secondary output.
i Output
0 No output from the solver.
1 The Header and Summary.
2, 3, 4, 5 Additionally, the Iteration log.
Constraint: 0Print Level5.
Print OptionsaDefault =YES
If Print Options=YES, a listing of optional parameters will be printed to the primary output and is always printed to the secondary output.
Constraint: Print Options=YES or NO.
Print SolutionaDefault =NO
If Print Solution=YES or X, the final values of the primal variables are printed on the primary and secondary outputs.
Constraint: Print Solution=YES, NO or X.
Stats TimeaDefault =NO
This parameter turns on timing. This might be helpful for a choice of different solving approaches. It is possible to choose between CPU and wall clock time. Choice YES is equivalent to WALL CLOCK.
Constraint: Stats Time=YES, NO, CPU or WALL CLOCK.
Time LimitrDefault =106
A limit to the number of seconds that the solver can use to solve one problem. If at the end of an iteration this limit is exceeded, the solver will terminate with fail.code= NE_TIME_LIMIT.
Constraint: Time Limit>0.