Singular Value Decomposition
svds(A; nsv=6, ritzvec=true, tol=0.0, maxiter=1000, ncv=2*nsv, v0=zeros((0,))) -> (SVD([left_sv,] s, [right_sv,]), nconv, niter, nmult, resid)
Computes the largest singular values s of A using implicitly restarted Lanczos iterations derived from eigs.
Inputs
A: Linear operator whose singular values are desired.Amay be represented as a subtype ofAbstractArray, e.g., a sparse matrix, or any other type supporting the four methodssize(A),eltype(A),A * vector, andA' * vector.nsv: Number of singular values. Default: 6.ritzvec: Iftrue, return the left and right singular vectorsleft_svandright_sv. Iffalse, omit the singular vectors. Default:true.tol: tolerance, seeeigs.maxiter: Maximum number of iterations, seeeigs. Default: 1000.ncv: Maximum size of the Krylov subspace, seeeigs(there callednev). Default:2*nsv.v0: Initial guess for the first Krylov vector. It may have lengthmin(size(A)...), or 0.
Outputs
svd: AnSVDobject containing the left singular vectors, the requested values, and the right singular vectors. Ifritzvec = false, the left and right singular vectors will be empty.U,S,VandVtcan be obtained from the SVD object withZ.U,Z.S,Z.VandZ.Vt, whereZ = svds(A)[1]andU * Diagonal(S) * Vtis a low-rank approximation ofAwith ranknsv. InternallyVtis stored and henceVtis more efficient to extract thanV.nconv: Number of converged singular values.niter: Number of iterations.nmult: Number of matrix–vector products used.resid: Final residual vector.
Examples
julia> Random.seed!(123);
julia> A = Diagonal(1:5);
julia> Z = svds(A, nsv = 2)[1];
julia> Z.U
5×2 Array{Float64,2}:
0.0 7.80626e-18
0.0 -0.0
-1.33227e-16 5.35947e-33
-6.38552e-17 1.0
-1.0 -6.38552e-17
julia> Z.S
2-element Array{Float64,1}:
5.0
3.999999999999999
julia> Z.Vt
2×5 Array{Float64,2}:
-2.77556e-17 0.0 -2.22045e-16 -7.9819e-17 -1.0
3.1225e-17 1.89735e-19 0.0 1.0 -8.32667e-17
julia> Z.V
5×2 Adjoint{Float64,Array{Float64,2}}:
-2.77556e-17 3.1225e-17
0.0 1.89735e-19
-2.22045e-16 0.0
-7.9819e-17 1.0
-1.0 -8.32667e-17svds(A) is formally equivalent to calling eigs to perform implicitly restarted Lanczos tridiagonalization on the Hermitian matrix $A^\prime A$ or $AA^\prime$ such that the size is smallest.