DataFidelity#

class deepinv.optim.DataFidelity(d=None)[source]#

Bases: Potential

Base 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 d to 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 the prox. 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:

torch.Tensor

fn(x, y, physics, *args, **kwargs)[source]#

Computes the data fidelity term \(\datafid{x}{y} = \distance{\forw{x}}{y}\).

Parameters:
Returns:

(torch.Tensor) data fidelity \(\datafid{x}{y}\).

Return type:

torch.Tensor

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_d with \(u = \forw{x}\). The multiplication is computed using the A_vjp method of the physics.

Parameters:
Returns:

(torch.Tensor) gradient \(\nabla_x \datafid{x}{y}\), computed in \(x\).

Return type:

torch.Tensor

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:

torch.Tensor

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:

torch.Tensor

Examples using DataFidelity:#

Use iterative reconstruction algorithms

Use iterative reconstruction algorithms

Calibrating physics operators

Calibrating physics operators

Distributed Plug-and-Play (PnP) Reconstruction

Distributed Plug-and-Play (PnP) Reconstruction

Distributed Training of Unfolded Networks

Distributed Training of Unfolded Networks

Low-dose CT with ASTRA backend and Total-Variation (TV) prior

Low-dose CT with ASTRA backend and Total-Variation (TV) prior

Single-pixel imaging with Spyrit

Single-pixel imaging with Spyrit

Radio interferometric imaging with deepinverse

Radio interferometric imaging with deepinverse

Image deblurring with Total-Variation (TV) prior

Image deblurring with Total-Variation (TV) prior

Image deblurring with custom deep explicit prior.

Image deblurring with custom deep explicit prior.

Multispectral demosaicing from raw sensor data

Multispectral demosaicing from raw sensor data

Patch priors for limited-angle computed tomography

Patch priors for limited-angle computed tomography

Poisson Inverse Problems with Maximum-Likelihood Expectation-Maximization (MLEM)

Poisson Inverse Problems with Maximum-Likelihood Expectation-Maximization (MLEM)

Image inpainting with wavelet prior

Image inpainting with wavelet prior

Positron emission tomography (PET) in 2D

Positron emission tomography (PET) in 2D

Positron emission tomography (PET) in 3D

Positron emission tomography (PET) in 3D

Random phase retrieval and reconstruction methods.

Random phase retrieval and reconstruction methods.

Ptychography phase retrieval

Ptychography phase retrieval

Inverse scattering problem

Inverse scattering problem

Spatial unwrapping and modulo imaging

Spatial unwrapping and modulo imaging

Pattern Ordering in a Compressive Single Pixel Camera

Pattern Ordering in a Compressive Single Pixel Camera

DPIR method for PnP image deblurring.

DPIR method for PnP image deblurring.

PnP with custom optimization algorithm (Primal-Dual Condat-Vu)

PnP with custom optimization algorithm (Primal-Dual Condat-Vu)

Plug-and-Play algorithm with Mirror Descent for Poisson noise inverse problems.

Plug-and-Play algorithm with Mirror Descent for Poisson noise inverse problems.

Multi-scale Plug-and-Play for Inpainting

Multi-scale Plug-and-Play for Inpainting

Regularization by Denoising (RED) for Super-Resolution.

Regularization by Denoising (RED) for Super-Resolution.

Vanilla PnP for computed tomography (CT).

Vanilla PnP for computed tomography (CT).

Building your custom MCMC sampling algorithm.

Building your custom MCMC sampling algorithm.

Implementing DiffPIR

Implementing DiffPIR

Using state-of-the-art diffusion models from HuggingFace Diffusers with DeepInverse

Using state-of-the-art diffusion models from HuggingFace Diffusers with DeepInverse

Building your diffusion posterior sampling method using SDEs

Building your diffusion posterior sampling method using SDEs

DPS – Posterior Sampling with Diffusion Models

DPS -- Posterior Sampling with Diffusion Models

Flow-Matching for posterior sampling and unconditional generation

Flow-Matching for posterior sampling and unconditional generation

Uncertainty quantification with PnP-ULA.

Uncertainty quantification with PnP-ULA.

Deep Equilibrium (DEQ) algorithms for image deblurring

Deep Equilibrium (DEQ) algorithms for image deblurring

Learned Iterative Soft-Thresholding Algorithm (LISTA) for compressed sensing

Learned Iterative Soft-Thresholding Algorithm (LISTA) for compressed sensing

Learned iterative custom prior

Learned iterative custom prior

Learned Primal-Dual algorithm for CT scan.

Learned Primal-Dual algorithm for CT scan.

Reducing the memory and computational complexity of unfolded network training

Reducing the memory and computational complexity of unfolded network training

Unfolded Chambolle-Pock for constrained image inpainting

Unfolded Chambolle-Pock for constrained image inpainting

Vanilla Unfolded algorithm for super-resolution

Vanilla Unfolded algorithm for super-resolution