laplax.curv.lanczos
lanczos_iterations ¶
lanczos_iterations(matvec: Callable[[Array], Array], b: Array, *, maxiter: int = 20, tol: Float = 1e-06, full_reorthogonalize: bool = True, dtype: DType = float64, mv_jit: bool = True) -> tuple[Array, Array, Array]
Runs Lanczos iterations starting from vector b
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matvec
|
Callable[[Array], Array]
|
A callable that computes |
required |
b
|
Array
|
Starting vector. |
required |
maxiter
|
int
|
Number of iterations. |
20
|
tol
|
Float
|
Tolerance to detect convergence. |
1e-06
|
full_reorthogonalize
|
bool
|
If True, reorthogonalize at every step. |
True
|
dtype
|
DType
|
Data type for the Lanczos scalars/vectors. |
float64
|
mv_jit
|
bool
|
If True, uses |
True
|
Returns:
Name | Type | Description |
---|---|---|
alpha |
Array
|
1D array of Lanczos scalars (diagonal of T). |
beta |
Array
|
1D array of off-diagonals (with beta[-1] not used). |
V |
Array
|
2D array (maxiter+1 x input_dim) of Lanczos vectors. |
Source code in laplax/curv/lanczos.py
construct_tridiagonal ¶
Constructs the symmetric tridiagonal matrix from Lanczos scalars.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha
|
Array
|
Diagonal elements. |
required |
beta
|
Array
|
Off-diagonal elements (only beta[:k-1] are used). |
required |
Returns:
Type | Description |
---|---|
Array
|
A \(k \times k\) symmetric tridiagonal matrix \(T\). |
Source code in laplax/curv/lanczos.py
compute_eigendecomposition ¶
compute_eigendecomposition(alpha: Array, beta: Array, V: Array, *, compute_vectors: bool = False) -> Array | tuple[Array, Array]
Computes the eigendecomposition of the tridiagonal matrix generated by Lanczos.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alpha
|
Array
|
Diagonal elements. |
required |
beta
|
Array
|
Off-diagonal elements. |
required |
V
|
Array
|
Lanczos vectors. |
required |
compute_vectors
|
bool
|
If True, compute Ritz vectors in the original space. |
False
|
Returns:
Type | Description |
---|---|
Array | tuple[Array, Array]
|
If compute_vectors is True: (eigvals, ritz_vectors), else: eigvals. |
Source code in laplax/curv/lanczos.py
lanczos_lowrank ¶
lanczos_lowrank(A: Callable[[Array], Array] | Array, *, key: KeyType | None = None, b: Array | None = None, layout: Layout | None = None, rank: int = 20, tol: float = 1e-06, mv_dtype: DType | None = None, calc_dtype: DType = float64, return_dtype: DType | None = None, mv_jit: bool = True, full_reorthogonalize: bool = True, **kwargs: Kwargs) -> LowRankTerms
Compute a low-rank approximation using the Lanczos algorithm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A
|
Callable[[Array], Array] | Array
|
Matrix or callable representing the matrix-vector product |
required |
key
|
KeyType | None
|
PRNG key for random initialization. Either |
None
|
b
|
Array | None
|
Starting vector. Either |
None
|
layout
|
Layout | None
|
Dimension of input vector (required if |
None
|
rank
|
int
|
Number of leading eigenpairs to compute. Defaults to \(R=20\). |
20
|
tol
|
float
|
Convergence tolerance for the algorithm. |
1e-06
|
mv_dtype
|
DType | None
|
Data type for matrix-vector products. Defaults to |
None
|
calc_dtype
|
DType
|
Data type for internal calculations. |
float64
|
return_dtype
|
DType | None
|
Data type for returned results. |
None
|
mv_jit
|
bool
|
If True, enables JIT compilation of matrix-vector products. Note that this can cause problems if the matrix-vector product generates a large computational graph. |
True
|
full_reorthogonalize
|
bool
|
Whether to perform full reorthogonalization. |
True
|
**kwargs
|
Kwargs
|
Additional arguments (ignored). |
{}
|
Returns:
Name | Type | Description |
---|---|---|
LowRankTerms |
LowRankTerms
|
A dataclass containing:
|
Raises:
Type | Description |
---|---|
ValueError
|
If neither key nor b is provided. |
Source code in laplax/curv/lanczos.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|