NAG CL Interface
f10cac (svd_​rowext_​real)

Settings help

CL Name Style:


1 Purpose

f10cac computes the singular value decomposition (SVD) of a real m×n matrix A, optionally computing the left and/or right singular vectors by using a randomised numerical linear algebra (RNLA) method.

2 Specification

#include <nag.h>
void  f10cac (Nag_ComputeUType jobu, Nag_ComputeVTType jobvt, Integer m, Integer n, const double a[], Integer pda, Integer k, double rtol_abs, double rtol_rel, Integer state[], double s[], double u[], Integer pdu, double vt[], Integer pdvt, Integer *r, NagError *fail)
The function may be called by the names: f10cac or nag_rnla_svd_rowext_real.

3 Description

The SVD is written as
A = UΣVT ,  
where Σ is an m×n matrix which is zero except for its min(m,n) diagonal elements, U is an m×m orthogonal matrix, and V is an n×n orthogonal matrix. The diagonal elements of Σ are the singular values of A; they are real and non-negative, and are returned in descending order. The first min(m,n) columns of U and V are the left and right singular vectors of A.
Note that the function returns VT, not V.
If the rank of A is r<min(m,n), then σ has r nonzero elements, and only r columns of U and V are well-defined. In this case we can reduce σ to an r×r matrix, U to an m×r matrix and VT to an r×n matrix.
f10cac is designed for efficiently computing the SVD in the case r<min(m,n). The input argument k should be greater than r by a small oversampling parameter, δ, such that k=r+δ. A reasonable value for δ, to compute the SVD to within machine precision, is δ=5. The value of δ should not vary based on m or n. If r is not known then the function can be used iteratively to refine the estimate and accuracy of the computed SVD; using a larger value of δ than necessary increases the computational cost of the function.
As a by-product of computing the SVD, the function estimates r.
If the input argument k is less than r the accuracy depends on the (k+1)th singular value, σk+1. See Section 7 for more details.
A call to f10cac consists of the following:
  1. 1.A random projection is applied, Y=AΩ, where Ω is an n×k matrix. (Note that the product AΩ is computed using a Fast Fourier Transform, so can be computed in O(mnlog(k)) time.) See f10dac for more details on the random projection.
  2. 2.A pivoted QR decomposition of Y is calculated (see f08bfc for more details). The rank estimate is then r such that, on the diagonal of R,
    | R rr | > εa + εr × R 11 ,  
    where εa and εr are the absolute and relative error tolerances, respectively, and r is the largest diagonal index for which the above relation holds.
  3. 3.Obtain the SVD from the QR decomposition of Y (or, depending on the rank, an approximation to the SVD) of A. This is referred to as row extraction.
Further details of the randomized SVD procedure can be found in Sections 4 and 5 of Halko et al. (2011).

4 References

Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (1999) LAPACK Users' Guide (3rd Edition) SIAM, Philadelphia https://www.netlib.org/lapack/lug
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Halko N (2012) Randomized methods for computing low-rank approximations of matrices PhD thesis
Halko N, Martinsson P G and Tropp J A (2011) Finding structure with randomness: Probabilistic algorithms for constructing approximate matrix decompositions SIAM Rev. 53(2) 217–288 https://epubs.siam.org/doi/abs/10.1137/090771806

5 Arguments

1: jobu Nag_ComputeUType Input
On entry: specifies options for computing part of or none of the matrix U.
jobu=Nag_SingularVecsU
The first k columns of U (the left singular vectors) are returned in the array u.
jobu=Nag_NotU
No columns of U (no left singular vectors) are computed.
Constraint: jobu=Nag_SingularVecsU or Nag_NotU.
2: jobvt Nag_ComputeVTType Input
On entry: specifies options for computing part of or none of the matrix VT.
jobvt=Nag_SingularVecsVT
The first k rows of VT (the right singular vectors) are returned in the array vt.
jobvt=Nag_NotVT
No rows of VT (no right singular vectors) are computed.
Constraint: jobvt=Nag_SingularVecsVT or Nag_NotVT.
3: m Integer Input
On entry: m, the number of rows of the matrix A.
Constraint: m>0.
4: n Integer Input
On entry: n, the number of columns of the matrix A.
Constraint: n>0.
5: a[dim] const double Input
Note: the dimension, dim, of the array a must be at least pda×n.
The (i,j)th element of the matrix A is stored in a[(j-1)×pda+i-1].
On entry: the m×n matrix A.
6: pda Integer Input
On entry: the stride separating matrix row elements in the array a.
Constraint: pdam.
7: k Integer Input
On entry: k, number of columns in random projection, Y=AΩ.
Constraint: 0<kmin(m,n).
8: rtol_abs double Input
On entry: the absolute tolerance, εa used in defining the threshold on estimating the rank of A. If rtol_abs<0.0 then 0.0 is used unless rtol_rel0.0 in which case machine precision is used.
9: rtol_rel double Input
On entry: the relative tolerance, εr used in defining the threshold on estimating the rank of A. If rtol_rel<0.0 then 0.0 is used unless rtol_abs0.0 in which case machine precision is used.
10: state[dim] Integer Communication Array
Note: the dimension, dim, of this array is dictated by the requirements of associated functions that must have been previously called. This array MUST be the same array passed as argument state in the previous call to nag_rand_init_repeatable (g05kfc) or nag_rand_init_nonrepeatable (g05kgc).
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
11: s[k] double Output
On exit: the first r elements of s contain the r largest singular values of A in descending order. The remaining values are set to zero.
12: u[dim] double Output
Note: the dimension, dim, of the array u must be at least k when jobu=Nag_SingularVecsU.
The (i,j)th element of the matrix U is stored in u[(j-1)×pdu+i-1].
On exit: if jobu=Nag_SingularVecsU, u contains the first r columns of U (the left singular vectors, stored column-wise); the remaining elements of u are set to zero.
If jobu=Nag_NotU, u is not referenced.
13: pdu Integer Input
On entry: the stride separating matrix row elements in the array u.
Constraint: if jobu=Nag_SingularVecsU, pdum
14: vt[dim] double Output
Note: the dimension, dim, of the array vt must be at least
  • pdvt×n when jobvt=Nag_SingularVecsVT;
  • 1 otherwise.
The (i,j)th element of the matrix is stored in vt[(j-1)×pdvt+i-1].
On exit: if jobvt=Nag_SingularVecsVT, vt contains the first r rows of VT (the right singular vectors); the remaining elements of vt are set to zero.
If jobvt=Nag_NotVT, vt is not referenced.
15: pdvt Integer Input
On entry: the stride separating matrix row elements in the array vt.
Constraint: if jobvt=Nag_SingularVecsVT, pdvtk
16: r Integer * Output
On exit: r, contains estimated rank of array a.
17: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

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_INT
On entry, k=value.
Constraint: 0<kmin(m,n).
On entry, m=value.
Constraint: m>0.
On entry, n=value.
Constraint: n>0.
On entry, pda=value.
Constraint: pdam.
On entry, state vector has been corrupted or not initialized.
NE_INT_2
On entry, jobu=value and pdu=value.
Constraint: if jobu=Nag_SingularVecsU, pdum.
On entry, jobvt=value and pdvt=value.
Constraint: if jobvt=Nag_SingularVecsVT, pdvtk.
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_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_REAL
A has effective rank of zero.
First diagonal element of R, from QR of Y, =value.
Tolerance used to determine rank =value.
On exit, r=k, the rank of A may be larger than r.
Increase k to obtain a more accurate rank estimate.
Smallest diagonal element of R, from QR of Y, =value.
Tolerance used to determine rank =value.

7 Accuracy

The error is approximately,
A-UσV* < [1+ 1 + 4k (n-k) ] ε ,  
where,
ε= 1+7n/k · σk+1 .  
The norm on the left-hand side of the first equation is the spectral norm, and σk+1 is the (k+1)th singular value of A. More details on the error bound can be found in Sections 5 and 11 of Halko et al. (2011).

8 Parallelism and Performance

f10cac is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f10cac makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

The total number of floating-point operations is O(log(k)mn+k2(m+n)). The first term corresponds to applying the random projection, i.e., computing Y=AΩ. The second term corresponds to the QR decomposition of Y and the steps required to obtain the SVD of the original matrix A.
Deterministic SVD solvers, such as f08kbc, require O(mn2) operations when mn and O(nm2) operations when nm.
The default values for rtol_abs and rtol_rel assume that you need an accurate approximation to A. If you only need to use a small number of singular values or singular vectors, larger values for these tolerances are appropriate. Increasing tolerances sufficiently will decrease r, the estimated rank. Decreasing r means that k can then be decreased to reduce the run-time of the routine.

10 Example

This example finds the singular values, the left and right singular vectors, and the rank of the 6×6 matrix
A = ( 2.27 0.28 -0.48 1.07 -2.35 0.62 -1.54 -1.67 -3.09 1.22 2.93 -7.39 1.15 0.94 0.99 0.79 -1.45 1.03 -1.94 -0.78 -0.21 0.63 2.30 -2.57 -1.94 -0.78 -0.21 0.63 2.30 -2.57 -1.94 -0.78 -0.21 0.63 2.30 -2.57 ) ,  
using the randomised solver, f10cac, and a deterministic solver, f08kbc for comparison.

10.1 Program Text

Program Text (f10cace.c)

10.2 Program Data

Program Data (f10cace.d)

10.3 Program Results

Program Results (f10cace.r)