|
◆ Zgejsv()
Sub Zgejsv |
( |
Joba As |
String, |
|
|
Jobu As |
String, |
|
|
Jobv As |
String, |
|
|
Jobr As |
String, |
|
|
Jobt As |
String, |
|
|
Jobp As |
String, |
|
|
M As |
Long, |
|
|
N As |
Long, |
|
|
A() As |
Complex, |
|
|
S() As |
Double, |
|
|
U() As |
Complex, |
|
|
V() As |
Complex, |
|
|
Info As |
Long, |
|
|
Optional Scale0 As |
Double, |
|
|
Optional Scale1 As |
Double, |
|
|
Optional Ns As |
Long, |
|
|
Optional SCond As |
Double, |
|
|
Optional Nrank As |
Long |
|
) |
| |
Singular value decomposition (SVD) of a complex matrix (preconditioned Jacobi SVD algorithm)
- Purpose
- This routine computes the singular value decomposition (SVD) of a complex m x n matrix A, where m >= n. The SVD of A is written as where SIGMA is an n x n (m x n) matrix which is zero except for its n diagonal elements, U is an m x n (or m x m) unitary matrix, and V is an n x n unitary matrix. The diagonal elements of SIGMA are the singular values of A. The columns of U and V are the left and the right singular vectors of A, respectively. The matrices U and V are computed and stored in the arrays U() and V(), respectively. The diagonal of SIGMA is computed and stored in the array S().
- Parameters
-
[in] | Joba | Specifies the level of accuracy:
= "C": This option works well (high relative accuracy) if A = B * D, with well-conditioned B and arbitrary diagonal matrix D. The accuracy cannot be spoiled by column scaling. The accuracy of the computed output depends on the condition of B, and the procedure aims at the best theoretical accuracy. The relative error max_{i = 1 to N}|d sigma_i|/sigma_i is bounded by f(M, N)*epsilon*cond(B), independent of D.
The input matrix is preprocessed with the QRF with column pivoting. This initial preprocessing and preconditioning by a rank revealing QR factorization is common for all values of Joba. Additional actions are specified as follows:
= "E": Computation as with "C" with an additional estimate of the condition number of B. It provides a realistic error bound.
= "F": If A = D1 * C * D2 with ill-conditioned diagonal scalings D1, D2, and well-conditioned matrix C, this option gives higher accuracy than the "C" option. If the structure of the input matrix is not known, and relative accuracy is desirable, then this option is advisable. The input matrix A is preprocessed with QR factorization with FULL (row and column) pivoting.
= "G": Computation as with "F" with an additional estimate of the condition number of B, where A = D*B. If A has heavily weighted rows, then using this condition number gives too pessimistic error bound.
= "A": Small singular values are the noise and the matrix is treated as numerically rank deficient. The error in the computed singular values is bounded by f(M, N)*epsilon*||A||. The computed SVD A = U * S * V^H restores A up to f(M, N)*epsilon*||A||. This gives the procedure the licence to discard (set to zero) all singular values below N*epsilon*||A||.
= "R": Similar as in "A". Rank revealing property of the initial QR factorization is used to reveal (using triangular factor) a gap sigma_r+1 < epsilon * sigma_r in which case the numerical rank is declared to be r. The SVD is computed with absolute error bounds, but more accurately than with "A". |
[in] | Jobu | Specifies whether to compute the columns of U:
= "U": N columns of U are returned in the array U().
= "F": Full set of M left singular vectors is returned in the array U().
= "W": U() may be used as workspace of length M * N. See the description of U().
= "N": U is not computed. |
[in] | Jobv | Specifies whether to compute the matrix V:
= "V": N columns of V are returned in the array V(). Jacobi rotations are not explicitly accumulated.
= "J": N columns of V are returned in the array V(), but they are computed as the product of Jacobi rotations, if Jobt = "N".
= "W": V() may be used as workspace of length N * N. See the description of V().
= "N": V is not computed. |
[in] | Jobr | Specifies the range for the singular values. Issues the licence to set to zero small positive singular values if they are outside specified range. If A <> 0 is scaled so that the largest singular value of c*A is around sqrt(big), big = Dlamch("O"), then Jobr issues the licence to kill columns of A whose norm in c*A is less than sqrt(sfmin) (for Jobr = "R"), or less than small = sfmin/epsln, where sfmin = Dlamch("S"), epsln = Dlamch("E").
= "N": Do not kill small columns of c*A. This option assumes that BLAS and QR factorizations and triangular solvers are implemented to work in that range. If the condition of A is greater than big, use Dgesvj.
= "R": Restricted range for sigma(c*A) is [sqrt(sfmin), sqrt(big)] (roughly, as described above). This option is recommended.
For computing the singular values in the full range [sfmin, big] use Dgesvj. |
[in] | Jobt | If the matrix is square then the procedure may determine to use transposed A if A^H 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 A^H*A.
= "T": Transpose if entropy test indicates possibly faster convergence of Jacobi process if A^H is taken as input. If A is replaced with A^H, then the row pivoting is included automatically.
= "N": Do not speculate.
The option "T" can be used to compute only the singular values, or the full SVD (U, SIGMA and V). For only one set of singular vectors (U or V), the caller should provide both U() and V(), as one of the arrays is used as workspace if the matrix A is transposed. See the descriptions of U() and V(). |
[in] | Jobp | Issues the licence to introduce structured perturbations to drown denormalized numbers. This licence should be active if the denormals are poorly implemented, causing slow computation, especially in cases of fast convergence (!). For the sake of simplicity, this perturbations are included only when the full SVD or only the singular values are requested. The implementer/user can easily add the perturbation for the cases of computing one set of singular vectors.
= "P": Introduce perturbation.
= "N": Do not perturb. |
[in] | M | Number of rows of the input matrix A. (M >= 0) (If M = 0, returns without computation) |
[in] | N | Number of columns of the input matrix A. (M >= N >= 0) (If N = 0, returns without computation) |
[in,out] | A() | Array A(LA1 - 1, LA2 - 1) (LA1 >= M, LA2 >= N)
[in] M x N matrix A.
[out] The contents of A() are destroyed. |
[out] | S() | Array S(LS - 1) (LS >= N)
Scale0/Scale1 = 1: The singular values of A. During the computation, S() contains Euclidean column norms of the iterated matrices in the array A().
Scale0 <> Scale1: The singular values of A are (Scale0/Scale1)*S(0 to N-1). This factored form is used if sigma_max(A) overflows or if small singular values have been saved from underflow by scaling the input matrix A.
If jobr = "R", then some of the singular values may be returned as exact zeros obtained by "set to zero" because they are below the numerical rank threshold or are denormalized numbers. |
[out] | U() | Array V(LU1 - 1, LU2 - 1) (LU1 >= M, LU2 >= M (Jobu = "F") or N (otherwise))
Jobu = "U": U() contains the M x N matrix of the left singular vectors.
Jobu = "F": U() contains the M x M matrix of the left singular vectors, including an orthonormal basis of the orthogonal complement of the Range(A).
Jobu = "W": If Jobv = "V" and Jobt = "T" and M = N, then U() is used as workspace if the procedure replaces A with A^H. In that case, V is computed in U() as left singular vectors of A^H and then copied back to the V() array. This "W" option is just a reminder to the caller that in this case U() is reserved as workspace of length N * N.
Jobu = "N": U() is not referenced, unless Jobt = "T". |
[out] | V() | Array V(LV1 - 1, LV2 - 1) (LV1 >= N, LV2 >= N)
Jobv = "V" or "J": V() contains the N x N matrix of the right singular vectors.
Jobv = "W": If Jobu = "U" and Jobt = "T" and M = N, then V() is used as workspace if the procedure replaces A with A^H. In that case, U is computed in V() as right singular vectors of A^H and then copied back to the U() array. This "W" option is just a reminder to the caller that in this case V is reserved as workspace of length N * N.
Jobv = "N": V() is not referenced, unless Jobt = "T". |
[out] | Info | = 0: Successful exit.
= -1: The argument Joba had an illegal value. (Joba <> "C", "E", "F", "G", "A" nor "R")
= -2: The argument Jobu had an illegal value. (Jobu <> "U", "F", "W" nor "N")
= -3: The argument Jobv had an illegal value. (Jobv <> "V", "J", "W" nor "N")
= -4: The argument Jobr had an illegal value. (Jobr <> "N" nor "R")
= -5: The argument Jobt had an illegal value. (Jobt <> "T" nor "N")
= -6: The argument Jobp had an illegal value. (Jobp <> "P" nor "N")
= -7: The argument M had an illegal value. (M < 0)
= -8: The argument N had an illegal value. (N < 0 or N > M)
= -9: The argument A() is invalid.
= -10: The argument S() is invalid.
= -11: The argument U() is invalid.
= -12: The argument V() is invalid.
= 1: Scaling factor is not one (Scale0 <> Scale1). (Warning)
= 2: Some of the column norms of A were denormalized floats. The requested high accuracy is not warranted by the data. (Warning)
= 29: Not converged in the maximal allowed number of sweeps (30). |
[out] | Scale0 | (Optional)
|
[out] | Scale1 | (Optional)
scale = Scale1/Scale0 is the scaling factor such that scale*S(0 to N-1) are the computed singular values of A (See the description of S()). |
[out] | Ns | (Optional)
The number of the computed nonzero singular values. |
[out] | Scond | (Optional)
An estimate for the condition number of column equilibrated A. (If Joba = "E" or "G") Sconda is an estimate of sqrt(||(R^H*R)^(-1)||_1). It is computed using Dpocon. It holds N^(-1/4)*Sconda <= ||R^(-1)||_2 <= N^(1/4)*Sconda where R is the triangular factor from the QRF of A. However, if R is truncated and the numerical rank is determined to be strictly smaller than N, Sconda is returned as -1, thus indicating that the smallest singular values might be lost. |
[out] | Nrank | (Optional)
The numerical rank determined after the initial QR factorization with pivoting. See the descriptions of Joba and Jobr. |
- Reference
- LAPACK
- Example Program
- Compute singular values and left and right singular vectors of matrix A, where
( 0.20-0.11i -0.93-0.32i 0.81+0.37i )
A = ( -0.80-0.92i -0.29+0.86i 0.64+0.51i )
( 0.71+0.59i -0.15+0.19i 0.20+0.94i )
Sub Ex_Zgejsv()
Const M = 3, N = 3
Dim A(M - 1, N - 1) As Complex, U(M - 1, N - 1) As Complex, V(N - 1, N - 1) As Complex
Dim S(N - 1) As Double, Ns As Long, Nrank As Long, Info As Long
A(0, 0) = Cmplx(0.2, -0.11): A(0, 1) = Cmplx(-0.93, -0.32): A(0, 2) = Cmplx(0.81, 0.37)
A(1, 0) = Cmplx(-0.8, -0.92): A(1, 1) = Cmplx(-0.29, 0.86): A(1, 2) = Cmplx(0.64, 0.51)
A(2, 0) = Cmplx(0.71, 0.59): A(2, 1) = Cmplx(-0.15, 0.19): A(2, 2) = Cmplx(0.2, 0.94)
Call Zgejsv("C", "U", "V", "N", "N", "N", M, N, A(), S(), U(), V(), Info, , , Ns, , Nrank)
Debug.Print "Singular values =", S(0), S(1), S(2)
Debug.Print "U ="
Debug.Print Creal(U(0, 0)), Cimag(U(0, 0)), Creal(U(0, 1)), Cimag(U(0, 1))
Debug.Print Creal(U(1, 0)), Cimag(U(1, 0)), Creal(U(1, 1)), Cimag(U(1, 1))
Debug.Print Creal(U(2, 0)), Cimag(U(2, 0)), Creal(U(2, 1)), Cimag(U(2, 1))
Debug.Print Creal(U(0, 2)), Cimag(U(0, 2))
Debug.Print Creal(U(1, 2)), Cimag(U(1, 2))
Debug.Print Creal(U(2, 2)), Cimag(U(2, 2))
Debug.Print "V^H ="
Debug.Print Creal(V(0, 0)), Cimag(V(0, 0)), Creal(V(1, 0)), Cimag(V(1, 0))
Debug.Print Creal(V(0, 1)), Cimag(V(0, 1)), Creal(V(1, 1)), Cimag(V(1, 1))
Debug.Print Creal(V(0, 2)), Cimag(V(0, 2)), Creal(V(1, 2)), Cimag(V(1, 2))
Debug.Print Creal(V(2, 0)), Cimag(V(2, 0))
Debug.Print Creal(V(2, 1)), Cimag(V(2, 1))
Debug.Print Creal(V(2, 2)), Cimag(V(2, 2))
Debug.Print "Ns =", Ns, "Nrank =", Nrank, "Info =", Info
End Sub
- Example Results
Singular values = 2.07084030821889 1.23513084760163 0.901483337149816
U =
0.322218195271111 -0.402632553976182 0.323580768676013 0.032766875846889
-0.255509191701108 -0.690011678142581 -0.219080816933185 0.593565694755161
0.438566422474147 -1.79134356330225E-02 0.612649925763086 0.34433304824613
-0.583412100357814 -0.536576742191836
0.241341326648261 6.05497287146372E-03
0.108590300074888 0.549219053729666
V^H =
0.603023103819567 1.86227915744298E-04 -0.366673081969094 0.394409352108013
0.265910254090572 -0.608232432266715 0.191162102396799 -6.37222693955672E-02
0.160663801530462 0.412183562948795 0.81816174251754 -6.93889390390723E-18
-0.160579494721751 -0.566188521062472
0.714850576679605 -8.79216760506474E-02
2.71033959614138E-02 -0.366290352480977
Ns = 3 Nrank = 3 Info = 0
|