iterative#

torchsim.iterative(solver=None, *, max_iter=50, tol=1e-6)[source]#

The inner solve, by a regularized linear least-squares routine.

A Gauss-Newton step leaves ||A d - b||^2 + (1/g) ||d - z||^2 once the damping and its reference are in it, and asks only for products with the Jacobian, so it does not care whether an encoding operator sits in front of the model. Any LeastSquares minimizes exactly that.

Parameters:
  • solver (LeastSquares, optional) –

    Anything matching LeastSquares. The default is deepinv’s least_squares, which is conjugate gradients. One of its others is that same function with the argument bound:

    from functools import partial
    from deepinv.optim.linear import least_squares
    
    iterative(partial(least_squares, solver="lsqr"))
    

    Which one suits depends on the problem and is worth measuring: conjugate gradients works on the normal equations, so on a small well-scaled system it stops on a tolerance the squared condition number has already spoiled, while LSQR and MINRES reach what a direct solve reaches – and on a large encoded problem inside a fixed iteration budget the ordering reverses.

  • max_iter (int, optional) – Most inner iterations per Gauss-Newton step.

  • tol (float, optional) – Stop when the residual has fallen this far relative to the data.

Returns:

An inner solve, to give GaussNewton as solve=.

Return type:

callable

Raises:

ImportError – If no solver is given and deepinv is not installed. TorchSim does not depend on it: pass a LeastSquares of your own, or use direct() where the model stands alone.

Examples using torchsim.iterative#

Nonlinear inversion from k-space

Nonlinear inversion from k-space