Browse and solve 1,200+ machine learning coding challenges on Deep-ML. Filter by difficulty (beginner, intermediate, advanced) and category (linear algebra, machine learning, deep learning, NLP, computer vision). Write Python solutions in the browser and get instant feedback against test cases.
Deep-ML | Tweedie Denoiser: From Score to x0Tweedie Denoiser: From Score to x0
A noisy sample xt=αˉtx0+1−αˉtϵ can be denoised by a network that predicts the score∇xtlogq(xt), the noiseϵ, or directly the clean signal. Tweedie's formula ties them together:
x_t has shape (N, ...) (a batch; typically (N, d)).
alpha_bar_t is a scalar or an array of shape (N,) with one αˉt per batch element, broadcast along the batch axis.
Exactly one of score or eps is given, with the same shape as x_t.
Compute the missing one of the pair (eps from score or score from eps) with the relation above, then the posterior mean x^0=E[x0∣xt].
Return a dict with keys "score", "eps", "x0_hat", each a numpy array of the same shape as x_t rounded to decimals.
gaussian_score(x_t, alpha_bar_t, mu0, var0)
The data distribution is q(x0)=N(μ0,v0I) with mu0 of shape (d,) (or a scalar) and var0 a scalar. The marginal of xt is then N(αˉtμ0,(αˉtv0+1−αˉt)I).
Return its exact score at x_t (unrounded array, same shape as x_t; alpha_bar_t scalar or (N,) as above).
Hints
Reshape an (N,) array of αˉt to (N, 1, ..., 1) so it broadcasts against (N, ...) data.
The score of N(m,vI) at x is −(x−m)/v.
With the analytic Gaussian score, x0_hat must coincide with the Bayes posterior mean of x0 given xt up to rounding.