| 96 | return torch.tensor(betas).float() |
| 97 | |
| 98 | def set_params(self): |
| 99 | self.alpha = 1 - self.beta |
| 100 | self.alpha_bar = torch.cumprod(self.alpha, dim=0) |
| 101 | self.alpha_bar_prev = torch.cat([torch.ones(1,), self.alpha_bar[:-1]]) |
| 102 | |
| 103 | self.beta_tilde = self.beta * (1.0 - self.alpha_bar_prev) / (1.0 - self.alpha_bar) |
| 104 | self.log_beta_tilde_clipped = torch.log(torch.cat([self.beta_tilde[1, None], self.beta_tilde[1:]])) |
| 105 | |
| 106 | # to caluclate x0 from eps_pred |
| 107 | self.coef1_x0 = torch.sqrt(1.0 / self.alpha_bar) |
| 108 | self.coef2_x0 = torch.sqrt(1.0 / self.alpha_bar - 1) |
| 109 | |
| 110 | # for q(x_{t-1} | x_t, x_0) |
| 111 | self.coef1_q = self.beta * torch.sqrt(self.alpha_bar_prev) / (1.0 - self.alpha_bar) |
| 112 | self.coef2_q = (1.0 - self.alpha_bar_prev) * torch.sqrt(self.alpha) / (1.0 - self.alpha_bar) |
| 113 | |
| 114 | def space(self, n_timesteps_new): |
| 115 | # change parameters for spaced timesteps during sampling |