Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Solver Strategy Comparison

gaussx provides two solver strategies that pair solve + logdet:

  • DenseSolver — structural dispatch (Cholesky for PSD, etc.)
  • CGSolver — iterative CG solve + stochastic Lanczos logdet

This notebook compares them on the same problem.

For small-to-medium problems (N≲5000N \lesssim 5000), direct factorization (Cholesky for PSD systems) is optimal: O(N3/3)O(N^3/3) flops with machine-precision accuracy. For larger problems, iterative methods like conjugate gradients (CG) achieve useful accuracy in far fewer flops, especially when the matrix is well-conditioned or a good preconditioner is available.

Setup: PSD kernel matrix

Problem size: 50x50

DenseSolver

DenseSolver:
  solve residual: 1.09e-14
  logdet: -91.659733

CGSolver

The CGSolver pairs conjugate gradients for the linear solve with stochastic Lanczos quadrature (SLQ) for the log-determinant. SLQ exploits the identity log⁡∣A∣=tr⁡(log⁡A)\log|A| = \operatorname{tr}(\log A) and then uses Hutchinson’s trace estimator: draw random probe vectors zz and approximate tr⁡(log⁡A)≈1P∑p=1Pzp⊤log⁡(A) zp\operatorname{tr}(\log A) \approx \frac{1}{P}\sum_{p=1}^P z_p^\top \log(A)\, z_p. Each quadratic form z⊤log⁡(A) zz^\top \log(A)\, z is evaluated via a short Lanczos decomposition, which produces a tridiagonal matrix whose eigenvalues give accurate Gauss quadrature nodes for the spectral integral. See Ubaru et al. (2017) for convergence analysis.

CGSolver:
  solve residual: 3.51e-09
  logdet: -90.873256

Comparison

Solve difference: 3.41e-09
Logdet difference: 0.7865

True logdet:    -91.659733
Dense logdet:   -91.659733  (error: 0.00e+00)
CG logdet:      -90.873256  (error: 0.7865)
<Figure size 1200x400 with 2 Axes>

When to use which

StrategyBest forSolveLogdet
DenseSolverSmall-medium, structuredExact (structural dispatch)Exact
CGSolverLarge PSD, matrix-freeIterativeStochastic

The DenseSolver is exact and exploits gaussx structural dispatch (Kronecker, BlockDiag, LowRank, Diagonal fast paths). The CGSolver works for any PSD operator, even matrix-free ones where as_matrix() is unavailable, but the logdet is approximate.

The crossover point depends on hardware (GPU memory, FLOP throughput) and matrix conditioning. On modern GPUs, Cholesky can handle N∼10,000N \sim 10{,}000--50,00050{,}000; beyond that, CG-based methods become necessary.

References

  • Golub, G. H. & Van Loan, C. F. (2013). Matrix Computations. 4th edition, Johns Hopkins University Press.
  • Ubaru, S., Chen, J., & Saad, Y. (2017). Fast estimation of tr⁡(f(A))\operatorname{tr}(f(A)) via stochastic Lanczos quadrature. SIAM J. Matrix Analysis, 38(4), 1075--1099.
  • Hestenes, M. R. & Stiefel, E. (1952). Methods of conjugate gradients for solving linear systems. Journal of Research of the National Bureau of Standards, 49(6), 409--436.