recpack.algorithms.loss_functions.vae_loss

recpack.algorithms.loss_functions.vae_loss(reconstructed_X, mu, logvar, X, anneal=1.0)

VAE loss function for use with Auto Encoders.

Loss defined in ‘Variational Autoencoders for Collaborative Filtering’, D. Liang et al. @ KDD2018. Uses a combination of Binary Cross Entropy loss and Kullback–Leibler divergence (relative entropy).

Parameters
  • reconstructed_X (torch.Tensor) – The reconstructed matrix X

  • mu (torch.Tensor) – The mean tensor

  • logvar (torch.Tensor) – The variance Tensor.

  • X (torch.Tensor) – The matrix to reconstruct

  • anneal (float, optional) – multiplicative factor for the KLD part of the loss function, defaults to 1.0

Returns

The loss as a 0D tensor

Return type

torch.Tensor