hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_fit_glin_l1sol (e02ga)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_fit_glin_l1sol (e02ga) calculates an l1 solution to an over-determined system of linear equations.

Syntax

[a, b, x, resid, irank, iter, ifail] = e02ga(a, b, 'm', m, 'nplus2', nplus2, 'toler', toler)
[a, b, x, resid, irank, iter, ifail] = nag_fit_glin_l1sol(a, b, 'm', m, 'nplus2', nplus2, 'toler', toler)

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.

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

Parameters

Compulsory Input Parameters

1:     aldanplus2 – double array
lda, the first dimension of the array, must satisfy the constraint ldam+2.
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.
2:     bm – double array
bi must contain bi, the ith element of the vector b, for i=1,2,,m.

Optional Input Parameters

1:     m int64int32nag_int scalar
Default: the dimension of the array b.
The number of equations, m (the number of rows of the matrix A).
Constraint: mn1.
2:     nplus2 int64int32nag_int scalar
Default: the second dimension of the array a.
n+2, where n is the number of unknowns (the number of columns of the matrix A).
Constraint: 3nplus2m+2.
3:     toler – double scalar
Default: 0.0.
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.

Output Parameters

1:     aldanplus2 – double array
lda=m+2.
Contains the last simplex tableau generated by the simplex method.
2:     bm – double array
The ith residual ri corresponding to the solution vector x, for i=1,2,,m.
3:     xnplus2 – double array
xj contains the jth element of the solution vector x, for j=1,2,,n. The elements xn+1 and xn+2 are unused.
4:     resid – double scalar
The sum of the absolute values of the residuals for the solution vector x.
5:     irank int64int32nag_int scalar
The computed rank of the matrix A.
6:     iter int64int32nag_int scalar
The number of iterations taken by the simplex method.
7:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

W  ifail=1
An optimal solution has been obtained but this may not be unique.
   ifail=2
The calculations have terminated prematurely due to rounding errors. Experiment with larger values of toler or try scaling the columns of the matrix (see Further Comments).
   ifail=3
On entry,nplus2<3,
ornplus2>m+2,
orlda<m+2.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

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.

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.

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_fit_glin_l1sol (e02ga) is used to solve these in the l1 sense.
function e02ga_example


fprintf('e02ga example results\n\n');

a = zeros(7, 5);
for i = 1:5
  a(i, 1) = exp((i-1)/5);
  a(i, 2) = exp(-(i-1)/5);
  a(i, 3) = 1;
end
b = [4.501;   4.36;   4.333;   4.418;   4.625];

[a, b, x, resid, irank, iter, ifail] = ...
  e02ga(a, b);

fprintf('Resid = %8.4f  Rank = %5d  Iterations = %5d\n\n',resid, irank, iter);
disp('Solution:');
disp(x(1:irank)');


e02ga example results

Resid =   0.0028  Rank =     3  Iterations =     5

Solution:
    1.0014    2.0035    1.4960


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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