DataFidelity#
- class deepinv.optim.DataFidelity(d=None)[source]#
Bases:
PotentialBase class for the data fidelity term \(\distance{A(x)}{y}\) where \(A\) is the forward operator, \(x\in\xset\) is a variable and \(y\in\yset\) is the data, and where \(d\) is a distance function, from the class
deepinv.optim.Distance.- Parameters:
d (Callable) – distance function \(d(x, y)\) between a variable \(x\) and an observation \(y\). The distance \(\distancename\) is not optional: pass a callable
dto the constructor or use a subclass instead e.g.,deepinv.optim.L2.
- bregman_prox(x, bregman_potential, y, physics, *args, gamma=1.0, stepsize_inter=1.0, max_iter_inter=50, tol_inter=1e-3, **kwargs)[source]#
(Right) Bregman proximal operator of \(\gamma \datafid{x}{y}\), with Bregman potential \(\phi\).
Compute the Bregman proximity operator of the fidelity term, i.e.
\[\operatorname{prox}^\phi_{\gamma \datafidname}(x) = \underset{u}{\text{argmin}} \; \gamma \, \datafid{u}{y} + D_\phi(u,x)\]where \(D_\phi(u,x)\) stands for the Bregman divergence with potential \(\phi\).
Warning
If \(\phi\) is the squared Euclidean norm (
deepinv.optim.BregmanL2), this operator reduces to theprox. Otherwise, this function will use a gradient descent method to compute the Bregman proximity operator, which may be slow and not guaranteed to converge.- Parameters:
x (torch.Tensor) – Variable \(x\) at which the proximity operator is computed.
bregman_potential (deepinv.optim.Bregman) – Bregman potential \(\phi\) to be used in the Bregman proximity operator.
y (torch.Tensor) – Data \(y\).
physics (deepinv.physics.Physics) – physics model.
gamma (float) – step size for the proximity operator.
stepsize_inter (float) – step size for the internal optimization.
max_iter_inter (int) – maximum number of iterations for the internal optimization.
tol_inter (float) – tolerance for the internal optimization.
- Returns:
(
torch.Tensor) Bregman proximity operator \(\operatorname{prox}^\phi_{\gamma \datafidname}(x)\), computed in \(x\).- Return type:
- fn(x, y, physics, *args, **kwargs)[source]#
Computes the data fidelity term \(\datafid{x}{y} = \distance{\forw{x}}{y}\).
- Parameters:
x (torch.Tensor) – Variable \(x\) at which the data fidelity is computed.
y (torch.Tensor) – Data \(y\).
physics (deepinv.physics.Physics) – physics model.
- Returns:
(
torch.Tensor) data fidelity \(\datafid{x}{y}\).- Return type:
- grad(x, y, physics, *args, **kwargs)[source]#
Calculates the gradient of the data fidelity term \(\datafidname\) at \(x\).
The gradient is computed using the chain rule:
\[\nabla_x \distance{\forw{x}}{y} = \left. \frac{\partial A}{\partial x} \right|_x^\top \nabla_u \distance{u}{y},\]where \(\left. \frac{\partial A}{\partial x} \right|_x\) is the Jacobian of \(A\) at \(x\), and \(\nabla_u \distance{u}{y}\) is computed using
grad_dwith \(u = \forw{x}\). The multiplication is computed using theA_vjpmethod of the physics.- Parameters:
x (torch.Tensor) – Variable \(x\) at which the gradient is computed.
y (torch.Tensor) – Data \(y\).
physics (deepinv.physics.Physics) – physics model.
- Returns:
(
torch.Tensor) gradient \(\nabla_x \datafid{x}{y}\), computed in \(x\).- Return type:
- prox(x, y, physics, gamma=1.0, stepsize_inter=1.0, max_iter_inter=50, tol_inter=1e-3, **kwargs)[source]#
Proximal operator of \(\gamma \datafid{x}{y}\)
Compute the proximal operator of the fidelity term \(\operatorname{prox}_{\gamma \datafidname}\), i.e.
\[\operatorname{prox}_{\gamma \datafidname}(x) = \underset{u}{\text{argmin}} \; \gamma \, d(\forw{u},y)+\frac{1}{2}\|u-x\|_2^2\]Warning
If the proximity operator is not available in closed form, this function will use a gradient descent method to compute the proximity operator, which may be slow and not guaranteed to converge.
- Parameters:
x (torch.Tensor) – Variable \(x\) at which the proximity operator is computed.
y (torch.Tensor) – Data \(y\).
physics (deepinv.physics.Physics) – physics model.
gamma (float) – step size for the proximity operator.
stepsize_inter (float) – step size for the internal optimization.
max_iter_inter (int) – maximum number of iterations for the internal optimization.
tol_inter (float) – tolerance for the internal optimization.
- Returns:
(
torch.Tensor) proximity operator computed in \(x\).- Return type:
- prox_conjugate(x, y, physics, *args, gamma=1.0, lamb=1.0, **kwargs)[source]#
Proximal operator of the convex conjugate of \(\lambda \datafidname\).
Compute \(\operatorname{prox}_{\gamma (\lambda \datafidname)^*}\) using the Moreau identity
\[\operatorname{prox}_{\gamma (\lambda \datafidname)^*}(x) = x - \gamma \operatorname{prox}_{\frac{\lambda}{\gamma} \datafidname}\left(\frac{x}{\gamma}\right)\]where \(\operatorname{prox}_{\gamma \datafidname}\) is computed with
prox.Warning
The Moreau identity is only valid if the data fidelity term is convex.
- Parameters:
x (torch.Tensor) – Variable \(x\) at which the proximity operator is computed.
y (torch.Tensor) – Data \(y\).
physics (deepinv.physics.Physics) – physics model.
gamma (float) – step size for the proximity operator.
lamb (float) – \(\lambda\) parameter in front of \(\datafidname\).
- Returns:
(
torch.Tensor) proximity operator \(\operatorname{prox}_{\gamma (\lambda \datafidname)^*}(x)\), computed in \(x\).- Return type:
Examples using DataFidelity:#
Low-dose CT with ASTRA backend and Total-Variation (TV) prior
Patch priors for limited-angle computed tomography
Poisson Inverse Problems with Maximum-Likelihood Expectation-Maximization (MLEM)
Random phase retrieval and reconstruction methods.
Pattern Ordering in a Compressive Single Pixel Camera
PnP with custom optimization algorithm (Primal-Dual Condat-Vu)
Plug-and-Play algorithm with Mirror Descent for Poisson noise inverse problems.
Regularization by Denoising (RED) for Super-Resolution.
Using state-of-the-art diffusion models from HuggingFace Diffusers with DeepInverse
Building your diffusion posterior sampling method using SDEs
Flow-Matching for posterior sampling and unconditional generation
Deep Equilibrium (DEQ) algorithms for image deblurring
Learned Iterative Soft-Thresholding Algorithm (LISTA) for compressed sensing
Reducing the memory and computational complexity of unfolded network training
Unfolded Chambolle-Pock for constrained image inpainting