(16) -> )jlDoc svd
)jlDoc svd
svd(A; full::Bool = false, alg::Algorithm = default_svd_alg(A)) -> SVD
Compute the singular value decomposition (SVD) of A and return an SVD
object.
U, S, V and Vt can be obtained from the factorization F with F.U, F.S, F.V
and F.Vt, such that A = U * Diagonal(S) * Vt. The algorithm produces Vt and
hence Vt is more efficient to extract than V. The singular values in S are
sorted in descending order.
Iterating the decomposition produces the components U, S, and V.
If full = false (default), a "thin" SVD is returned. For an M \times N
matrix A, in the full factorization U is M \times M and V is N \times N,
while in the thin factorization U is M \times K and V is N \times K, where K
= \min(M,N) is the number of singular values.
If alg = DivideAndConquer() a divide-and-conquer algorithm is used to
calculate the SVD. Another (typically slower but more accurate) option is
alg = QRIteration().
│ Julia 1.3
│
│ The alg keyword argument requires Julia 1.3 or later.
Examples
≡≡≡≡≡≡≡≡
julia> A = rand(4,3);
julia> F = svd(A); # Store the Factorization Object
julia> A ≈ F.U * Diagonal(F.S) * F.Vt
true
julia> U, S, V = F; # destructuring via iteration
julia> A ≈ U * Diagonal(S) * V'
true
julia> Uonly, = svd(A); # Store U only
julia> Uonly == U
true
svd(A, B) -> GeneralizedSVD
Compute the generalized SVD of A and B, returning a GeneralizedSVD
factorization object F such that [A;B] = [F.U * F.D1; F.V * F.D2] * F.R0 *
F.Q'
• U is a M-by-M orthogonal matrix,
• V is a P-by-P orthogonal matrix,
• Q is a N-by-N orthogonal matrix,
• D1 is a M-by-(K+L) diagonal matrix with 1s in the first K entries,
• D2 is a P-by-(K+L) matrix whose top right L-by-L block is
diagonal,
• R0 is a (K+L)-by-N matrix whose rightmost (K+L)-by-(K+L) block is
nonsingular upper block triangular,
K+L is the effective numerical rank of the matrix [A; B].
Iterating the decomposition produces the components U, V, Q, D1, D2, and R0.
The generalized SVD is used in applications such as when one wants to
compare how much belongs to A vs. how much belongs to B, as in human vs
yeast genome, or signal vs noise, or between clusters vs within clusters.
(See Edelman and Wang
for discussion: https:
//arxiv.org/abs
/1901.00485)
It decomposes [A; B] into [UC; VS]H, where [UC; VS] is a natural orthogonal
basis for the column space of [A; B], and H = RQ' is a natural
non-orthogonal basis for the rowspace of [A;B], where the top rows are most
closely attributed to the A matrix, and the bottom to the B matrix. The
multi-cosine/sine matrices C and S provide a multi-measure of how much A vs
how much B, and U and V provide directions in which these are measured.
Examples
≡≡≡≡≡≡≡≡
julia> A = randn(3,2); B=randn(4,2);
julia> F = svd(A, B);
julia> U,V,Q,C,S,R = F;
julia> H = R*Q';
julia> [A; B] ≈ [U*C; V*S]*H
true
julia> [A; B] ≈ [F.U*F.D1; F.V*F.D2]*F.R0*F.Q'
true
julia> Uonly, = svd(A,B);
julia> U == Uonly
true
- Greg