zea.inverse.solversΒΆ

Matrix-free linear-algebra utilities for inverse ultrasound problems.

This module provides the solver primitives used by zea.inverse:

  • linear_adjoint() β€” build the adjoint (transpose) of a linear operator with backend-agnostic automatic differentiation.

  • cgls() β€” conjugate gradient least squares for matrix-free linear operators.

Operators are plain callables on tensors of any shape; inner products are taken over all elements, so no explicit flattening or matrix assembly is required.

Functions

cgls(matvec, rmatvec, b, x0[, n_iter, verbose])

Conjugate gradient least squares (CGLS).

linear_adjoint(matvec, input_template)

Construct the adjoint of a linear operator via automatic differentiation.

zea.inverse.solvers.cgls(matvec, rmatvec, b, x0, n_iter=50, verbose=False)[source]ΒΆ

Conjugate gradient least squares (CGLS).

Iteratively minimizes \(\|A x - b\|^2\) for a matrix-free linear operator \(A\) given by matvec and its adjoint rmatvec. Started from zero on an underdetermined system, CGLS converges to the minimum-norm least-squares (Moore-Penrose pseudo-inverse) solution.

Parameters:
  • matvec (callable) – The linear operator \(A\).

  • rmatvec (callable) – The adjoint operator \(A^T\) (see linear_adjoint()).

  • b (Tensor) – Measurement, shaped like the output of matvec.

  • x0 (Tensor) – Initial iterate, shaped like the input of matvec. Use zeros for the minimum-norm solution.

  • n_iter (int, optional) – Number of iterations. Defaults to 50.

  • verbose (bool, optional) – Log the relative residual periodically. Defaults to False.

Returns:

The solution estimate with the shape of x0.

Return type:

Tensor

zea.inverse.solvers.linear_adjoint(matvec, input_template)[source]ΒΆ

Construct the adjoint of a linear operator via automatic differentiation.

For a linear operator \(A\) the adjoint satisfies \(\langle A x, y \rangle = \langle x, A^T y \rangle\). It is obtained here as the gradient of \(x \mapsto \langle A x,\, y \rangle\) evaluated at \(x = 0\), which equals \(A^T y\) exactly (no linearization error) because the map is linear in \(x\).

Parameters:
  • matvec (callable) – Linear function mapping an input tensor to an output tensor. Must be built from differentiable Keras ops.

  • input_template (Tensor) – Tensor with the shape and dtype of the operator input. Only shape and dtype are used.

Returns:

Function mapping an output-shaped tensor y to \(A^T y\) with the shape of input_template.

Return type:

callable

Example

>>> import numpy as np
>>> from keras import ops
>>> from zea.inverse import linear_adjoint

>>> matrix = np.arange(15, dtype=np.float32).reshape(3, 5)
>>> matvec = lambda x: ops.matmul(matrix, x)
>>> rmatvec = linear_adjoint(matvec, ops.zeros(5))
>>> y = np.ones(3, dtype=np.float32)
>>> bool(np.allclose(rmatvec(y), matrix.T @ y, atol=1e-5))
True