NoisyDataFidelity#

class deepinv.sampling.NoisyDataFidelity(weight=1.0, *args, **kwargs)[source]#

Bases: DataFidelity

Data fidelity term for noisy input data \(- \log p(y|x + \sigma(t) \omega)\) with \(\omega\sim\mathcal{N}(0,\mathrm{I})\).

This is a base class used for approximating \(- \log p_t(y|x_t)\) used in diffusion algorithms for inverse problems, in deepinv.sampling.PosteriorDiffusion.

It comes with a .grad method computing the negative log-likelihood gradient :math:` - nabla_{x_t} log p_t(y|x_t)`.

By default we have

\[- \nabla_{x_t} \log p(y|x + \sigma(t) \omega) = A^\top(\forw{x_t}-y),\]

which subclasses override with their own approximation.

Note

Unlike deepinv.optim.DataFidelity, these terms are defined through their gradient only: the approximations of \(- \log p_t(y|x_t)\) used by diffusion samplers generally do not admit a closed-form value. The .forward method therefore raises a NotImplementedError unless a subclass defines it.

Parameters:

weight (float) – Weighting factor for the data fidelity term. Default to 1.

forward(*args, **kwargs)[source]#

Not implemented: noisy data-fidelity terms are defined through their gradient \(-\nabla_{x_t} \log p_t(y|x_t)\), see grad(). Subclasses whose approximation of \(- \log p_t(y|x_t)\) has a closed form override this method.

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

Computes the gradient of the data-fidelity term \(\lambda A^\top(A(x) - y)\).

Parameters:
Returns:

(torch.Tensor) data-fidelity term.

Return type:

Tensor

Examples using NoisyDataFidelity:#

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

Noisy data-fidelity terms for diffusion posterior sampling

Noisy data-fidelity terms for diffusion posterior sampling