ALDDataFidelity#
- class deepinv.sampling.ALDDataFidelity(gamma=None, weight=1.0, *args, **kwargs)[source]#
Bases:
NoisyDataFidelityScore-based annealed Langevin dynamics (Score-ALD) data-fidelity term.
This corresponds to the \(p(y|x_t)\) approximation proposed in [64], and reviewed in [35], given by
\[p_t(y|x_t) \approx \mathcal{N} \left( y; A x_t, \left(\sigma_y^2 + \gamma_t^2\right)\mathrm{Id} \right).\]The resulting negative log-likelihood gradient is
\[-\nabla_{x_t} \log p_t(y|x_t) \approx \lambda \frac{A^\top \left(A x_t - y\right)}{\sigma_y^2 + \gamma_t^2},\]where \(\sigma_y\) is the measurement noise level and \(\lambda\), exposed as
weight, controls the scale of the data-fidelity term.Note
\(\gamma_t\) should decrease along the diffusion, so that the guidance strengthens as \(x_t\) gets closer to the data manifold. The default
gamma=Nonefollows [64] and uses the current diffusion noise level, \(\gamma_t=\sigma_t\).- Parameters:
gamma (Callable, float) – annealing parameter \(\gamma_t\). If
None(default), \(\gamma_t = \sigma_t\), the current diffusion noise level. Afloatuses a constant value, and aCallableis evaluated as \(\gamma_t = \text{gamma}(\sigma_t)\).weight (float) – Weighting factor \(\lambda\). Default:
1.0.
- forward(x, y, physics, sigma, *args, **kwargs)[source]#
Returns the loss term \(\lambda \| A x_t - y \|^2 / \left(2(\sigma_y^2 + \gamma_t^2)\right)\), whose gradient is given by
grad().- Parameters:
x (torch.Tensor) – input image.
y (torch.Tensor) – measurements.
physics (deepinv.physics.Physics) – forward operator.
sigma (torch.Tensor, float) – Diffusion noise standard deviation.
- Returns:
(
torch.Tensor) loss term, of sizeBthe batch size.- Return type:
- grad(x, y, physics, sigma, *args, **kwargs)[source]#
Compute the Score-ALD data-fidelity gradient.
\[-\nabla_{x_t} \log p_t(y|x_t) \approx \lambda \frac{A^\top \left(A x_t - y\right)}{\sigma_y^2 + \gamma_t^2}.\]The measurement noise level \(\sigma_y\) is read from
physics.noise_model.sigmawhen the noise is Gaussian, and is taken to be zero otherwise.- Parameters:
x (torch.Tensor) – Current noisy iterate.
y (torch.Tensor) – Measurements.
physics (deepinv.physics.Physics) – physics model.
sigma (torch.Tensor, float) – Diffusion noise standard deviation.
- Returns:
Score-ALD gradient, with the same shape as
x.- Return type:
Examples using ALDDataFidelity:#
Noisy data-fidelity terms for diffusion posterior sampling