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
|
Conjugate gradient least squares (CGLS). |
|
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
matvecand its adjointrmatvec. 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
yto \(A^T y\) with the shape ofinput_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