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.LinearSolverofpiazzi.gauss_newton()for a denseH. A sparseHis densified first.- Parameters:
H (
torch.Tensor) – curvature model of shape(n, n), dense or sparse.g (
torch.Tensor) – gradient of shape(n,).damping (
torch.Tensor) – diagonal damping of shape(n,).
- Returns:
Tensor – the step
dof 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.LinearSolveris the default ofpiazzi.gauss_newton()for a sparseH. It uses CG from torchsparsegradutils, which needs the optional dependency (pip install "piazzi[sparse]").His only used through its diagonal and matrix-vector products, so it can be any sparse layout thatH @ vsupports. CG stops at a relative residual oftolor aftermax_iteriterations, 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} ginstead, which is still a descent direction.- Parameters:
tol (
float, optional) – relative residual at which CG stops; must be positive. Default:1e-6max_iter (
int, optional) – maximum number of CG iterations per solve. Default:500preconditioner (
strorCallable, optional) –"jacobi"divides bydiag(H) + damping. A callablepreconditioner(H, damping)returningv -> M^{-1} vsupplies your own (for example block-Jacobi, inverting each parameter block’s diagonal block).Nonedisables preconditioning. Default:"jacobi"
- Returns:
LinearSolver –
solver(H, g, damping) -> d, for thelinear_solverargument ofpiazzi.gauss_newton().
- piazzi.LinearSolver¶
Signature of a linear solver for
gauss_newton():solver(H, g, damping) -> dsolves(H + diag(damping)) d = -g, withHof shape(n, n)(dense, or sparse COO or CSR) andg,dampinganddof shape(n,).