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\). Default None.

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}\).

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\).

grad_d(u, y, *args, **kwargs)[source]#

Computes the gradient \(\nabla_u\distance{u}{y}\), computed in \(u\).

Note that this is the gradient of \(\distancename\) and not \(\datafidname\). This function directly calls deepinv.optim.Potential.grad() for the specific distance function \(\distancename\).

Parameters:
  • u (torch.Tensor) – Variable \(u\) at which the gradient is computed.

  • y (torch.Tensor) – Data \(y\) of the same dimension as \(u\).

Returns:

(torch.Tensor) gradient of \(d\) in \(u\), i.e. \(\nabla_u\distance{u}{y}\).

prox_d(u, y, *args, **kwargs)[source]#

Computes the proximity operator \(\operatorname{prox}_{\gamma\distance{\cdot}{y}}(u)\), computed in \(u\).

Note that this is the proximity operator of \(\distancename\) and not \(\datafidname\). This function directly calls deepinv.optim.Potential.prox() for the specific distance function \(\distancename\).

Parameters:
  • u (torch.Tensor) – Variable \(u\) at which the gradient is computed.

  • y (torch.Tensor) – Data \(y\) of the same dimension as \(u\).

Returns:

(torch.Tensor) gradient of \(d\) in \(u\), i.e. \(\nabla_u\distance{u}{y}\).

prox_d_conjugate(u, y, *args, **kwargs)[source]#

Computes the proximity operator of the convex conjugate of the distance function \(\distance{u}{y}\).

This function directly calls deepinv.optim.Potential.prox_conjugate() for the specific distance function \(\distancename\).

Examples using DataFidelity:#

Radio interferometric imaging with deepinverse

Radio interferometric imaging with deepinverse

Image deblurring with custom deep explicit prior.

Image deblurring with custom deep explicit prior.

Saving and loading models

Saving and loading models

Random phase retrieval and reconstruction methods.

Random phase retrieval and reconstruction methods.

Ptychography phase retrieval

Ptychography phase retrieval

Image deblurring with Total-Variation (TV) prior

Image deblurring with Total-Variation (TV) prior

Image inpainting with wavelet prior

Image inpainting with wavelet prior

Patch priors for limited-angle computed tomography

Patch priors for limited-angle computed tomography

DPIR method for PnP image deblurring.

DPIR method for PnP image deblurring.

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

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

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

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

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 sampling algorithm.

Building your custom sampling algorithm.

Implementing DiffPIR

Implementing DiffPIR

Implementing DPS

Implementing DPS

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.

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