class_docstr: Tests for the vectorized computation of KL divergences.
class_docstr_tok: ["Tests","for","the","vectorized","computation","of","KL","divergences","."]
code: def _get_kl_similarity_torch(self):
      # compute using pytorch
      e_mean = self.h_mean - self.t_mean
      e_var = self.h_var + self.t_var
      r_mean, r_var = self.r_var, self.r_mean
      self.assertTrue((e_var > 0).all())
      sim2 = torch.empty(
          self.batch_size,
          self.num_heads,
          self.num_relations,
          self.num_tails,
      )
      for bi, hi, ri, ti in itertools.product(
          range(self.batch_size),
          range(self.num_heads),
          range(self.num_relations),
          range(self.num_tails),
      ):
          # prepare distributions
          e_loc = e_mean[bi, hi, 0, ti, :]
          r_loc = r_mean[bi, 0, ri, 0, :]
          e_cov = torch.diag(e_var[bi, hi, 0, ti, :])
          r_cov = torch.diag(r_var[bi, 0, ri, 0, :])
          p = torch.distributions.MultivariateNormal(
              loc=e_loc,
              covariance_matrix=e_cov,
          )
          q = torch.distributions.MultivariateNormal(
              loc=r_loc,
              covariance_matrix=r_cov,
          )
          sim2[bi, hi, ri, ti] = -torch.distributions.kl_divergence(
              p=p, q=q
          ).view(-1)
      return sim2
  
file_path: pykeen/tests/test_nn/test_sim.py
imports: import itertools
  import unittest
  import torch
  from pykeen.nn.sim import _torch_kl_similarity, kullback_leibler_similarity
  from pykeen.typing import GaussianDistribution
  from pykeen.utils import convert_to_canonical_shape
label_desc: Use image node_id 3 for calling the KullbackLeiblerTests obj's underlying member method code with example usage: obj._get_kl_similarity_torch() and returns: sim2