MCPcopy Index your code
hub / github.com/CompVis/diff2flow / q_sample

Method q_sample

diff2flow/ddpm.py:199–209  ·  view source on GitHub ↗

Diffuse the data for a given number of diffusion steps => sample x_t ~ q(x_t | x_0) with x_t = sqrt(alpha_bar_t) * x_0 + sqrt(1 - alpha_bar_t) * noise

(self, x_start, t, noise=None)

Source from the content-addressed store, hash-verified

197 return mean, variance, log_variance
198
199 def q_sample(self, x_start, t, noise=None):
200 """
201 Diffuse the data for a given number of diffusion steps
202 => sample x_t ~ q(x_t | x_0) with
203 x_t = sqrt(alpha_bar_t) * x_0 + sqrt(1 - alpha_bar_t) * noise
204 """
205 if noise is None:
206 noise = torch.randn_like(x_start)
207 sqrt_alpha_cumprod_t = extract_into_tensor(self.sqrt_alphas_cumprod, t, x_start.shape)
208 sqrt_one_minus_alpha_cumprod_t = extract_into_tensor(self.sqrt_one_minus_alphas_cumprod, t, x_start.shape)
209 return sqrt_alpha_cumprod_t * x_start + sqrt_one_minus_alpha_cumprod_t * noise
210
211 def get_v(self, x_start, noise, t):
212 """ v-parameterization: sqrt(alpha_bar_t) * eps - sqrt(1 - alpha_bar_t) * x_0 """

Callers 6

training_lossesMethod · 0.95
calc_bpd_loopMethod · 0.95
training_stepMethod · 0.45
validation_stepMethod · 0.45
inferenceMethod · 0.45

Calls 1

extract_into_tensorFunction · 0.70

Tested by

no test coverage detected