XLPack 7.0
XLPack Numerical Library (Excel VBA) Reference Manual
Loading...
Searching...
No Matches

◆ Dgssvd()

Sub Dgssvd ( Jobv As  String,
Jobu As  String,
M As  Long,
N As  Long,
Val() As  Double,
Ptr() As  Long,
Ind() As  Long,
Which As  String,
Nev As  Long,
Ncv As  Long,
S() As  Double,
V() As  Double,
U() As  Double,
Optional Info As  Long,
Optional Nconv As  Long,
Optional Niter As  Long,
Optional Base As  Long = -1,
Optional Format As  Long = 0,
Optional Maxiter As  Long = 300,
Optional Tol As  Double = 0 
)

Singular value decomposition (SVD) of a general sparse matrix (implicitly restarted Lanczos method (IRLM)) (Arpack) (driver)

Purpose
The singular values (s) and corresponding right singular vectors (v) for the the matrix A are computed by solving the symmetric eigenvalue problem:
(A^T*A)*v = s^2*v
where A is an M by N real general sparse matrix. The left singular vectors are also computed by u = A*v/s if required.

The sparse matrix is stored in CSC or CSR format.

The eigenvalue problem is solved by the implicitly restarted Lanczos method (IRLM) using Arpack routines Dsaupd and Dseupd.
Parameters
[in]Jobv= 'N': Do not compute right singular vector(s).
= 'V': Compute right singular vector(s).
[in]Jobu= 'N': Do not compute left singular vector(s).
= 'V': Compute left singular vector(s). (jobv must also be 'V'.)
[in]MNumber of rows of the matrix. (M >= 0) (If M = 0, returns without computation)
[in]NNumber of columns of the matrix. (N >= 0) (If N = 0, returns without computation)
[in]Val()Array Val(LVal - 1) (LVal >= Nnz)
Values of nonzero elements of input matrix (where Nnz is the number of nonzero elements).
[in]Ptr()Array Ptr(LPtr - 1) (LPtr >= N + 1
Column pointers (if CSC) or row pointers (if CSR) of input matrix.
[in]Ind()Array Ind(LInd - 1) (LInd >= Nnz)
Row indices (if CSC) or column indices (if CSR) of input matrix (where Nnz is the number of nonzero elements).
[in]Which= "LA": Compute the Nev largest (algebraic) singular values.
= "SA": Compute the Nev smallest (algebraic) singular values.
= "LM": Compute the Nev largest (in magnitude) singular values.
= "SM": Compute the Nev smallest (in magnitude) singular values.
= "BE": Compute Nev singular values, half from each end of the spectrum. When Nev is odd, compute one more from the high end than from the low end.
[in]NevNumber of singular values to be computed. (0 < Nev < N)
[in]NcvThis will indicate how many Lanczos vectors are generated at each iteration. (Nev < Ncv <= N) (Ncv >= 2*Nev is recommended)
[out]S()Array S(LS - 1) (LS >= Nev)
Contains the singular values of A. The values are returned in ascending order.
[out]V()Array V(LV1 - 1, LV2 - 1) (LV1 >= N, LV2 >= Nev)
Nev right singular vectors. Not referenced if Jobv = 'N'.
[out]U()Array U(LU1 - 1, LU2 - 1) (LU1 >= M, LU2 >= Nev)
Nev left singular vectors. Not referenced if Jobu = 'N'.
[out]InfoReturn code.
= 0: Successful exit.
< 0: The (-Info)-th argument is invalid.
= 1: Maximum number of iterations taken.
= 3: No shifts could be applied during a cycle of the implicitly restarted Lanczos iteration. A possible remedy is to increase Ncv relative to Nev (Ncv >= 2*Nev is recommended).
= 11: Initial residual vector is zero.
= 12: Failed to build a Lanczos factorization.
= 13: Error return from LAPACK eigenvalue calculation.
= 14: Dsaupd did not find any eigenvalues to sufficient accuracy.
= 15 to 17: Internal code error.
[out]Nconv(Optional)
Number of Ritz values that satisfy the convergence criterion.
[out]Niter(Optional)
Number of Lanczos update iterations taken.
[in]Base(Optional)
Indexing of Ptr() and Ind().
= 0: Zero-based (C style) indexing: Starting index is 0.
= 1: One-based (Fortran style) indexing: Starting index is 1.
(default: Assumes 1 if Ptr(0) = 1, 0 otherwise)
[in]Format(Optional)
Sparse matrix format. (default = 0)
= 0: CSR format.
= 1: CSC format.
[in]MaxIter(Optional)
Maximum number of Lanczos update iterations. (MaxIter > 0) (default = 300)
[in]Tol(Optional)
Stopping criterion: the acceptable relative accuracy of the Ritz value. (default = 0)
If Tol <= 0, machine precision is assumed.
Example Program
Computes largest two singular values and their singular vectors of matrix A where
( 1 6 11 )
( 2 7 12 )
A = ( 3 8 13 )
( 4 9 14 )
( 5 10 15 )
Sub Ex_Dgssvd()
Const M = 5, N = 3, Nnz = M * N, Ncv = 3, Nev = 2
Dim A(Nnz - 1) As Double, Ia(M) As Long, Ja(Nnz - 1) As Long
Dim S(Nev - 1) As Double, V(N - 1, Nev - 1) As Double, U(M - 1, Nev - 1) As Double
Dim Nconv As Long, Niter As Long, Info As Long, J As Long
A(0) = 1: A(1) = 6: A(2) = 11: A(3) = 2: A(4) = 7: A(5) = 12: A(6) = 3: A(7) = 8: A(8) = 13: A(9) = 4: A(10) = 9: A(11) = 14: A(12) = 5: A(13) = 10: A(14) = 15
Ia(0) = 0: Ia(1) = 3: Ia(2) = 6: Ia(3) = 9: Ia(4) = 12: Ia(5) = 15
Ja(0) = 0: Ja(1) = 1: Ja(2) = 2: Ja(3) = 0: Ja(4) = 1: Ja(5) = 2: Ja(6) = 0: Ja(7) = 1: Ja(8) = 2: Ja(9) = 0: Ja(10) = 1: Ja(11) = 2: Ja(12) = 0: Ja(13) = 1
Ja(14) = 2
Call Dgssvd("V", "V", M, N, A(), Ia(), Ja(), "LM", Nev, Ncv, S(), V(), U(), Info, Nconv)
Debug.Print "S ="
Debug.Print S(0), S(1)
Debug.Print "U ="
Debug.Print U(0, 0), U(0, 1)
Debug.Print U(1, 0), U(1, 1)
Debug.Print U(2, 0), U(2, 1)
Debug.Print U(3, 0), U(3, 1)
Debug.Print U(4, 0), U(4, 1)
Debug.Print "V ="
Debug.Print V(0, 0), V(0, 1)
Debug.Print V(1, 0), V(1, 1)
Debug.Print V(2, 0), V(2, 1)
Debug.Print "Nconv =" + Str(Nconv) + ", Info =" + Str(Info)
End Sub
Sub Dgssvd(Jobv As String, Jobu As String, M As Long, N As Long, Val() As Double, Ptr() As Long, Ind() As Long, Which As String, Nev As Long, Ncv As Long, S() As Double, V() As Double, U() As Double, Optional Info As Long, Optional Nconv As Long, Optional Niter As Long, Optional Base As Long=-1, Optional Format As Long=0, Optional Maxiter As Long=300, Optional Tol As Double=0)
Singular value decomposition (SVD) of a general sparse matrix (implicitly restarted Lanczos method (I...
Example Results
S =
2.46539669691652 35.1272233335747
U =
0.688686643768252 0.354557057037681
0.375554529395872 0.398696369998832
6.24224150234914E-02 0.442835682959984
-0.250709699348889 0.486974995921135
-0.563841813721269 0.531114308882286
V =
-0.890317132783019 0.201664911192694
-0.257331626824051 0.516830501392305
0.375653879134918 0.831996091591915
Nconv = 2, Info = 0