NAG C Library Function Document
nag_real_partial_svd (f02wgc)
1
Purpose
nag_real_partial_svd (f02wgc) returns leading terms in the singular value decomposition (SVD) of a real general matrix and computes the corresponding left and right singular vectors.
2
Specification
#include <nag.h> |
#include <nagf02.h> |
void |
nag_real_partial_svd (Nag_OrderType order,
Integer m,
Integer n,
Integer k,
Integer ncv,
void |
(*av)(Integer *iflag,
Integer m,
Integer n,
const double x[],
double ax[],
Nag_Comm *comm),
|
|
Integer *nconv,
double sigma[],
double u[],
Integer pdu,
double v[],
Integer pdv,
double resid[],
Nag_Comm *comm,
NagError *fail) |
|
3
Description
nag_real_partial_svd (f02wgc) computes a few,
, of the largest singular values and corresponding vectors of an
by
matrix
. The value of
should be small relative to
and
, for example
. The full singular value decomposition (SVD) of an
by
matrix
is given by
where
and
are orthogonal and
is an
by
diagonal matrix with real diagonal elements,
, such that
The are the singular values of and the first columns of and are the left and right singular vectors of .
If
,
denote the leading
columns of
and
respectively, and if
denotes the leading principal submatrix of
, then
is the best rank-
approximation to
in both the
-norm and the Frobenius norm.
The singular values and singular vectors satisfy
where
and
are the
th columns of
and
respectively.
Thus, for
, the largest singular values and corresponding right singular vectors are computed by finding eigenvalues and eigenvectors for the symmetric matrix
. For
, the largest singular values and corresponding left singular vectors are computed by finding eigenvalues and eigenvectors for the symmetric matrix
. These eigenvalues and eigenvectors are found using functions from
Chapter f12. You should read the
f12 Chapter Introduction for full details of the method used here.
The real matrix
is not explicitly supplied to
nag_real_partial_svd (f02wgc). Instead, you are required to supply a function,
av, that must calculate one of the requested matrix-vector products
or
for a given real vector
(of length
or
respectively).
4
References
Wilkinson J H (1978) Singular Value Decomposition – Basic Aspects Numerical Software – Needs and Availability (ed D A H Jacobs) Academic Press
5
Arguments
- 1:
– 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
. See
Section 3.3.1.3 in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint:
or .
- 2:
– IntegerInput
-
On entry: , the number of rows of the matrix .
Constraint:
.
If , an immediate return is effected.
- 3:
– IntegerInput
-
On entry: , the number of columns of the matrix .
Constraint:
.
If , an immediate return is effected.
- 4:
– IntegerInput
-
On entry: , the number of singular values to be computed.
Constraint:
.
- 5:
– IntegerInput
-
On entry: the dimension of the arrays
sigma and
resid.
This is the number of Lanczos basis vectors to use during the computation of the largest eigenvalues of
(
) or
(
).
At present there is no
a priori analysis to guide the selection of
ncv relative to
k. However, it is recommended that
. If many problems of the same type are to be solved, you should experiment with varying
ncv while keeping
k fixed for a given test problem. This will usually decrease the required number of matrix-vector operations but it also increases the internal storage required to maintain the orthogonal basis vectors. The optimal ‘cross-over’ with respect to CPU time is problem dependent and must be determined empirically.
Constraint:
.
- 6:
– function, supplied by the userExternal Function
-
av must return the vector result of the matrix-vector product
or
, as indicated by the input value of
iflag, for the given vector
.
The specification of
av is:
void |
av (Integer *iflag,
Integer m,
Integer n,
const double x[],
double ax[],
Nag_Comm *comm)
|
|
- 1:
– Integer *Input/Output
-
On entry: if
,
ax must return the
-vector result of the matrix-vector product
.
If
,
ax must return the
-vector result of the matrix-vector product
.
On exit: may be used as a flag to indicate a failure in the computation of
or
. If
iflag is negative on exit from
av,
nag_real_partial_svd (f02wgc) will exit immediately with
fail set to
iflag.
- 2:
– IntegerInput
-
On entry: the number of rows of the matrix .
- 3:
– IntegerInput
-
On entry: the number of columns of the matrix .
- 4:
– const doubleInput
-
Note: the dimension of the array
x will be
- when ;
- when .
On entry: the vector to be pre-multiplied by the matrix or .
- 5:
– doubleOutput
-
Note: the dimension of the array
ax will be
- when ;
- when .
On exit: if
, contains the
-vector result of the matrix-vector product
.
If , contains the -vector result of the matrix-vector product .
- 6:
– Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to
av.
- user – double *
- iuser – Integer *
- p – Pointer
The type Pointer will be
void *. Before calling
nag_real_partial_svd (f02wgc) you may allocate memory and initialize these pointers with various quantities for use by
av when called from
nag_real_partial_svd (f02wgc) (see
Section 3.3.1.1 in How to Use the NAG Library and its Documentation).
Note: av should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by
nag_real_partial_svd (f02wgc). If your code inadvertently
does return any NaNs or infinities,
nag_real_partial_svd (f02wgc) is likely to produce unexpected results.
- 7:
– Integer *Output
-
On exit: the number of converged singular values found.
- 8:
– doubleOutput
-
On exit: the
nconv converged singular values are stored in the first
nconv elements of
sigma.
- 9:
– doubleOutput
-
Note: the dimension,
dim, of the array
u
must be at least
- when ;
- when .
Where
appears in this document, it refers to the array element
- when ;
- when .
On exit: the left singular vectors corresponding to the singular values stored in
sigma.
The
th element of the th left singular vector is stored in , for and .
- 10:
– IntegerInput
-
On entry: the stride used in the array
u.
Constraints:
- if ,
;
- if , .
- 11:
– doubleOutput
-
Note: the dimension,
dim, of the array
v
must be at least
- when ;
- when .
Where
appears in this document, it refers to the array element
- when ;
- when .
On exit: the right singular vectors corresponding to the singular values stored in
sigma.
The
th element of the th right singular vector is stored in , for and .
- 12:
– IntegerInput
-
On entry: the stride used in the array
v.
Constraints:
- if ,
;
- if , .
- 13:
– doubleOutput
-
On exit: the residual , for , or , for , for each of the converged singular values and corresponding left and right singular vectors and .
- 14:
– Nag_Comm *
-
The NAG communication argument (see
Section 3.3.1.1 in How to Use the NAG Library and its Documentation).
- 15:
– NagError *Input/Output
-
The NAG error argument (see
Section 3.7 in How to Use the NAG Library and its Documentation).
nag_real_partial_svd (f02wgc) returns with NE_NOERROR if at least singular values have converged and the corresponding left and right singular vectors have been computed.
6
Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_EIGENVALUES
-
The number of eigenvalues found to sufficient accuracy is zero.
- NE_INT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INT_2
-
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
- NE_INT_3
-
On entry, , and .
Constraint: .
- NE_INT_4
-
On entry, , , and .
Constraint: .
- NE_INTERNAL_ERROR
-
An error occurred during an internal call. Consider increasing the size of
ncv relative to
k.
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 2.7.6 in How to Use the NAG Library and its Documentation for further information.
- NE_LANCZOS_ITERATION
-
No shifts could be applied during a cycle of the implicitly restarted Lanczos iteration.
- NE_MAX_ITER
-
The maximum number of iterations has been reached. The maximum number of iterations . The number of converged eigenvalues .
- NE_NO_LANCZOS_FAC
-
Could not build a full Lanczos factorization.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
- NE_USER_STOP
-
On output from user-defined function
av,
iflag was set to a negative value,
.
7
Accuracy
See
Section 2.14.2 in the f08 Chapter Introduction.
8
Parallelism and Performance
nag_real_partial_svd (f02wgc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_real_partial_svd (f02wgc) 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.
None.
10
Example
This example finds the four largest singular values (
) and corresponding right and left singular vectors for the matrix
, where
is the
by
real matrix derived from the simplest finite difference discretization of the two-dimensional kernel
where
10.1
Program Text
Program Text (f02wgce.c)
10.2
Program Data
Program Data (f02wgce.d)
10.3
Program Results
Program Results (f02wgce.r)