Solvers & Preconditioners¶
Layer 1.5: strategy objects that encapsulate how a solve or logdet is
computed, decoupled from what is being solved. Everything that accepts a
solver= keyword anywhere in gaussx takes one of these; None falls back to
structural dispatch on the operator.
A strategy bundles a solve and a logdet algorithm. Mix and match with
ComposedSolver — e.g. CG for the solve, stochastic
Lanczos quadrature for the logdet — which is the standard recipe for large
kernel matrices.
The front door¶
linear_solve is the high-level entry point: it accepts a lineax operator or
a bare (matvec, shape) pair, normalises negative-definite systems, picks a
sensible iterative solver from the operator's tags, and threads a
preconditioner through. as_linear_operator wraps a raw matvec callable into a
tagged FunctionLinearOperator for matrix-free workflows.
Structured linear algebra and Gaussian primitives for JAX.
linear_solve(operator: OperatorLike, vector: Float[Array, ' n'], *, solver: AbstractSolveStrategy | None = None, preconditioner: PreconditionerLike | None = None) -> Float[Array, ' n']
¶
Solve A x = b through the unified front door.
Accepts either a built operator or a (matvec, shape) pair, handles the
negative-definite sign convention, picks a default solver when none is
given, and optionally applies a preconditioner.
Sign handling: an operator tagged negative semidefinite (and not PSD) is
solved via the equivalent positive-definite system (-A) x = -b, so that
a CG-style solver can be used directly. This is the common case for elliptic
PDE operators (e.g. a discrete Laplacian), which finite-volume / spectral
callers hand over as negative-definite matvecs.
Default solver selection (when solver is None):
- positive semidefinite operator ->
CGSolver - symmetric (possibly indefinite) operator ->
MINRESSolver - otherwise -> a
ValueErrorasking for an explicit solver
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
OperatorLike
|
The linear operator |
required |
vector
|
Float[Array, ' n']
|
Right-hand side |
required |
solver
|
AbstractSolveStrategy | None
|
Solve strategy to use. When |
None
|
preconditioner
|
PreconditionerLike | None
|
Optional preconditioner. May be an
|
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, ' n']
|
The solution |
Source code in src/gaussx/_solve_frontend.py
as_linear_operator(matvec: MatvecLike, *, shape: tuple[int, int] | None = None, in_structure: object | None = None, dtype: object = float, symmetric: bool = False, positive_semidefinite: bool = False, negative_definite: bool = False) -> lx.AbstractLinearOperator
¶
Wrap a raw matvec callable as a tagged lineax operator.
This is the matrix-free front door: callers that only have a
v -> A @ v function (rather than a structured operator object) use this
to obtain an operator that gaussx's solvers and primitives understand.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matvec
|
MatvecLike
|
The matrix-vector product |
required |
shape
|
tuple[int, int] | None
|
Matrix shape |
None
|
in_structure
|
object | None
|
An explicit input structure -- either a
|
None
|
dtype
|
object
|
Dtype used when building the input structure from |
float
|
symmetric
|
bool
|
Tag the operator symmetric ( |
False
|
positive_semidefinite
|
bool
|
Tag the operator PSD (implies symmetric). |
False
|
negative_definite
|
bool
|
Tag the operator negative semidefinite (implies
symmetric). Use this for elliptic operators such as a discrete
Laplacian; |
False
|
Returns:
| Type | Description |
|---|---|
AbstractLinearOperator
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither |
Source code in src/gaussx/_solve_frontend.py
Abstract interfaces¶
Structured linear algebra and Gaussian primitives for JAX.
AbstractSolveStrategy
¶
Bases: Module
Protocol for linear solve strategies.
A solve strategy encapsulates the choice of algorithm for
solving A x = b. Separating solve from logdet lets
users mix-and-match via ComposedSolver.
Source code in src/gaussx/_strategies/_base.py
solve(operator: lx.AbstractLinearOperator, vector: Float[Array, ' n']) -> Float[Array, ' n']
abstractmethod
¶
Solve A x = b.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
Linear operator |
required |
vector
|
Float[Array, ' n']
|
Right-hand side |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, ' n']
|
Solution |
Source code in src/gaussx/_strategies/_base.py
AbstractLogdetStrategy
¶
Bases: Module
Protocol for log-determinant strategies.
A logdet strategy encapsulates the choice of algorithm for
computing log |det(A)|. Separating logdet from solve
lets users mix-and-match via ComposedSolver.
All implementations accept an optional key parameter for
stochastic methods. Deterministic strategies ignore it.
Source code in src/gaussx/_strategies/_base.py
logdet(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> Float[Array, '']
abstractmethod
¶
Compute log |det(A)|.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
Linear operator. |
required |
key
|
Array | None
|
Optional PRNG key for stochastic estimators. |
None
|
Source code in src/gaussx/_strategies/_base.py
AbstractSolverStrategy
¶
Bases: AbstractSolveStrategy, AbstractLogdetStrategy
Protocol for solver strategies that pair solve + logdet.
A solver strategy encapsulates the choice of algorithm for solving linear systems and computing log-determinants. This decouples distribution objects from solver implementation details.
Subclasses must implement both solve and logdet.
For independent control, see AbstractSolveStrategy and
AbstractLogdetStrategy, composable via
ComposedSolver.
Source code in src/gaussx/_strategies/_base.py
Direct & iterative solvers¶
Structured linear algebra and Gaussian primitives for JAX.
DenseSolver
¶
Bases: AbstractSolverStrategy
Dense solver strategy using gaussx structural dispatch.
Delegates to gaussx.solve and gaussx.logdet which
automatically select the best algorithm based on operator
structure (Diagonal, BlockDiag, Kronecker, LowRankUpdate,
or dense fallback via lineax).
Source code in src/gaussx/_strategies/_dense.py
solve(operator: lx.AbstractLinearOperator, vector: Float[Array, ' n']) -> Float[Array, ' n']
¶
Solve A x = b via structural dispatch (gaussx.solve).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
Linear operator |
required |
vector
|
Float[Array, ' n']
|
Right-hand side |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, ' n']
|
Solution |
Source code in src/gaussx/_strategies/_dense.py
logdet(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> Float[Array, '']
¶
Compute log|det(A)| via structural dispatch (gaussx.logdet).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
Linear operator |
required |
key
|
Array | None
|
Unused; present for protocol compatibility with stochastic estimators. |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar log-determinant. |
Source code in src/gaussx/_strategies/_dense.py
AutoSolver
¶
Bases: AbstractSolverStrategy
Automatic solver selection based on operator type and size.
Selection logic:
- Structured (Diagonal, BlockDiag, Kronecker, LowRankUpdate): DenseSolver (structural dispatch handles efficiency)
- Small dense (N <= size_threshold): DenseSolver
- Large PSD: CGSolver
- Large general: DenseSolver (fallback)
Attributes:
| Name | Type | Description |
|---|---|---|
size_threshold |
int
|
Matrix dimension above which iterative solvers are preferred. Default: 1000. |
Source code in src/gaussx/_strategies/_auto.py
solve(operator: lx.AbstractLinearOperator, vector: Float[Array, ' n']) -> Float[Array, ' n']
¶
Solve A x = b with automatically selected algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
The linear operator A. |
required |
vector
|
Float[Array, ' n']
|
The right-hand side b. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, ' n']
|
The solution x. |
Source code in src/gaussx/_strategies/_auto.py
logdet(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> Float[Array, '']
¶
Compute log |det(A)| with automatically selected algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
The linear operator A. |
required |
key
|
Array | None
|
Optional PRNG key (forwarded to stochastic strategies). |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar log |det(A)|. |
Source code in src/gaussx/_strategies/_auto.py
CGSolver
¶
Bases: AbstractSolverStrategy
Iterative CG solver with stochastic log-determinant.
Uses lineax CG for the linear solve and matfree's stochastic Lanczos quadrature (SLQ) for the log-determinant. Suitable for large PSD operators where dense factorization is too expensive.
Attributes:
| Name | Type | Description |
|---|---|---|
rtol |
float
|
Relative tolerance for CG. |
atol |
float
|
Absolute tolerance for CG. |
max_steps |
int
|
Maximum CG iterations. |
num_probes |
int
|
Number of probe vectors for stochastic logdet. |
lanczos_order |
int
|
Order of the Lanczos decomposition for SLQ. |
preconditioner |
AbstractPreconditioner | None
|
Optional preconditioner. When set, its approximate inverse is passed to lineax CG to accelerate convergence. |
Source code in src/gaussx/_strategies/_cg.py
solve(operator: lx.AbstractLinearOperator, vector: Float[Array, ' n']) -> Float[Array, ' n']
¶
Solve A x = b with conjugate gradients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A PSD linear operator |
required |
vector
|
Float[Array, ' n']
|
Right-hand side |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, ' n']
|
Solution |
Source code in src/gaussx/_strategies/_cg.py
logdet(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> Float[Array, '']
¶
Stochastic log-determinant via Lanczos quadrature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A PSD linear operator. |
required |
key
|
Array | None
|
PRNG key for probe vector sampling. If None,
uses |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar estimate of log |det(A)|. |
Source code in src/gaussx/_strategies/_cg.py
PreconditionedCGSolver
¶
Bases: AbstractSolverStrategy
CG solver with pivoted partial Cholesky preconditioner.
Uses matfree's low_rank.cholesky_partial_pivot to build a
rank-k preconditioner, then solves (sI + LL^T)^{-1} v via
the Woodbury identity inside lineax CG.
For operators of the form K + sigma^2 I, preconditioning
dramatically reduces the number of CG iterations.
Attributes:
| Name | Type | Description |
|---|---|---|
preconditioner_rank |
int
|
Rank of the partial Cholesky. Set to 0 to disable preconditioning (falls back to plain CG). |
shift |
float
|
Diagonal shift |
rtol |
float
|
Relative tolerance for CG. |
atol |
float
|
Absolute tolerance for CG. |
max_steps |
int
|
Maximum CG iterations. |
num_probes |
int
|
Number of probe vectors for stochastic logdet. |
lanczos_order |
int
|
Lanczos iterations for SLQ logdet. |
seed |
int
|
Seed for probe vector generation. |
Source code in src/gaussx/_strategies/_precond_cg.py
solve(operator: lx.AbstractLinearOperator, vector: Float[Array, ' n']) -> Float[Array, ' n']
¶
Solve A x = b via preconditioned CG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A PSD linear operator. |
required |
vector
|
Float[Array, ' n']
|
The right-hand side b. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, ' n']
|
The solution x. |
Source code in src/gaussx/_strategies/_precond_cg.py
logdet(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> Float[Array, '']
¶
Stochastic log-determinant via Lanczos quadrature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A PSD linear operator. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar estimate of log |det(A)|. |
Source code in src/gaussx/_strategies/_precond_cg.py
MINRESSolver
¶
Bases: AbstractSolverStrategy
MINRES solver for symmetric (possibly indefinite) systems.
Uses the Lanczos-based MINRES algorithm for the linear solve and matfree's stochastic Lanczos quadrature (SLQ) for the log-determinant. Unlike CG, MINRES only requires symmetry — it works on indefinite and singular systems.
Use cases: EP natural parameters, saddle-point systems, Laplace approximation Hessians.
Attributes:
| Name | Type | Description |
|---|---|---|
rtol |
float
|
Relative tolerance for MINRES. |
atol |
float
|
Absolute tolerance for MINRES. |
max_steps |
int
|
Maximum MINRES iterations. |
shift |
float
|
Diagonal shift — solves |
num_probes |
int
|
Number of probe vectors for stochastic logdet. |
lanczos_order |
int
|
Order of the Lanczos decomposition for SLQ. |
Source code in src/gaussx/_strategies/_minres.py
solve(operator: lx.AbstractLinearOperator, vector: Float[Array, ' n']) -> Float[Array, ' n']
¶
Solve (A + shift I) x = b with MINRES.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A symmetric (possibly indefinite) linear operator |
required |
vector
|
Float[Array, ' n']
|
Right-hand side |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, ' n']
|
Solution |
Source code in src/gaussx/_strategies/_minres.py
logdet(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> Float[Array, '']
¶
Stochastic log|det(A + shift I)| via Lanczos quadrature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A symmetric linear operator. |
required |
key
|
Array | None
|
PRNG key for probe vector sampling. If None,
uses |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar estimate of |
Source code in src/gaussx/_strategies/_minres.py
LSMRSolver
¶
Bases: AbstractSolverStrategy
LSMR iterative least-squares solver (Fong & Saunders 2011).
Matrix-free solver that only requires matvec and transpose-matvec.
Supports Tikhonov regularization via damp parameter:
minimizes ||Ax - b||^2 + damp^2 ||x||^2.
Suitable for rectangular, ill-conditioned, or regularized systems.
The undamped path delegates to lineax.LSMR (with lineax's
implicit-differentiation rules). lineax's LSMR has no Tikhonov
damp parameter, so damped solves use matfree's LSMR, which has
a custom VJP for memory-efficient backpropagation.
Attributes:
| Name | Type | Description |
|---|---|---|
atol |
float
|
Absolute tolerance. |
btol |
float
|
Relative tolerance on the residual. |
ctol |
float
|
Condition number tolerance (the lineax path uses
|
maxiter |
int
|
Maximum iterations. |
damp |
float
|
Tikhonov damping parameter. |
num_probes |
int
|
Number of probe vectors for stochastic logdet. |
lanczos_order |
int
|
Lanczos iterations for SLQ logdet. |
seed |
int
|
Seed for probe vector generation. |
Source code in src/gaussx/_strategies/_lsmr.py
solve(operator: lx.AbstractLinearOperator, vector: Float[Array, ' m']) -> Float[Array, ' n']
¶
Solve A x = b via LSMR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A linear operator (may be rectangular). |
required |
vector
|
Float[Array, ' m']
|
The right-hand side b. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, ' n']
|
The (least-squares) solution x. |
Source code in src/gaussx/_strategies/_lsmr.py
logdet(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> Float[Array, '']
¶
Stochastic log-determinant via Lanczos quadrature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A PSD linear operator. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar estimate of log |det(A)|. |
Source code in src/gaussx/_strategies/_lsmr.py
BBMMSolver
¶
Bases: AbstractSolverStrategy
Black-Box Matrix-Matrix solver (Gardner et al. 2018).
Simultaneously solves multiple RHS and computes logdet via modified batched CG (mBCG). Amortizes matvecs across solve and logdet.
Solve: CG via lineax on each RHS column. Logdet: Stochastic Lanczos Quadrature via matfree.
Probe vectors are generated at construction time from seed
and stored as frozen state. This makes logdet and
solve_and_logdet deterministic functions of the operator —
no PRNG key is needed at call time.
Attributes:
| Name | Type | Description |
|---|---|---|
cg_max_iter |
int
|
Maximum CG iterations. |
cg_tolerance |
float
|
Relative tolerance for CG. |
lanczos_iter |
int
|
Lanczos iterations for SLQ. |
num_probes |
int
|
Number of probe vectors for Hutchinson. |
seed |
int
|
Seed for probe vector generation. |
Source code in src/gaussx/_strategies/_bbmm.py
solve(operator: lx.AbstractLinearOperator, vector: Float[Array, ' n']) -> Float[Array, ' n']
¶
Solve A x = b via CG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A PSD linear operator. |
required |
vector
|
Float[Array, ' n']
|
The right-hand side b. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, ' n']
|
The solution x. |
Source code in src/gaussx/_strategies/_bbmm.py
logdet(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> Float[Array, '']
¶
Stochastic log-determinant via Lanczos quadrature.
Probe vectors are generated deterministically from self.seed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A PSD linear operator. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar estimate of log |det(A)|. |
Source code in src/gaussx/_strategies/_bbmm.py
solve_and_logdet(operator: lx.AbstractLinearOperator, vector: Float[Array, ' n']) -> tuple[Float[Array, ' n'], Float[Array, '']]
¶
Joint solve + logdet.
Computes both solve(A, b) and logdet(A) sharing the operator's matvec calls where possible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A PSD linear operator. |
required |
vector
|
Float[Array, ' n']
|
The right-hand side b. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Float[Array, ' n'], Float[Array, '']]
|
Tuple of (solution, log_determinant). |
Source code in src/gaussx/_strategies/_bbmm.py
ComposedSolver
¶
Bases: AbstractSolverStrategy
Mix-and-match solve and logdet from different strategies.
This lets you pair, e.g., an exact dense solve with a stochastic log-determinant estimator, or an iterative CG solve with a closed-form Kronecker log-determinant.
Accepts either fine-grained protocols (AbstractSolveStrategy,
AbstractLogdetStrategy) or full solver strategies.
Attributes:
| Name | Type | Description |
|---|---|---|
solve_strategy |
AbstractSolveStrategy
|
Strategy whose |
logdet_strategy |
AbstractLogdetStrategy
|
Strategy whose |
Examples:
solver = ComposedSolver(
solve_strategy=DenseSolver(),
logdet_strategy=SLQLogdet(num_probes=50, lanczos_order=30),
)
Source code in src/gaussx/_strategies/_composed.py
solve(operator: lx.AbstractLinearOperator, vector: Float[Array, ' n']) -> Float[Array, ' n']
¶
Solve A x = b by delegating to solve_strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
Linear operator |
required |
vector
|
Float[Array, ' n']
|
Right-hand side |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, ' n']
|
Solution |
Source code in src/gaussx/_strategies/_composed.py
logdet(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> Float[Array, '']
¶
Compute log|det(A)| by delegating to logdet_strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
Linear operator |
required |
key
|
Array | None
|
Optional PRNG key forwarded to stochastic estimators. |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar log-determinant. |
Source code in src/gaussx/_strategies/_composed.py
Logdet strategies¶
Dense eigendecomposition for exactness; stochastic Lanczos quadrature (SLQ) for \(O(n^2 \cdot \text{rank})\) estimates on large PSD (or symmetric-indefinite) operators.
Structured linear algebra and Gaussian primitives for JAX.
DenseLogdet
¶
Bases: AbstractLogdetStrategy
Dense log-determinant via gaussx structural dispatch.
Delegates to gaussx.logdet which automatically selects
the best algorithm based on operator structure (Diagonal,
BlockDiag, Kronecker, LowRankUpdate, or dense fallback).
Source code in src/gaussx/_strategies/_slq_logdet.py
logdet(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> Float[Array, '']
¶
Compute log |det(A)| via structural dispatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A linear operator. |
required |
key
|
Array | None
|
Ignored (deterministic). |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar |
Source code in src/gaussx/_strategies/_slq_logdet.py
SLQLogdet
¶
Bases: AbstractLogdetStrategy
Stochastic log-determinant via Lanczos quadrature (SLQ).
Estimates log det(A) for PSD operators using stochastic
trace estimation: logdet(A) = tr(log(A)). Uses matfree's
Lanczos decomposition with sign-flip ("Rademacher") probe vectors
by default.
Attributes:
| Name | Type | Description |
|---|---|---|
num_probes |
int
|
Number of probe vectors for Hutchinson estimator. |
lanczos_order |
int
|
Order of the Lanczos decomposition. |
seed |
int
|
Seed for probe vector generation (used when no
|
sampler |
SamplerName
|
Probe distribution ( |
Source code in src/gaussx/_strategies/_slq_logdet.py
logdet(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> Float[Array, '']
¶
Stochastic log det(A) via Lanczos quadrature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A PSD linear operator. |
required |
key
|
Array | None
|
PRNG key for probe vector sampling. If |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar estimate of |
Source code in src/gaussx/_strategies/_slq_logdet.py
logdet_and_error(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> tuple[Float[Array, ''], Float[Array, '']]
¶
Stochastic log det(A) with its standard error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A PSD linear operator. |
required |
key
|
Array | None
|
PRNG key for probe vector sampling. If |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Tuple |
Float[Array, '']
|
error is the standard error of the mean across probes. |
Source code in src/gaussx/_strategies/_slq_logdet.py
IndefiniteSLQLogdet
¶
Bases: AbstractLogdetStrategy
Stochastic log|det(A)| for symmetric (possibly indefinite) operators.
Like SLQLogdet but uses log(|lambda|) as the matrix
function, so it works on indefinite and negative-definite matrices.
Supports a diagonal shift (A + shift * I).
Attributes:
| Name | Type | Description |
|---|---|---|
num_probes |
int
|
Number of probe vectors for Hutchinson estimator. |
lanczos_order |
int
|
Order of the Lanczos decomposition. |
shift |
float
|
Diagonal shift applied before computing the logdet. |
seed |
int
|
Seed for probe vector generation. |
sampler |
SamplerName
|
Probe distribution ( |
Source code in src/gaussx/_strategies/_slq_logdet.py
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 191 192 193 194 195 196 197 198 | |
logdet(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> Float[Array, '']
¶
Stochastic log|det(A + shift I)| via Lanczos quadrature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A symmetric linear operator. |
required |
key
|
Array | None
|
PRNG key for probe vector sampling. If |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar estimate of |
Source code in src/gaussx/_strategies/_slq_logdet.py
logdet_and_error(operator: lx.AbstractLinearOperator, *, key: jax.Array | None = None) -> tuple[Float[Array, ''], Float[Array, '']]
¶
Stochastic log|det(A + shift I)| with its standard error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A symmetric linear operator. |
required |
key
|
Array | None
|
PRNG key for probe vector sampling. If |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Float[Array, ''], Float[Array, '']]
|
Tuple |
Source code in src/gaussx/_strategies/_slq_logdet.py
Preconditioners¶
Approximate inverses \(M^{-1} \approx A^{-1}\) that accelerate the iterative
solvers above. Pass them via the preconditioner= argument of
linear_solve, CGSolver, or
PreconditionedCGSolver.
Structured linear algebra and Gaussian primitives for JAX.
AbstractPreconditioner
¶
Bases: Module
Protocol for preconditioners producing an approximate inverse.
Subclasses implement as_operator, returning a PSD lineax operator
that applies M^{-1} (or None to disable preconditioning).
Source code in src/gaussx/_preconditioners/_base.py
as_operator(operator: lx.AbstractLinearOperator | None = None) -> lx.AbstractLinearOperator | None
abstractmethod
¶
Return M^{-1} as a PSD lineax operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator | None
|
The system operator |
None
|
Returns:
| Type | Description |
|---|---|
AbstractLinearOperator | None
|
A positive-semidefinite operator applying |
AbstractLinearOperator | None
|
indicate that no preconditioning should be applied. |
Source code in src/gaussx/_preconditioners/_base.py
JacobiPreconditioner
¶
Bases: AbstractPreconditioner
Diagonal preconditioner M^{-1} = diag(1 / diag(A)).
The cheapest preconditioner: scales each coordinate by the reciprocal of
the corresponding diagonal entry of A. Effective when A is
diagonally dominant.
Attributes:
| Name | Type | Description |
|---|---|---|
diagonal |
Float[Array, ' n'] | None
|
The diagonal of |
Source code in src/gaussx/_preconditioners/_jacobi.py
as_operator(operator: lx.AbstractLinearOperator | None = None) -> lx.AbstractLinearOperator
¶
Return diag(1 / d) as a PSD operator.
Source code in src/gaussx/_preconditioners/_jacobi.py
OperatorPreconditioner
¶
Bases: AbstractPreconditioner
Use an externally supplied approximate inverse as a preconditioner.
Attributes:
| Name | Type | Description |
|---|---|---|
approx_inverse |
AbstractLinearOperator | Callable
|
The approximate inverse |
in_structure |
object
|
Input structure for the callable form. When |
Source code in src/gaussx/_preconditioners/_operator.py
as_operator(operator: lx.AbstractLinearOperator | None = None) -> lx.AbstractLinearOperator
¶
Return the approximate inverse as a PSD lineax operator.
Source code in src/gaussx/_preconditioners/_operator.py
NystromPreconditioner
¶
Bases: AbstractPreconditioner
Low-rank approximate inverse from randomized operator probing.
Builds a rank-k Nyström approximation of a symmetric positive
semidefinite operator A and uses it as an approximate inverse. Good when
A is available only through matvecs and a handful of probes captures its
dominant spectrum.
Algorithm (for PSD A):
- Draw a Gaussian probe matrix
Omega in R^{n x k}and orthonormalise it via QR to getQ. - Form
Y = A Q(kmatvecs) and the small matrixB = Q^T Y. - Eigendecompose
B = U S U^Tand setW = Q U(orthonormal columns). - The approximate inverse is
M^{-1} x = a x + W ((s_inv - a) (W^T x)), wheres_inv = 1 / |eig(B)|and the scalar fallbackakeeps directions outside the captured subspace near the inverse of the smallest captured eigenvalue (so CG does not falsely converge in the preconditioned norm).
Construct via from_operator.
Attributes:
| Name | Type | Description |
|---|---|---|
basis |
Float[Array, 'n k']
|
Orthonormal basis |
scale |
Float[Array, ' k']
|
Per-direction extra scaling |
shift |
Float[Array, '']
|
Scalar fallback |
Source code in src/gaussx/_preconditioners/_nystrom.py
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 | |
from_operator(operator: lx.AbstractLinearOperator, rank: int = 50, key: jax.Array | None = None) -> NystromPreconditioner
classmethod
¶
Build a Nyström preconditioner by probing operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operator
|
AbstractLinearOperator
|
A symmetric PSD operator |
required |
rank
|
int
|
Number of probe vectors (approximation rank). |
50
|
key
|
Array | None
|
PRNG key for the probe matrix. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
NystromPreconditioner
|
A ready-to-use |
Source code in src/gaussx/_preconditioners/_nystrom.py
as_operator(operator: lx.AbstractLinearOperator | None = None) -> lx.AbstractLinearOperator
¶
Return the rank-k approximate inverse as a PSD operator.
Source code in src/gaussx/_preconditioners/_nystrom.py
PartialCholeskyPreconditioner
¶
Bases: AbstractPreconditioner
Preconditioner from a pivoted partial Cholesky factor.
Builds a rank-k partial Cholesky factor L of the system operator via
matfree, then applies (s I + L L^T)^{-1} through the Woodbury identity.
For operators of the form K + sigma^2 I this dramatically reduces CG
iteration counts.
Attributes:
| Name | Type | Description |
|---|---|---|
rank |
int
|
Rank of the partial Cholesky. |
shift |
float
|
Diagonal shift |
Source code in src/gaussx/_preconditioners/_partial_cholesky.py
as_operator(operator: lx.AbstractLinearOperator | None = None) -> lx.AbstractLinearOperator | None
¶
Build the Woodbury preconditioner operator from operator.