class_docstr: Guassian Diffusion for large-scale recommendation.
class_docstr_tok: ["Guassian","Diffusion","for","large-scale","recommendation","."]
code: def __init__(
      self,
      item_emb,
      n_cate,
      in_dims,
      out_dims,
      device,
      act_func,
      reparam=True,
      dropout=0.1,
  ):
      super(AutoEncoder, self).__init__()
  
      self.item_emb = item_emb
      self.n_cate = n_cate
      self.in_dims = in_dims
      self.out_dims = out_dims
      self.act_func = act_func
      self.n_item = len(item_emb)
      self.reparam = reparam
      self.dropout = nn.Dropout(dropout)
  
      if n_cate == 1:  # no clustering
          in_dims_temp = (
              [self.n_item + 1]
              + self.in_dims[:-1]
              + [self.in_dims[-1] * 2]
          )
          out_dims_temp = (
              [self.in_dims[-1]] + self.out_dims + [self.n_item + 1]
          )
  
          self.encoder = MLPLayers(
              in_dims_temp, activation=self.act_func
          )
          self.decoder = MLPLayers(
              out_dims_temp,
              activation=self.act_func,
              last_activation=False,
          )
  
      else:
          from kmeans_pytorch import kmeans
  
          self.cluster_ids, _ = kmeans(
              X=item_emb,
              num_clusters=n_cate,
              distance="euclidean",
              device=device,
          )
          # cluster_ids(labels): [0, 1, 2, 2, 1, 0, 0, ...]
          category_idx = []
          for i in range(n_cate):
              idx = (
                  np.argwhere(self.cluster_ids.numpy() == i)
                  .flatten()
                  .tolist()
              )
              category_idx.append(torch.tensor(idx, dtype=int) + 1)
          self.category_idx = category_idx  # [cate1: [iid1, iid2, ...], cate2: [iid3, iid4, ...], cate3: [iid5, iid6, ...]]
          self.category_map = torch.cat(
              tuple(category_idx), dim=-1
          )  # map
          self.category_len = [
              len(self.category_idx[i]) for i in range(n_cate)
          ]  # item num in each category
          print("category length: ", self.category_len)
          assert sum(self.category_len) == self.n_item
  
          ##### Build the Encoder and Decoder #####
          encoders = []
          decode_dim = []
          for i in range(n_cate):
              if i == n_cate - 1:
                  latent_dims = list(
                      self.in_dims - np.array(decode_dim).sum(axis=0)
                  )
              else:
                  latent_dims = [
                      int(
                          self.category_len[i]
                          / self.n_item
                          * self.in_dims[j]
                      )
                      for j in range(len(self.in_dims))
                  ]
                  latent_dims = [
                      latent_dims[j] if latent_dims[j] != 0 else 1
                      for j in range(len(self.in_dims))
                  ]
              in_dims_temp = (
                  [self.category_len[i]]
                  + latent_dims[:-1]
                  + [latent_dims[-1] * 2]
              )
              encoders.append(
                  MLPLayers(in_dims_temp, activation=self.act_func)
              )
              decode_dim.append(latent_dims)
  
          self.encoder = nn.ModuleList(encoders)
          print("Latent dims of each category: ", decode_dim)
  
          self.decode_dim = [
              decode_dim[i][::-1] for i in range(len(decode_dim))
          ]
  
          if (
              len(out_dims) == 0
          ):  # one-layer decoder: [encoder_dim_sum, n_item]
              out_dim = self.in_dims[-1]
              self.decoder = MLPLayers(
                  [out_dim, self.n_item], activation=None
              )
          else:  # multi-layer decoder: [encoder_dim, hidden_size, cate_num]
              # decoder_modules = [[] for _ in range(n_cate)]
              decoders = []
              for i in range(n_cate):
                  out_dims_temp = self.decode_dim[i] + [
                      self.category_len[i]
                  ]
                  decoders.append(
                      MLPLayers(
                          out_dims_temp,
                          activation=self.act_func,
                          last_activation=False,
                      )
                  )
              self.decoder = nn.ModuleList(decoders)
  
      self.apply(xavier_normal_initialization)
  
imports: import os
  import numpy
  import torch
  import torch.nn.functional
  import torch.nn
  from recbole.model.init import xavier_normal_initialization
  from recbole.model.layers import MLPLayers
  from recbole.model.general_recommender.diffrec import DiffRec, DNN, ModelMeanType, mean_flat
label_desc: Use image node_id 1 to create a new AutoEncoder object from inherited base classes: nn with example: obj = AutoEncoder(item_emb, n_cate, in_dims, out_dims, device, act_func, reparam, dropout)