class_docstr: DiffRec is a generative recommender model which infers users' interaction probabilities in a denoising manner.
  Note that DiffRec simultaneously ranks all items for each user.
  We implement the the DiffRec model with only user dataloader.
class_docstr_tok: ["DiffRec","is","a","generative","recommender","model","which","infers","users","'","interaction","probabilities","in","a","denoising","manner",".","Note","that","DiffRec","simultaneously","ranks","all","items","for","each","user",".","We","implement","the","the","DiffRec","model","with","only","user","dataloader","."]
docstr: Calculate the coefficients for the diffusion process.
code: def calculate_for_diffusion(self):
      r"""
      Calculate the coefficients for the diffusion process.
      """
      alphas = 1.0 - self.betas
      # [alpha_{1}, ..., alpha_{1}*...*alpha_{T}] shape (steps,)
      self.alphas_cumprod = torch.cumprod(alphas, axis=0).to(
          self.device
      )
      # alpha_{t-1}
      self.alphas_cumprod_prev = torch.cat(
          [
              torch.tensor([1.0]).to(self.device),
              self.alphas_cumprod[:-1],
          ]
      ).to(self.device)
      # alpha_{t+1}
      self.alphas_cumprod_next = torch.cat(
          [self.alphas_cumprod[1:], torch.tensor([0.0]).to(self.device)]
      ).to(self.device)
      assert self.alphas_cumprod_prev.shape == (self.steps,)
  
      self.sqrt_alphas_cumprod = torch.sqrt(self.alphas_cumprod)
      self.sqrt_one_minus_alphas_cumprod = torch.sqrt(
          1.0 - self.alphas_cumprod
      )
      self.log_one_minus_alphas_cumprod = torch.log(
          1.0 - self.alphas_cumprod
      )
      self.sqrt_recip_alphas_cumprod = torch.sqrt(
          1.0 / self.alphas_cumprod
      )
      self.sqrt_recipm1_alphas_cumprod = torch.sqrt(
          1.0 / self.alphas_cumprod - 1
      )
  
      self.posterior_variance = (
          self.betas
          * (1.0 - self.alphas_cumprod_prev)
          / (1.0 - self.alphas_cumprod)
      )
  
      self.posterior_log_variance_clipped = torch.log(
          torch.cat(
              [
                  self.posterior_variance[1].unsqueeze(0),
                  self.posterior_variance[1:],
              ]
          )
      )
      # Eq.10 coef for x_theta
      self.posterior_mean_coef1 = (
          self.betas
          * torch.sqrt(self.alphas_cumprod_prev)
          / (1.0 - self.alphas_cumprod)
      )
      # Eq.10 coef for x_t
      self.posterior_mean_coef2 = (
          (1.0 - self.alphas_cumprod_prev)
          * torch.sqrt(alphas)
          / (1.0 - self.alphas_cumprod)
      )
  
imports: import enum
  import math
  import copy
  import numpy
  import torch
  import torch.nn.functional
  import torch.nn
  from recbole.model.init import xavier_normal_initialization
  from recbole.utils.enum_type import InputType
  from recbole.model.abstract_recommender import AutoEncoderMixin, GeneralRecommender
  from recbole.model.layers import MLPLayers
  import typing
label_desc: Use image node_id 4 for calling the DiffRec obj's underlying member method code with example usage: obj.calculate_for_diffusion() without return types