Singular Value Decomposition
Singular Value Decomposition for tall matrices
torchlinops.alg.svd
singular_value_decomposition
singular_value_decomposition(
A: Dense,
x_init: Tensor,
num_singular_values: int,
max_iters: int = 50,
tol: float = 1e-05,
eps: float = 0.0,
dim: Optional[int | Tuple[int, ...]] = None,
tqdm_kwargs: Optional[dict] = None,
) -> Tuple[Tensor, Tensor, Tensor]
Compute compact SVD of a "tall" linop using power method with deflation.
For a tall linear operator A (m x n with m >= n), computes the singular value decomposition A ≈ U @ diag(S) @ Vh using iterative deflation.
The algorithm:
- Compute A.N = A^H A (the normal operator)
- Find largest eigenvalue λ and eigenvector v of A.N via power iteration
- Singular value: σ = √λ
- Left singular vector: u = A(v) / σ
- Deflate: A.N ← A.N - σ² v v^H
- Note: v v^H = v.H.N
- Repeat for subsequent singular values
| PARAMETER | DESCRIPTION |
|---|---|
A
|
Tall linear operator with shape (m, n) where m >= n. Currently supports Dense linops for constructing deflation operators.
TYPE:
|
x_init
|
Initial vector for power iteration. Determines the input shape and dtype. For batched computation, includes batch dimensions.
TYPE:
|
num_singular_values
|
Number of singular values and vectors to compute.
TYPE:
|
max_iters
|
Maximum power iterations per singular value.
TYPE:
|
tol
|
Convergence tolerance for eigenvalue estimation.
TYPE:
|
eps
|
Small constant for numerical stability in normalization.
TYPE:
|
dim
|
Batch dimension(s) for batched power iteration.
TYPE:
|
tqdm_kwargs
|
Keyword arguments forwarded to tqdm progress bar.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
U
|
Left singular vectors. Shape: (*oshape, num_singular_values) where oshape is A's output shape.
TYPE:
|
S
|
Singular values in descending order. Shape: (num_singular_values,)
TYPE:
|
Vh
|
Conjugate transpose of right singular vectors. Shape: (num_singular_values, *ishape) where ishape is A's input shape.
TYPE:
|
Examples:
>>> A = Dense(torch.randn(10, 5), ("M", "N"), ("N",), ("M",))
>>> x_init = torch.randn(5)
>>> U, S, Vh = singular_value_decomposition(A, x_init, num_singular_values=3)
>>> # Verify: A @ x ≈ U @ diag(S) @ Vh @ x for reconstruction
Source code in src/torchlinops/alg/svd.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |