PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_lapack_dgejsv (f08kh)
Purpose
nag_lapack_dgejsv (f08kh) computes the singular value decomposition (SVD) of a real
by
matrix
where
, and optionally computes the left and/or right singular vectors.
nag_lapack_dgejsv (f08kh) implements the preconditioned Jacobi SVD of Drmac and Veselic. This is the expert driver function that calls
nag_lapack_dgesvj (f08kj) after certain preconditioning. In most cases
nag_lapack_dgesvd (f08kb) or
nag_lapack_dgesdd (f08kd) is sufficient to obtain the SVD of a real matrix. These are much simpler to use and also handle the case
.
Syntax
[
a,
sva,
u,
v,
work,
iwork,
info] = f08kh(
joba,
jobu,
jobv,
jobr,
jobt,
jobp,
a, 'm',
m, 'n',
n)
[
a,
sva,
u,
v,
work,
iwork,
info] = nag_lapack_dgejsv(
joba,
jobu,
jobv,
jobr,
jobt,
jobp,
a, 'm',
m, 'n',
n)
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
in descending order of magnitude. The columns of
and
are the left and the right singular vectors of
. The diagonal of
is computed and stored in the array
sva.
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
http://www.netlib.org/lapack/lug
Drmac Z and Veselic K (2008a) New fast and accurate Jacobi SVD algorithm I SIAM J. Matrix Anal. Appl. 29 4
Drmac Z and Veselic K (2008b) New fast and accurate Jacobi SVD algorithm II SIAM J. Matrix Anal. Appl. 29 4
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Parameters
Compulsory Input Parameters
- 1:
– string (length ≥ 1)
-
Specifies the form of pivoting for the
factorization stage; whether an estimate of the condition number of the scaled matrix is required; and the form of rank reduction that is performed.
- The initial factorization of the input matrix is performed with column pivoting; no estimate of condition number is computed; and, the rank is reduced by only the underflowed part of the triangular factor . This option works well (high relative accuracy) if , with well-conditioned and arbitrary diagonal matrix . The accuracy cannot be spoiled by column scaling. The accuracy of the computed output depends on the condition of , and the procedure aims at the best theoretical accuracy.
- Computation as with with an additional estimate of the condition number of . It provides a realistic error bound.
- The initial factorization of the input matrix is performed with full row and column pivoting; no estimate of condition number is computed; and, the rank is reduced by only the underflowed part of the triangular factor . If with ill-conditioned diagonal scalings , , and well-conditioned matrix , this option gives higher accuracy than the option. If the structure of the input matrix is not known, and relative accuracy is desirable, then this option is advisable.
- Computation as with with an additional estimate of the condition number of , where (i.e., ). If has heavily weighted rows, then using this condition number gives too pessimistic an error bound.
- Computation as with except in the treatment of rank reduction. In this case, small singular values are to be considered as noise and, if found, the matrix is treated as numerically rank deficient. The computed SVD restores up to , where is machine precision. This gives the procedure licence to discard (set to zero) all singular values below .
- Similar to . The rank revealing property of the initial factorization is used to reveal (using the upper triangular factor) a gap in which case the numerical rank is declared to be . The SVD is computed with absolute error bounds, but more accurately than with .
Constraint:
, , , , or .
- 2:
– string (length ≥ 1)
-
Specifies options for computing the left singular vectors
.
- The first left singular vectors (columns of ) are computed and returned in the array u.
- All left singular vectors are computed and returned in the array u.
- No left singular vectors are computed, but the array u (with and second dimension at least n) is available as workspace for computing right singular values. See the description of u.
- No left singular vectors are computed. is not referenced.
Constraint:
, , or .
- 3:
– string (length ≥ 1)
-
Specifies options for computing the right singular vectors
.
- the right singular vectors (columns of ) are computed and returned in the array v; Jacobi rotations are not explicitly accumulated.
- the right singular vectors (columns of ) are computed and returned in the array v, but they are computed as the product of Jacobi rotations. This option is allowed only if or , i.e., in computing the full SVD.
- No right singular values are computed, but the array v (with and second dimension at least n) is available as workspace for computing left singular values. See the description of v.
- No right singular vectors are computed. is not referenced.
Constraints:
- , , or ;
- if or , .
- 4:
– string (length ≥ 1)
Suggested value:
.
Specifies the conditions under which columns of
are to be set to zero. This effectively specifies a lower limit on the range of singular values; any singular values below this limit are (through column zeroing) set to zero. If
is scaled so that the largest column (in the Euclidean norm) of
is equal to the square root of the overflow threshold, then
jobr allows the function to kill columns of
whose norm in
is less than
(for
), or less than
(otherwise).
is the safe range argument, as returned by function
nag_machine_real_safe (x02am).
- Only set to zero those columns of for which the norm of corresponding column of , that is, those columns that are effectively zero (to machine precision) anyway. If the condition number of is greater than the overflow threshold , where is the value returned by nag_machine_real_largest (x02al), you are recommended to use function nag_lapack_dgesvj (f08kj).
- Set to zero those columns of for which the norm of the corresponding column of . This approximately represents a restricted range for of .
For computing the singular values in the full range from the safe minimum up to the overflow threshold use
nag_lapack_dgesvj (f08kj)
Constraint:
or .
- 5:
– string (length ≥ 1)
-
Specifies, in the case
, whether the function is permitted to use the transpose of
for improved efficiency. If the matrix is square then the procedure may use transposed
if
seems to be better with respect to convergence. If the matrix is not square,
jobt is ignored. The decision is based on two values of entropy over the adjoint orbit of
. See the descriptions of
and
.
- If , perform an entropy test and then transpose if the test indicates possibly faster convergence of the Jacobi process if is taken as input. If is replaced with , then the row pivoting is included automatically.
- No entropy test and no transposition is performed.
The option
can be used to compute only the singular values, or the full SVD (
,
and
). In the case where only one set of singular vectors (
or
) is required, the caller must still provide both
u and
v, as one of the matrices is used as workspace if the matrix
is transposed. See the descriptions of
u and
v
Constraint:
or .
- 6:
– string (length ≥ 1)
-
Specifies whether the function should be allowed to introduce structured perturbations to drown denormalized numbers. For details see
Drmac and Veselic (2008a) and
Drmac and Veselic (2008b). For the sake of simplicity, these perturbations are included only when the full SVD or only the singular values are requested.
- Introduce perturbation if is found to be very badly scaled (introducing denormalized numbers).
- Do not perturb.
Constraint:
or .
- 7:
– double array
-
The first dimension of the array
a must be at least
.
The second dimension of the array
a must be at least
.
The by matrix .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the first dimension of the array
a.
, the number of rows of the matrix .
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the second dimension of the array
a.
, the number of columns of the matrix .
Constraint:
.
Output Parameters
- 1:
– double array
-
The first dimension of the array
a will be
.
The second dimension of the array
a will be
.
The contents of
a are overwritten.
- 2:
– double array
-
The, possibly scaled, singular values of
.
The singular values of are
, for , where . Normally and no scaling is required to obtain the singular values. However, if the largest singular value of overflows or if small singular values have been saved from underflow by scaling the input matrix , then .
If then some of the singular values may be returned as exact zeros because they are below the numerical rank threshold or are denormalized numbers.
- 3:
– double array
-
The first dimension,
, of the array
u will be
- if , or , ;
- otherwise .
The second dimension of the array
u will be
if
,
if
or
and
otherwise.
If
,
u contains the
by
matrix of the left singular vectors.
If
,
u contains the
by
matrix of the left singular vectors, including an orthonormal basis of the orthogonal complement of Range(
).
If
and (
and
and
), then
u is used as workspace if the procedure replaces
with
. In that case,
is computed in
u as left singular vectors of
and then copied back to the array
v.
If
,
u is not referenced.
- 4:
– double array
-
The first dimension,
, of the array
v will be
- if , or , ;
- otherwise .
The second dimension of the array
v will be
if
,
or
and
otherwise.
If
or
,
v contains the
by
matrix of the right singular vectors.
If
and (
and
and
), then
v is used as workspace if the procedure replaces
with
. In that case,
is computed in
v as right singular vectors of
and then copied back to the array
u.
If
,
v is not referenced.
- 5:
– double array
-
Contains information about the completed job.
- is the scaling factor such that
, for are the computed singular values of . (See the description of .)
- See the description of .
- sconda, an estimate for the condition number of column equilibrated (if or ). sconda is an estimate of . It is computed using nag_lapack_dpocon (f07fg). It satisfies where is the triangular factor from the factorization of . However, if is truncated and the numerical rank is determined to be strictly smaller than , sconda is returned as , thus indicating that the smallest singular values might be lost.
If full SVD is needed, and you are familiar with the details of the method, the following two condition numbers are useful for the analysis of the algorithm.
- An estimate of the scaled condition number of the triangular factor in the first factorization.
- An estimate of the scaled condition number of the triangular factor in the second factorization.
The following two parameters are computed if
.
- The entropy of : this is the Shannon entropy of taken as a point in the probability simplex.
- The entropy of .
- 6:
– int64int32nag_int array
-
Contains information about the completed job.
- The numerical rank of determined after the initial factorization with pivoting. See the descriptions of joba and jobr.
- The number of computed nonzero singular values.
- If nonzero, a warning message: If then some of the column norms of were denormalized (tiny) numbers. The requested high accuracy is not warranted by the data.
- 7:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
If , argument had an illegal value. An explanatory message is output, and execution of the program is terminated.
- W
-
nag_lapack_dgejsv (f08kh) did not converge in the allowed number of iterations (). The computed values might be inaccurate.
Accuracy
The computed singular value decomposition is nearly the exact singular value decomposition for a nearby matrix
, where
and
is the
machine precision. In addition, the computed singular vectors are nearly orthogonal to working precision. See Section 4.9 of
Anderson et al. (1999) for further details.
Further Comments
nag_lapack_dgejsv (f08kh) implements a preconditioned Jacobi SVD algorithm. It uses
nag_lapack_dgeqrf (f08ae),
nag_lapack_dgelqf (f08ah) and
nag_lapack_dgeqp3 (f08bf) as preprocessors and preconditioners. Optionally, an additional row pivoting can be used as a preprocessor, which in some cases results in much higher accuracy. An example is matrix
with the structure
, where
,
are arbitrarily ill-conditioned diagonal matrices and
is a well-conditioned matrix. In that case, complete pivoting in the first
factorizations provides accuracy dependent on the condition number of
, and independent of
,
. Such higher accuracy is not completely understood theoretically, but it works well in practice. Further, if
can be written as
, with well-conditioned
and some diagonal
, then the high accuracy is guaranteed, both theoretically and in software, independent of
.
Example
This example finds the singular values and left and right singular vectors of the
by
matrix
together with the condition number of
and approximate error bounds for the computed singular values and vectors.
Open in the MATLAB editor:
f08kh_example
function f08kh_example
fprintf('f08kh example results\n\n');
m = int64(6);
n = int64(4);
a = [2.27, -1.54, 1.15, -1.94;
0.28, -1.67, 0.94, -0.78;
-0.48, -3.09, 0.99, -0.21;
1.07, 1.22, 0.79, 0.63;
-2.35, 2.93, -1.45, 2.30;
0.62, -7.39, 1.03, -2.57];
joba = 'estimated condition number';
jobu = 'U required';
jobv = 'V required';
jobr = 'restricted range';
jobt = 'No entropy test';
jobp = 'No perturbations';
[~, s, u, v, work, iwork, info] = ...
f08kh( ...
joba, jobu, jobv, jobr, jobt, jobp, a);
eps = x02aj;
serrbd = eps*s(1);
if (abs(work(1)-work(2)) < 2*eps)
fprintf('Singular values:\n');
disp(transpose(s));
else
fprintf('Scaled singular values:\n');
disp(transpose(s));
fprintf('\nFor true singular values, multiply by a/b\n');
fprintf(' where a=%13.5e and b=%13.5e.\n', work(1), work(2));
end
[ifail] = x04ca( ...
'Gen', ' ', u, 'Left singular vectors');
fprintf('\n');
[ifail] = x04ca( ...
'Gen', ' ', v, 'Right singular vectors');
[rcondu, info] = f08fl( ...
'Left', m, n, s);
[rcondv, info] = f08fl( ...
'Right', m, n, s);
fprintf('\nEstimate of the condition number of column equilibrated A\n');
fprintf('%11.1e\n', work(3));
fprintf('\nError estimate for S:\n');
fprintf('%11.1e\n', serrbd);
fprintf('\nError estimates for U:\n');
fprintf('%11.1e ',serrbd./rcondu);
fprintf('\n\nError estimates for V:\n');
fprintf('%11.1e ',serrbd./rcondv);
fprintf('\n');
f08kh example results
Singular values:
9.9966 3.6831 1.3569 0.5000
Left singular vectors
1 2 3 4
1 0.2774 -0.6003 -0.1277 0.1323
2 0.2020 -0.0301 0.2805 0.7034
3 0.2918 0.3348 0.6453 0.1906
4 -0.0938 -0.3699 0.6781 -0.5399
5 -0.4213 0.5266 0.0413 -0.0575
6 0.7816 0.3353 -0.1645 -0.3957
Right singular vectors
1 2 3 4
1 0.1921 -0.8030 0.0041 -0.5642
2 -0.8794 -0.3926 -0.0752 0.2587
3 0.2140 -0.2980 0.7827 0.5027
4 -0.3795 0.3351 0.6178 -0.6017
Estimate of the condition number of column equilibrated A
9.0e+00
Error estimate for S:
1.1e-15
Error estimates for U:
1.8e-16 4.8e-16 1.3e-15 2.2e-15
Error estimates for V:
1.8e-16 4.8e-16 1.3e-15 1.3e-15
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015