code: def expected_likelihood(
      h: GaussianDistribution,
      r: GaussianDistribution,
      t: GaussianDistribution,
      exact: bool = True,
  ) -> torch.FloatTensor:
      r"""Compute the similarity based on expected likelihood.
  
      .. math::
  
          D((\mu_e, \Sigma_e), (\mu_r, \Sigma_r)))
          = \frac{1}{2} \left(
              (\mu_e - \mu_r)^T(\Sigma_e + \Sigma_r)^{-1}(\mu_e - \mu_r)
              + \log \det (\Sigma_e + \Sigma_r) + d \log (2 \pi)
          \right)
          = \frac{1}{2} \left(
              \mu^T\Sigma^{-1}\mu
              + \log \det \Sigma + d \log (2 \pi)
          \right)
  
      with :math:`\mu_e = \mu_h - \mu_t` and :math:`\Sigma_e = \Sigma_h + \Sigma_t`.
  
      :param h: shape: (batch_size, num_heads, 1, 1, d)
          The head entity Gaussian distribution.
      :param r: shape: (batch_size, 1, num_relations, 1, d)
          The relation Gaussian distribution.
      :param t: shape: (batch_size, 1, 1, num_tails, d)
          The tail entity Gaussian distribution.
      :param exact:
          Whether to return the exact similarity, or leave out constant offsets.
  
      :return: torch.Tensor, shape: (batch_size, num_heads, num_relations, num_tails)
          The similarity.
      """
      # subtract, shape: (batch_size, num_heads, num_relations, num_tails, dim)
      var = tensor_sum(*(d.diagonal_covariance for d in (h, r, t)))
      mean = tensor_sum(h.mean, -t.mean, -r.mean)
  
      #: a = \mu^T\Sigma^{-1}\mu
      safe_sigma = at_least_eps(var)
      sim = batched_dot(
          a=safe_sigma.reciprocal(),
          b=(mean**2),
      )
  
      #: b = \log \det \Sigma
      sim = sim + safe_sigma.log().sum(dim=-1)
      if exact:
          sim = sim + sim.shape[-1] * math.log(2.0 * math.pi)
      return sim
  
file_path: pykeen/src/pykeen/nn/sim.py
imports: import itertools
  import math
  import torch
  from .compute_kernel import batched_dot
  from ..typing import GaussianDistribution
  from ..utils import at_least_eps, calculate_broadcasted_elementwise_result_shape, tensor_sum
label_desc: Use image node_id 1 for calling a global function with example usage: expected_likelihood(h, r, t, exact) and returns: sim