NAG FL Interface
e02gaf (glin_​l1sol)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

e02gaf calculates an l1 solution to an overdetermined system of linear equations.

2 Specification

Fortran Interface
Subroutine e02gaf ( m, a, lda, b, nplus2, toler, x, resid, irank, iter, iwork, ifail)
Integer, Intent (In) :: m, lda, nplus2
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: irank, iter, iwork(m)
Real (Kind=nag_wp), Intent (In) :: toler
Real (Kind=nag_wp), Intent (Inout) :: a(lda,nplus2), b(m)
Real (Kind=nag_wp), Intent (Out) :: x(nplus2), resid
C Header Interface
#include <nag.h>
void  e02gaf_ (const Integer *m, double a[], const Integer *lda, double b[], const Integer *nplus2, const double *toler, double x[], double *resid, Integer *irank, Integer *iter, Integer iwork[], Integer *ifail)
The routine may be called by the names e02gaf or nagf_fit_glin_l1sol.

3 Description

Given a matrix A with m rows and n columns (mn) and a vector b with m elements, the routine calculates an l1 solution to the overdetermined system of equations
Ax=b.  
That is to say, it calculates a vector x, with n elements, which minimizes the l1 norm (the sum of the absolute values) of the residuals
r(x)=i=1m|ri|,  
where the residuals ri are given by
ri=bi-j=1naijxj,  i=1,2,,m.  
Here aij is the element in row i and column j of A, bi is the ith element of b and xj the jth element of x. The matrix A need not be of full rank.
Typically in applications to data fitting, data consisting of m points with coordinates (ti,yi) are to be approximated in the l1 norm by a linear combination of known functions ϕj(t),
α1ϕ1(t)+α2ϕ2(t)++αnϕn(t).  
This is equivalent to fitting an l1 solution to the overdetermined system of equations
j=1nϕj(ti)αj=yi,  i=1,2,,m.  
Thus if, for each value of i and j, the element aij of the matrix A in the previous paragraph is set equal to the value of ϕj(ti) and bi is set equal to yi, the solution vector x will contain the required values of the αj. Note that the independent variable t above can, instead, be a vector of several independent variables (this includes the case where each ϕi is a function of a different variable, or set of variables).
The algorithm is a modification of the simplex method of linear programming applied to the primal formulation of the l1 problem (see Barrodale and Roberts (1973) and Barrodale and Roberts (1974)). The modification allows several neighbouring simplex vertices to be passed through in a single iteration, providing a substantial improvement in efficiency.

4 References

Barrodale I and Roberts F D K (1973) An improved algorithm for discrete l1 linear approximation SIAM J. Numer. Anal. 10 839–848
Barrodale I and Roberts F D K (1974) Solution of an overdetermined system of equations in the l1-norm Comm. ACM 17(6) 319–320

5 Arguments

1: m Integer Input
On entry: the number of equations, m (the number of rows of the matrix A).
Constraint: mn1.
2: a(lda,nplus2) Real (Kind=nag_wp) array Input/Output
On entry: a(i,j) must contain aij, the element in the ith row and jth column of the matrix A, for i=1,2,,m and j=1,2,,n. The remaining elements need not be set.
On exit: contains the last simplex tableau generated by the simplex method.
3: lda Integer Input
On entry: the first dimension of the array a as declared in the (sub)program from which e02gaf is called.
Constraint: ldam+2.
4: b(m) Real (Kind=nag_wp) array Input/Output
On entry: b(i) must contain bi, the ith element of the vector b, for i=1,2,,m.
On exit: the ith residual ri corresponding to the solution vector x, for i=1,2,,m.
5: nplus2 Integer Input
On entry: n+2, where n is the number of unknowns (the number of columns of the matrix A).
Constraint: 3nplus2m+2.
6: toler Real (Kind=nag_wp) Input
On entry: a non-negative value. In general toler specifies a threshold below which numbers are regarded as zero. The recommended threshold value is ε2/3 where ε is the machine precision. The recommended value can be computed within the routine by setting toler to zero. If premature termination occurs a larger value for toler may result in a valid solution.
Suggested value: 0.0.
7: x(nplus2) Real (Kind=nag_wp) array Output
On exit: x(j) contains the jth element of the solution vector x, for j=1,2,,n. The elements x(n+1) and x(n+2) are unused.
8: resid Real (Kind=nag_wp) Output
On exit: the sum of the absolute values of the residuals for the solution vector x.
9: irank Integer Output
On exit: the computed rank of the matrix A.
10: iter Integer Output
On exit: the number of iterations taken by the simplex method.
11: iwork(m) Integer array Workspace
12: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or −1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
An optimal solution has been obtained, but may not be unique.
ifail=2
Premature termination due to rounding errors. Try using larger value of toler: toler=value.
ifail=3
On entry, lda=value and m=value.
Constraint: ldam+2.
On entry, nplus2=value.
Constraint: nplus23.
On entry, nplus2=value and m=value.
Constraint: 3nplus2m+2.
ifail=4
More than 1000*n iterations were performed. e02gaf has terminated without calculating a solution. The output data from the routine is as computed on the last good iteration. Consider increasing the value of toler. Alternatively, A may be ill conditioned—try scaling its columns.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

Experience suggests that the computational accuracy of the solution x is comparable with the accuracy that could be obtained by applying Gaussian elimination with partial pivoting to the n equations satisfied by this algorithm (i.e., those equations with zero residuals). The accuracy, therefore, varies with the conditioning of the problem, but has been found generally very satisfactory in practice.

8 Parallelism and Performance

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

9 Further Comments

The effects of m and n on the time and on the number of iterations in the Simplex Method vary from problem to problem, but typically the number of iterations is a small multiple of n and the total time taken is approximately proportional to mn2.
It is recommended that, before the routine is entered, the columns of the matrix A are scaled so that the largest element in each column is of the order of unity. This should improve the conditioning of the matrix, and also enable the argument toler to perform its correct function. The solution x obtained will then, of course, relate to the scaled form of the matrix. Thus if the scaling is such that, for each j=1,2,,n, the elements of the jth column are multiplied by the constant kj, the element xj of the solution vector x must be multiplied by kj if it is desired to recover the solution corresponding to the original matrix A.

10 Example

Suppose we wish to approximate a set of data by a curve of the form
y=Ket+Le-t+M  
where K, L and M are unknown. Given values yi at 5 points ti we may form the overdetermined set of equations for K, L and M
exiK+e-xiL+M=yi,  i=1,2,,5.  
e02gaf is used to solve these in the l1 sense.

10.1 Program Text

Program Text (e02gafe.f90)

10.2 Program Data

Program Data (e02gafe.d)

10.3 Program Results

Program Results (e02gafe.r)