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: Generate users' interaction probabilities in a denoising manner.
  Args:
      x_start (torch.FloatTensor): the input tensor that contains user's history interaction matrix,
                                   for DiffRec shape: [batch_size, n_items]
                                   for LDiffRec shape: [batch_size, hidden_size]
  Returns:
      torch.FloatTensor: the interaction probabilities,
                         for DiffRec shape: [batch_size, n_items]
                         for LDiffRec shape: [batch_size, hidden_size]
code: def p_sample(self, x_start):
      r"""
      Generate users' interaction probabilities in a denoising manner.
      Args:
          x_start (torch.FloatTensor): the input tensor that contains user's history interaction matrix,
                                       for DiffRec shape: [batch_size, n_items]
                                       for LDiffRec shape: [batch_size, hidden_size]
      Returns:
          torch.FloatTensor: the interaction probabilities,
                             for DiffRec shape: [batch_size, n_items]
                             for LDiffRec shape: [batch_size, hidden_size]
      """
      steps = self.sampling_steps
      if steps == 0:
          x_t = x_start
      else:
          t = torch.tensor([steps - 1] * x_start.shape[0]).to(
              x_start.device
          )
          x_t = self.q_sample(x_start, t)
  
      indices = list(range(self.steps))[::-1]
  
      if self.noise_scale == 0.0:
          for i in indices:
              t = torch.tensor([i] * x_t.shape[0]).to(x_start.device)
              x_t = self.mlp(x_t, t)
          return x_t
  
      for i in indices:
          t = torch.tensor([i] * x_t.shape[0]).to(x_start.device)
          out = self.p_mean_variance(x_t, t)
          if self.sampling_noise:
              noise = torch.randn_like(x_t)
              nonzero_mask = (
                  (t != 0)
                  .float()
                  .view(-1, *([1] * (len(x_t.shape) - 1)))
              )  # no noise when t == 0
              x_t = (
                  out["mean"]
                  + nonzero_mask
                  * torch.exp(0.5 * out["log_variance"])
                  * noise
              )
          else:
              x_t = out["mean"]
      return x_t
  
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 5 for calling the DiffRec obj's underlying member method code with example usage: obj.p_sample(x_start) and returns: x_t, x_t