class_docstr: Utilities for training and sampling diffusion models.
  
  Ported directly from here, and then adapted over time to further experimentation.
  https://github.com/hojonathanho/diffusion/blob/1e0dceb3b3495bbe19116a5e1b3596cd0706c543/diffusion_tf/diffusion_utils_2.py#L42
  
  :param betas: a 1-D numpy array of betas for each diffusion timestep,
                starting at T and going to 1.
  :param model_mean_type: a ModelMeanType determining what the model outputs.
  :param model_var_type: a ModelVarType determining how variance is output.
  :param loss_type: a LossType determining the loss function to use.
  :param rescale_timesteps: if True, pass floating point timesteps into the
                            model so that they are always scaled like in the
                            original paper (0 to 1000).
class_docstr_tok: ["Utilities","for","training","and","sampling","diffusion","models",".","Ported","directly","from","here",",","and","then","adapted","over","time","to","further","experimentation",".","https",":","\/\/github.com\/hojonathanho\/diffusion\/blob\/1e0dceb3b3495bbe19116a5e1b3596cd0706c543\/diffusion_tf\/diffusion_utils_2.py","#","L42",":","param","betas",":","a","1-D","numpy","array","of","betas","for","each","diffusion","timestep",",","starting","at","T","and","going","to","1.",":","param","model_mean_type",":","a","ModelMeanType","determining","what","the","model","outputs",".",":","param","model_var_type",":","a","ModelVarType","determining","how","variance","is","output",".",":","param","loss_type",":","a","LossType","determining","the","loss","function","to","use",".",":","param","rescale_timesteps",":","if","True",",","pass","floating","point","timesteps","into","the","model","so","that","they","are","always","scaled","like","in","the","original","paper","(","0","to","1000",")","."]
code: def __init__(
      self,
      *,
      betas,
      model_mean_type,
      model_var_type,
      loss_type,
      rescale_timesteps=False,
  ):
      self.model_mean_type = model_mean_type
      self.model_var_type = model_var_type
      self.loss_type = loss_type
      self.rescale_timesteps = rescale_timesteps
  
      # Use float64 for accuracy.
      betas = np.array(betas, dtype=np.float64)
      self.betas = betas
      assert len(betas.shape) == 1, "betas must be 1-D"
      assert (betas > 0).all() and (betas <= 1).all()
  
      self.num_timesteps = int(betas.shape[0])
  
      alphas = 1.0 - betas
      self.alphas_cumprod = np.cumprod(alphas, axis=0)
      self.alphas_cumprod_prev = np.append(
          1.0, self.alphas_cumprod[:-1]
      )
      self.alphas_cumprod_next = np.append(self.alphas_cumprod[1:], 0.0)
      assert self.alphas_cumprod_prev.shape == (self.num_timesteps,)
  
      # calculations for diffusion q(x_t | x_{t-1}) and others
      self.sqrt_alphas_cumprod = np.sqrt(self.alphas_cumprod)
      self.sqrt_one_minus_alphas_cumprod = np.sqrt(
          1.0 - self.alphas_cumprod
      )
      self.log_one_minus_alphas_cumprod = np.log(
          1.0 - self.alphas_cumprod
      )
      self.sqrt_recip_alphas_cumprod = np.sqrt(
          1.0 / self.alphas_cumprod
      )
      self.sqrt_recipm1_alphas_cumprod = np.sqrt(
          1.0 / self.alphas_cumprod - 1
      )
  
      # calculations for posterior q(x_{t-1} | x_t, x_0)
      self.posterior_variance = (
          betas
          * (1.0 - self.alphas_cumprod_prev)
          / (1.0 - self.alphas_cumprod)
      )
      # log calculation clipped because the posterior variance is 0 at the
      # beginning of the diffusion chain.
      self.posterior_log_variance_clipped = np.log(
          np.append(
              self.posterior_variance[1], self.posterior_variance[1:]
          )
      )
      self.posterior_mean_coef1 = (
          betas
          * np.sqrt(self.alphas_cumprod_prev)
          / (1.0 - self.alphas_cumprod)
      )
      self.posterior_mean_coef2 = (
          (1.0 - self.alphas_cumprod_prev)
          * np.sqrt(alphas)
          / (1.0 - self.alphas_cumprod)
      )
  
imports: import enum
  import math
  import numpy
  import paddle
  from .losses import discretized_gaussian_log_likelihood
  from .losses import normal_kl
  from .nn import mean_flat
label_desc: Use image node_id 1 to create a new GaussianDiffusion object  with example: obj = GaussianDiffusion()