E02GAF (PDF version)
E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document


Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.


    1  Purpose
    7  Accuracy

1  Purpose

E02GAF calculates an l1 solution to an over-determined system of linear equations.

2  Specification


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 over-determined system of equations
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
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 ϕjt,
This is equivalent to fitting an l1 solution to the over-determined system of equations
j=1nϕjtiα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 ϕjti 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 – INTEGERInput
On entry: the number of equations, m (the number of rows of the matrix A).
Constraint: Mn1.
2:     ALDANPLUS2 – REAL (KIND=nag_wp) arrayInput/Output
On entry: Aij 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 – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which E02GAF is called.
Constraint: LDAM+2.
4:     BM – REAL (KIND=nag_wp) arrayInput/Output
On entry: Bi 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 – INTEGERInput
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:     XNPLUS2 – REAL (KIND=nag_wp) arrayOutput
On exit: Xj contains the jth element of the solution vector x, for j=1,2,,n. The elements Xn+1 and Xn+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 – INTEGEROutput
On exit: the computed rank of the matrix A.
10:   ITER – INTEGEROutput
On exit: the number of iterations taken by the simplex method.
11:   IWORKM – INTEGER arrayWorkspace
12:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this argument, the recommended value is 0. 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:
An optimal solution has been obtained but this may not be unique.
The calculations have terminated prematurely due to rounding errors. Experiment with larger values of TOLER or try scaling the columns of the matrix (see Section 9).
On entry,NPLUS2<3,
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation 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

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
where K, L and M are unknown. Given values yi at 5 points ti we may form the over-determined 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)

E02GAF (PDF version)
E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2016