Linear solvers

The linear_solver argument of gauss_newton() (and least_squares()): how each damped normal-equations system is solved. See the sparse problems guide.

piazzi.dense_solver(H, g, damping)[source]

Solve the damped normal equations directly, with torch.linalg.solve().

The default piazzi.LinearSolver of piazzi.gauss_newton() for a dense H. A sparse H is densified first.

Parameters:
Returns:

Tensor – the step d of shape (n,) that solves (H + diag(damping)) d = -g.

piazzi.cg_solver(tol=1e-06, max_iter=500, preconditioner='jacobi')[source]

Make a preconditioned conjugate-gradient solver for large sparse normal equations.

The returned piazzi.LinearSolver is the default of piazzi.gauss_newton() for a sparse H. It uses CG from torchsparsegradutils, which needs the optional dependency (pip install "piazzi[sparse]"). H is only used through its diagonal and matrix-vector products, so it can be any sparse layout that H @ v supports. CG stops at a relative residual of tol or after max_iter iterations, without a warning: an inexact step is fine for Gauss-Newton and Levenberg-Marquardt, whose line search or gain ratio checks it. If CG breaks down (a numerically singular damped system), the solver returns the preconditioned gradient step -M^{-1} g instead, which is still a descent direction.

Parameters:
  • tol (float, optional) – relative residual at which CG stops; must be positive. Default: 1e-6

  • max_iter (int, optional) – maximum number of CG iterations per solve. Default: 500

  • preconditioner (str or Callable, optional) – "jacobi" divides by diag(H) + damping. A callable preconditioner(H, damping) returning v -> M^{-1} v supplies your own (for example block-Jacobi, inverting each parameter block’s diagonal block). None disables preconditioning. Default: "jacobi"

Returns:

LinearSolver – solver(H, g, damping) -> d, for the linear_solver argument of piazzi.gauss_newton().

piazzi.LinearSolver

Signature of a linear solver for gauss_newton(): solver(H, g, damping) -> d solves (H + diag(damping)) d = -g, with H of shape (n, n) (dense, or sparse COO or CSR) and g, damping and d of shape (n,).