NoisyDataFidelity#
- class deepinv.sampling.NoisyDataFidelity(weight=1.0, *args, **kwargs)[source]#
Bases:
DataFidelityData 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
.gradmethod 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.forwardmethod therefore raises aNotImplementedErrorunless 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:
x (torch.Tensor) – Current iterate.
y (torch.Tensor) – Input data.
physics (deepinv.physics.Physics) – physics model
- Returns:
(torch.Tensor) data-fidelity term.
- Return type:
Examples using NoisyDataFidelity:#
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
Noisy data-fidelity terms for diffusion posterior sampling