ExpectedLikelihood
- class ExpectedLikelihood(exact: bool = True)[source]
Bases:
KG2ESimilarity
Compute the similarity based on expected likelihood.
Denoting \(\mu = \mu_e - \mu_r\) and \(\Sigma = \Sigma_e + \Sigma_t\), it is given by
\[sim(\mathcal{N}(\mu_e, \Sigma_e),~\mathcal{N}(\mu_r, \Sigma_r))) = \frac{1}{2} \left( \mu^T\Sigma^{-1}\mu + \log \det \Sigma + d \log (2 \pi) \right)\]Initialize the similarity module.
- Parameters:
exact (bool) – Whether to return the exact similarity, or leave out constant offsets for slightly improved speed.
Methods Summary
forward
(h, r, t)Calculate the similarity.
Methods Documentation
- forward(h: GaussianDistribution, r: GaussianDistribution, t: GaussianDistribution) Tensor [source]
Calculate the similarity.
# noqa: DAR401
- Parameters:
h (GaussianDistribution) – shape: (*batch_dims, d) The head entity Gaussian distribution.
r (GaussianDistribution) – shape: (*batch_dims, d) The relation Gaussian distribution.
t (GaussianDistribution) – shape: (*batch_dims, d) The tail entity Gaussian distribution.
- Returns:
torch.Tensor, shape: (*batch_dims) # noqa: DAR202 The similarity.
- Return type: