Algorithms¶
Top-k eigenpairs¶
lanczos(operator, *, k=10, max_iter=None, tol=0.0001, reorthogonalize=None, which='LM', seed=None, backend=None)
¶
Compute top-k eigenpairs by symmetric Lanczos + tridiagonal eigendecomposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
CurvatureOperator
|
symmetric curvature operator providing matvec. |
required |
k
|
int
|
number of Ritz pairs to return. |
10
|
max_iter
|
int | None
|
number of Lanczos steps. Defaults to |
None
|
tol
|
float
|
convergence tolerance for Ritz residuals ( |
0.0001
|
reorthogonalize
|
bool | None
|
if True, full Gram-Schmidt against all prior basis vectors
after each step. None (default) selects True for |
None
|
which
|
Which
|
'LM' largest magnitude, 'LA' largest algebraic, 'SA' smallest algebraic. |
'LM'
|
seed
|
int | None
|
seed for the initial random vector. |
None
|
backend
|
LinAlgBackend[Tensor] | None
|
vector-arithmetic backend. |
None
|
Source code in hessian_eigenthings/algorithms/lanczos.py
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 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 | |
lanczos_tridiagonal(operator, v0, max_iter, *, reorthogonalize=True, backend=None)
¶
Run max_iter Lanczos steps from v0 and return the tridiagonal + basis.
Public so SLQ and other quadrature consumers can reuse the same Lanczos kernel.
Source code in hessian_eigenthings/algorithms/lanczos.py
LanczosTridiag
dataclass
¶
Output of one Lanczos run: tridiagonal coefficients + the basis used to build them.
Source code in hessian_eigenthings/algorithms/lanczos.py
deflated_power_iteration(operator, *, k=10, max_iter=100, tol=0.0001, momentum=0.0, seed=None, backend=None)
¶
Top-k eigenpairs by repeatedly computing the dominant eigenpair and deflating it out.
After finding (λ_i, v_i), the operator is replaced with A - sum_i λ_i v_i v_i^T
so the next iteration can find the next-largest eigenpair.
Source code in hessian_eigenthings/algorithms/power_iteration.py
power_iteration_one(operator, *, max_iter=100, tol=0.0001, momentum=0.0, init=None, seed=None, backend=None)
¶
Compute the dominant eigenpair via power iteration with optional Polyak momentum.
Returns (eigenvalue, eigenvector, residual_norm, iterations, converged).
Source code in hessian_eigenthings/algorithms/power_iteration.py
Trace estimation¶
trace(operator, *, num_matvecs=100, method='hutch++', distribution='rademacher', seed=None, backend=None)
¶
Stochastic estimate of tr(A) using num_matvecs matrix-vector products.
Source code in hessian_eigenthings/algorithms/trace.py
hutchinson(operator, *, num_samples=100, distribution='rademacher', seed=None, backend=None)
¶
Hutchinson's (1/m) Σ vᵢᵀ A vᵢ estimator. Rademacher gives lower variance for trace.
Source code in hessian_eigenthings/algorithms/trace.py
hutch_plus_plus(operator, *, num_matvecs=99, seed=None, backend=None)
¶
Hutch++ (Meyer et al. 2021): low-rank sketch + residual Hutchinson.
Splits the matvec budget into thirds: m/3 for AS (the sketch), m/3 for AQ
(exact trace on the projected component), and m/3 for A G_perp (Hutchinson on
the orthogonal complement). Achieves O(1/ε) total matvecs vs Hutchinson's O(1/ε²)
for (1±ε)·tr(A) accuracy on PSD matrices.
Source code in hessian_eigenthings/algorithms/trace.py
Spectral density¶
spectral_density(operator, *, num_runs=10, lanczos_steps=80, num_grid_points=10000, sigma=None, grid_padding=0.1, seed=None, backend=None)
¶
Estimate the eigenvalue density of a symmetric operator via Stochastic Lanczos Quadrature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
CurvatureOperator
|
symmetric curvature operator. |
required |
num_runs
|
int
|
number of independent Lanczos runs (n_v in the paper). 10 is a reasonable default; larger reduces Monte-Carlo noise. |
10
|
lanczos_steps
|
int
|
Lanczos steps per run (m in the paper). 80-100 is typical; larger improves spectral resolution but costs more matvecs per run. |
80
|
num_grid_points
|
int
|
density evaluated on a regular grid this size. |
10000
|
sigma
|
float | None
|
Gaussian smoothing bandwidth. If None, defaults to
|
None
|
grid_padding
|
float
|
fraction of spectrum range padded on each side of the grid. |
0.1
|
seed
|
int | None
|
base seed; per-run init vectors use seed + run_idx. |
None
|
backend
|
LinAlgBackend[Tensor] | None
|
vector-arithmetic backend. |
None
|
Source code in hessian_eigenthings/algorithms/spectral_density.py
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 | |
Result types¶
EigenResult
dataclass
¶
Top-k eigenpairs of a symmetric operator, sorted in the order requested by the algorithm.
Source code in hessian_eigenthings/algorithms/result.py
TraceResult
dataclass
¶
Stochastic estimate of tr(A) together with its sample-standard-error.
Source code in hessian_eigenthings/algorithms/trace.py
SpectralDensityResult
dataclass
¶
Smoothed eigenvalue density φ(t) on a regular grid, plus the raw quadrature data.