class_docstr: Hierarchical latent variable model based on a diffusion model.
  
  Args:
      model: The model to use for the denoising (should be in eval mode).
      diffusion: The diffusion to sample from.
      use_log_variance: Whether to use the (clipped) log variance.
      clip_denoised: If True, clip the denoised signal.
      device: The device to use.
          Defaults to the device of the first model parameter.
class_docstr_tok: ["Hierarchical","latent","variable","model","based","on","a","diffusion","model",".","Args",":","model",":","The","model","to","use","for","the","denoising","(","should","be","in","eval","mode",")",".","diffusion",":","The","diffusion","to","sample","from",".","use_log_variance",":","Whether","to","use","the","(","clipped",")","log","variance",".","clip_denoised",":","If","True",",","clip","the","denoised","signal",".","device",":","The","device","to","use",".","Defaults","to","the","device","of","the","first","model","parameter","."]
docstr: If `data` is None, outputs the mean and stdd of the Gaussian
  prior p(z_{step}|z_{step+1}), where latent equals z_{step+1}.
  If `data` is provided, uses the posterior q(z_{step}|z_{step+1}, data).
  
  Args:
      latent: The latent z_{step+1} at the given step.
      step: The number of diffusion steps (minus 1).
          Here, 0 means one step.
      data: The input data array.
  Returns:
      The parameters (mean and standard deviation)
      of the Gaussian prior or posterior.
docstr_tok: ["If","`","data","`","is","None",",","outputs","the","mean","and","stdd","of","the","Gaussian","prior","p","(","z_","{","step","}","|z_","{","step+1","}",")",",","where","latent","equals","z_","{","step+1","}",".","If","`","data","`","is","provided",",","uses","the","posterior","q","(","z_","{","step","}","|z_","{","step+1","}",",","data",")",".","Args",":","latent",":","The","latent","z_","{","step+1","}","at","the","given","step",".","step",":","The","number","of","diffusion","steps","(","minus","1",")",".","Here",",","0","means","one","step",".","data",":","The","input","data","array",".","Returns",":","The","parameters","(","mean","and","standard","deviation",")","of","the","Gaussian","prior","or","posterior","."]
code: def generate_fn(
      self,
      latent: np.ndarray,
      step: int,
      data: Optional[np.ndarray] = None,
  ) -> GaussianParams:
      """
      If `data` is None, outputs the mean and stdd of the Gaussian
      prior p(z_{step}|z_{step+1}), where latent equals z_{step+1}.
      If `data` is provided, uses the posterior q(z_{step}|z_{step+1}, data).
  
      Args:
          latent: The latent z_{step+1} at the given step.
          step: The number of diffusion steps (minus 1).
              Here, 0 means one step.
          data: The input data array.
      Returns:
          The parameters (mean and standard deviation)
          of the Gaussian prior or posterior.
      """
      t = torch.tensor([step], dtype=torch.long).expand(latent.shape[0])
      x_t = torch.from_numpy(latent).to(dtype=torch.float)
  
      if data is None:
          with torch.no_grad():
              output = self.diffusion.p_mean_variance(
                  model=self.model,
                  x=x_t.to(self.device),
                  t=t.to(self.device),
                  clip_denoised=self.clip_denoised,
              )
          mean, variance, log_variance = (
              output["mean"],
              output["variance"],
              output["log_variance"],
          )
      else:
          x_start = torch.from_numpy(data).to(dtype=torch.float)
          (
              mean,
              variance,
              log_variance,
          ) = self.diffusion.q_posterior_mean_variance(
              x_start=x_start, x_t=x_t, t=t
          )
      return self._gaussian_params(mean, variance, log_variance)
  
imports: from abc import ABC, abstractmethod
  from typing import List, NamedTuple, Optional, Tuple, Union, overload
  import craystack
  import numpy
  import torch
  from craystack import codecs
  from craystack.bb_ans import BBANS
  from improved_diffusion.gaussian_diffusion import GaussianDiffusion
label_desc: Use image node_id 4 for calling the DiffusionModel obj's underlying member method code with example usage: obj.generate_fn(latent, step, data) and returns: self