nag_lone_fit (e02gac) (PDF version)
e02 Chapter Contents
e02 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_lone_fit (e02gac)

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_lone_fit (e02gac) calculates an l1 solution to an over-determined system of linear equations.

2  Specification

#include <nag.h>
#include <nage02.h>
void  nag_lone_fit (Nag_OrderType order, Integer m, double a[], double b[], Integer nplus2, double toler, double x[], double *resid, Integer *rank, Integer *iter, NagError *fail)

3  Description

Given a matrix A with m rows and n columns mn and a vector b with m elements, the function calculates an l1 solution to the over-determined 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
rx=i=1mri,  
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,
α1ϕ1t+α2ϕ2t++αnϕnt.  
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:     order Nag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by order=Nag_RowMajor. See Section 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2:     m IntegerInput
On entry: the number of equations, m (the number of rows of the matrix A).
Constraint: mn1.
3:     a[m+2×nplus2] doubleInput/Output
Note: where Ai,j appears in this document, it refers to the array element
  • a[j-1×m+2+i-1] when order=Nag_ColMajor;
  • a[i-1×nplus2+j-1] when order=Nag_RowMajor.
On entry: Ai,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.
4:     b[m] doubleInput/Output
On entry: b[i-1] 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 doubleInput
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 function 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] doubleOutput
On exit: x[j-1] contains the jth element of the solution vector x, for j=1,2,,n. The elements x[n] and x[n+1] are unused.
8:     resid double *Output
On exit: the sum of the absolute values of the residuals for the solution vector x.
9:     rank 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:   fail NagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.2.1.2 in the Essential Introduction for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, nplus2=value.
Constraint: nplus23.
NE_INT_2
On entry, nplus2=value and m=value.
Constraint: 3nplus2m+2.
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.
An unexpected error has been triggered by this function. Please contact NAG.
See Section 3.6.6 in the Essential Introduction for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 3.6.5 in the Essential Introduction for further information.
NE_NON_UNIQUE
An optimal solution has been obtained, but may not be unique.
NE_TERMINATION_FAILURE
Premature termination due to rounding errors. Try using larger value of toler: toler=value.

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

Not applicable.

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 function 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 over-determined set of equations for K, L and M 
exiK+e-xiL+M=yi,  i=1,2,,5.  
nag_lone_fit (e02gac) is used to solve these in the l1 sense.

10.1  Program Text

Program Text (e02gace.c)

10.2  Program Data

Program Data (e02gace.d)

10.3  Program Results

Program Results (e02gace.r)


nag_lone_fit (e02gac) (PDF version)
e02 Chapter Contents
e02 Chapter Introduction
NAG Library Manual

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