Solvers¶
The module torch_radon.solvers contains implementations of algorithms that can be used to solve
tomographic reconstructions problems.
Landweber Iteration¶
- class torch_radon.solvers.Landweber(operator, projection=None, grad=False)[source]¶
Class that implements Landweber iteration to solve \(\min_{x \in C} \|Ax-y\|_2^2\) (see Wikipedia page).
The iteration used is \(x_{n+1} = \mathcal{P}_C(x - \alpha A^T A x_n)\) where \(\mathcal{P}_C\) is the projection onto \(C\).
- Parameters
operator – Instance of a class that implements products \(A x\) (
operator.forward(x)) and \(A^T y\) (operator.backward(y)).projection – Function that implements \(\mathcal{P}_C(\cdot)\), if not specified no projection is used.
grad – If true gradient will be enabled, more memory will be used but it will be possible to backpropagate.
- estimate_alpha(img_size, device, n_iter=50, batch_size=8)[source]¶
Use power iteration on \(A^T A\) to estimate the maximum step size that still guarantees convergence.
Note
Because this computation is not exact it is advised to use a value of alpha lower that the one estimated by this method (for example multiplying the estimate by 0.95).
- Parameters
img_size – Size of the image
device – GPU device that will be used for computation
n_iter – Number of iterations
batch_size – Number of vectors used in the power iteration.
- Returns
Estimated value for alpha
- run(x_zero, y, alpha, iterations=100, callback=None)[source]¶
Execute Landweber iterations.
- Parameters
x_zero – Initial solution guess used as a starting point for the iteration
y – Value of y in \(\min_{x \in C} \|Ax-y\|_2^2\)
alpha – Step size, can be estimated using
estimate_alphaiterations – Number of iterations
callback – Optional function that will be called at each iteration with \(x_n\) as argument. Values returned by
callbackwill be stored in a list and returned together with the computed solution
- Returns
If
callbackis specified returnsx, valueswherexis the solution computed by the Landweber iteration andvaluesis the list of values returned bycallbackat each iteration. Ifcallbackis not specified returns onlyx
Conjugate Gradient¶
- torch_radon.solvers.cg(forward, x, y, callback=None, max_iter=500, tol=1e-05)[source]¶
Implements Conjugate Gradient algorithm for solving \(\min_x \|Ax-y\|_2^2\).
Note
For conjugate gradient to work the matrix \(A\) must be symmetric positive definite. Otherwise use other solvers.
- Parameters
forward – function that implements products \(A x\) (
forward(x)).x – Initial solution guess used as a starting point for the iteration
y – Value of y in \(\min_{x \in C} \|Ax-y\|_2^2\)
callback – Optional function that will be called at each iteration with \(x_n\) and the residual as arguments. Values returned by
callbackwill be stored in a list and returned together with the computed solution.max_iter – Maximum number of iterations.
tol – Algorithm is stopped when \(\frac{\| Ax_n - y \|}{\| y \|} \leq \text{tol}\)
- Returns
If
callbackis specified returnsx, valueswherexis the solution computed by the Landweber iteration andvaluesis the list of values returned bycallbackat each iteration. Ifcallbackis not specified returns onlyx.
- torch_radon.solvers.cgne(operator, x, y, callback=None, max_iter=5000, tol=1e-05)[source]¶
Implements Conjugate Gradient on the Normal Equations, an algorithm for solving \(\min_x \|Ax-y\|_2^2\).
- Parameters
operator – Instance of a class that implements products \(A x\) (
operator.forward(x)) and \(A^T y\) (operator.backward(y)).x – Initial solution guess used as a starting point for the iteration :param y: Value of y in \(\min_{x \in C} \|Ax-y\|_2^2\)
callback – Optional function that will be called at each iteration with \(x_n\) as argument. Values returned by
callbackwill be stored in a list and returned together with the computed solutionmax_iter – Maximum number of iterations
tol – Algorithm is stopped when \(\frac{\| s \|}{\| y \|} \leq \text{tol}\)
- Returns
If
callbackis specified returnsx, valueswherexis the solution computed by the Landweber iteration andvaluesis the list of values returned bycallbackat each iteration. Ifcallbackis not specified returns onlyx