class_docstr: Collaborative Denoising Auto-Encoder (RecVAE) is a recommendation model
  for top-N recommendation with implicit feedback.
  
  We implement the model following the original author
class_docstr_tok: ["Collaborative","Denoising","Auto-Encoder","(","RecVAE",")","is","a","recommendation","model","for","top-N","recommendation","with","implicit","feedback",".","We","implement","the","model","following","the","original","author"]
code: def calculate_loss(self, interaction, encoder_flag):
      user = interaction[self.USER_ID]
      rating_matrix = self.get_rating_matrix(user)
      if encoder_flag:
          dropout_prob = self.dropout_prob
      else:
          dropout_prob = 0
      x_pred, mu, logvar, z = self.forward(rating_matrix, dropout_prob)
  
      if self.gamma:
          norm = rating_matrix.sum(dim=-1)
          kl_weight = self.gamma * norm
      else:
          kl_weight = self.beta
  
      mll = (
          (F.log_softmax(x_pred, dim=-1) * rating_matrix)
          .sum(dim=-1)
          .mean()
      )
      kld = (
          (log_norm_pdf(z, mu, logvar) - self.prior(rating_matrix, z))
          .sum(dim=-1)
          .mul(kl_weight)
          .mean()
      )
      negative_elbo = -(mll - kld)
  
      return negative_elbo
  
imports: import numpy
  from copy import deepcopy
  import torch
  import torch.nn
  import torch.nn.functional
  from recbole.model.abstract_recommender import GeneralRecommender, AutoEncoderMixin
  from recbole.model.init import xavier_normal_initialization
  from recbole.utils import InputType
label_desc: Use image node_id 4 for calling the RecVAE obj's underlying member method code with example usage: obj.calculate_loss(interaction, encoder_flag) and returns: negative_elbo