bayespecon._logdet.traceax_traces¶
-
bayespecon._logdet.traceax_traces(W_sparse, order, k, estimator=
'hutchpp', seed=0)[source]¶ Estimate tr(W^k) for k=1..order via variance-reduced stochastic trace estimation.
Uses pure-NumPy batched matmuls with scipy CSR matrices, matching the speed of
_barry_pace_traces()while achieving lower variance via the Hutch++ correction.- Parameters:¶
- W_sparse : scipy.sparse.csr_matrix¶
Row-standardised n×n spatial weights matrix.
- order : int¶
Maximum trace power to estimate.
- k : int¶
Number of matrix-vector products (probes) per trace estimate. Clamped to
nif larger (QR constraint).- estimator=
'hutchpp'¶ Estimator to use:
"hutchpp","xtrace", or"hutchinson".- seed : int, default 0¶
NumPy random seed for reproducibility.
- Returns:¶
Mean trace estimates:
traces[i] ≈ tr(W^{i+1}). Entries 0 and 1 are overridden with exact values (tr(W)andtr(W²)), matching the convention of_barry_pace_traces().- Return type:¶
np.ndarray, shape (order,)
Notes
The variance-reduced Hutch++ estimator provides lower variance than the basic Hutchinson (Girard) estimator by splitting probes into a low-rank approximation (k//3) and a residual trace, reducing variance for matrices with decaying eigenvalue spectra (typical of spatial weights matrices).
The XTrace estimator (Epperly–Tropp–Webber 2024) refines Hutch++ via a leave-one-out construction that reuses every probe for both the low-rank basis and the residual estimate, at roughly 2× the matvec cost of Hutch++.
For spatial weights matrices with a few dominant eigenvalues (common for row-standardised contiguity weights), Hutch++ can achieve the same accuracy as Hutchinson with 2–5× fewer probes.
- Raises:¶
ValueError – If
estimatoris not one of the supported values.