NAG CL Interface
f10cac (svd_rowext_real)
1
Purpose
f10cac computes the singular value decomposition (SVD) of a real by matrix , optionally computing the left and/or right singular vectors by using a randomised numerical linear algebra (RNLA) method.
2
Specification
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
where
is an
by
matrix which is zero except for its
diagonal elements,
is an
by
orthogonal matrix, and
is an
by
orthogonal matrix. The diagonal elements of
are the singular values of
; they are real and non-negative, and are returned in descending order. The first
columns of
and
are the left and right singular vectors of
.
Note that the function returns , not .
If the rank of is , then has nonzero elements, and only columns of and are well-defined. In this case we can reduce to an by matrix, to an by matrix and to an by matrix.
f10cac is designed for efficiently computing the SVD in the case . The input argument should be greater than by a small oversampling parameter, , such that . A reasonable value for , to compute the SVD to within machine precision, is . The value of should not vary based on or . If 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 .
If the input argument
is less than
the accuracy depends on the
th singular value,
. See
Section 7 for more details.
A call to
f10cac consists of the following:
-
1.A random projection is applied, , where is an by matrix. (Note that the product is computed using a Fast Fourier Transform, so can be computed in time.) See f10dac for more details on the random projection.
-
2.A pivoted decomposition of is calculated (see f08bec for more details). The rank estimate is then such that, on the diagonal of ,
where and are the absolute and relative error tolerances, respectively, and is the largest diagonal index for which the above relation holds.
-
3.Obtain the SVD from the decomposition of (or, depending on the rank, an approximation to the SVD) of . 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:
– Nag_ComputeUType
Input
-
On entry: specifies options for computing part of or none of the matrix
.
- The first columns of (the left singular vectors) are returned in the array u.
- No columns of (no left singular vectors) are computed.
Constraint:
or .
-
2:
– Nag_ComputeVTType
Input
-
On entry: specifies options for computing part of or none of the matrix
.
- The first rows of (the right singular vectors) are returned in the array vt.
- No rows of (no right singular vectors) are computed.
Constraint:
or .
-
3:
– Integer
Input
-
On entry: , the number of rows of the matrix .
Constraint:
.
-
4:
– Integer
Input
-
On entry: , the number of columns of the matrix .
Constraint:
.
-
5:
– const double
Input
-
Note: the dimension,
dim, of the array
a
must be at least
.
The th element of the matrix is stored in .
On entry: the by matrix .
-
6:
– Integer
Input
-
On entry: the stride separating matrix row elements in the array
a.
Constraint:
.
-
7:
– Integer
Input
-
On entry: , number of columns in random projection, .
Constraint:
.
-
8:
– double
Input
-
On entry: the absolute tolerance, used in defining the threshold on estimating the rank of . If then is used unless in which case is used.
-
9:
– double
Input
-
On entry: the relative tolerance, used in defining the threshold on estimating the rank of . If then is used unless in which case is used.
-
10:
– Integer
Communication Array
-
Note: the dimension,
, 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:
– double
Output
-
On exit: the first
r elements of
s contain the
r largest singular values of
in descending order. The remaining values are set to zero.
-
12:
– double
Output
-
Note: the dimension,
dim, of the array
u
must be at least
when
.
The th element of the matrix is stored in .
On exit: if
,
u contains the first
r columns of
(the left singular vectors, stored column-wise); the remaining elements of
u are set to zero.
If
,
u is not referenced.
-
13:
– Integer
Input
-
On entry: the stride separating matrix row elements in the array
u.
Constraint:
if ,
-
14:
– double
Output
-
Note: the dimension,
dim, of the array
vt
must be at least
- when
;
- otherwise.
The th element of the matrix is stored in .
On exit: if
,
vt contains the first
r rows of
(the right singular vectors); the remaining elements of
vt are set to zero.
If
,
vt is not referenced.
-
15:
– Integer
Input
-
On entry: the stride separating matrix row elements in the array
vt.
Constraint:
if ,
-
16:
– Integer *
Output
-
On exit:
, contains estimated rank of array
a.
-
17:
– 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 had an illegal value.
- NE_INT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry,
state vector has been corrupted or not initialized.
- NE_INT_2
-
On entry, and .
Constraint: if , .
On entry, and .
Constraint: if , .
- 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
-
has effective rank of zero.
First diagonal element of , from of , .
Tolerance used to determine rank .
On exit,
, the rank of
may be larger than
r.
Increase
k to obtain a more accurate rank estimate.
Smallest diagonal element of
, from
of
,
.
Tolerance used to determine rank
.
7
Accuracy
The error is approximately,
where,
The norm on the left-hand side of the first equation is the spectral norm, and
is the
th singular value of
. 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.
The total number of floating-point operations is . The first term corresponds to applying the random projection, i.e., computing . The second term corresponds to the decomposition of and the steps required to obtain the SVD of the original matrix .
Deterministic SVD solvers, such as
f08kbc, require
operations when
and
operations when
.
The default values for
rtol_abs and
rtol_rel assume that you need an accurate approximation to
. 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
by
matrix
using the randomised solver,
f10cac, and a deterministic solver,
f08kbc for comparison.
10.1
Program Text
10.2
Program Data
10.3
Program Results