class_docstr: Score based on marginal distributions.
  
  To predict scores for the tails, we make the following simplification of $P(t | h, r)$:
  
  .. math ::
      P(t | h, r) \sim P(t | h) * P(t | r)
  
  Depending on the settings, we either set $P(t | *) = \frac{1}{n}$ where $n$ is the number of entities,
  or estimate them by counting occurrences in the training triples.
  
  .. note ::
      This model cannot make use of GPU acceleration, since internally it uses scipy's sparse matrices.
  
  ---
  name: Marginal Distribution Baseline
  citation:
      author: Berrendorf
      year: 2021
      link: https://github.com/pykeen/pykeen/pull/514
      github: pykeen/pykeen
docstr: Initialize the model.
  
  :param triples_factory:
      The triples factory containing the training triples.
  :param entity_margin:
      whether to compute entity-specific marginal distributions
  :param relation_margin:
      whether to compute relation-specific marginal distributions
  
  If you set ``entity_margin=False`` and ``relation_margin=False``, it will
  lead to a uniform distribution, i.e. equal scores for all entities.
docstr_tok: ["Initialize","the","model",".",":","param","triples_factory",":","The","triples","factory","containing","the","training","triples",".",":","param","entity_margin",":","whether","to","compute","entity-specific","marginal","distributions",":","param","relation_margin",":","whether","to","compute","relation-specific","marginal","distributions","If","you","set","``","entity_margin=False","``","and","``","relation_margin=False","``",",","it","will","lead","to","a","uniform","distribution",",","i.e",".","equal","scores","for","all","entities","."]
code: def __init__(
      self,
      triples_factory: CoreTriplesFactory,
      entity_margin: bool = True,
      relation_margin: bool = True,
  ):
      """
      Initialize the model.
  
      :param triples_factory:
          The triples factory containing the training triples.
      :param entity_margin:
          whether to compute entity-specific marginal distributions
      :param relation_margin:
          whether to compute relation-specific marginal distributions
  
      If you set ``entity_margin=False`` and ``relation_margin=False``, it will
      lead to a uniform distribution, i.e. equal scores for all entities.
      """
      super().__init__(triples_factory=triples_factory)
      h, r, t = numpy.asarray(triples_factory.mapped_triples).T
      if relation_margin:
          self.head_per_relation, self.tail_per_relation = [
              get_csr_matrix(
                  row_indices=r,
                  col_indices=col_indices,
                  shape=(
                      triples_factory.num_relations,
                      triples_factory.num_entities,
                  ),
              )
              for col_indices in (h, t)
          ]
      else:
          self.head_per_relation = self.tail_per_relation = None
      if entity_margin:
          self.head_per_tail, self.tail_per_head = [
              get_csr_matrix(
                  row_indices=row_indices,
                  col_indices=col_indices,
                  shape=(
                      triples_factory.num_entities,
                      triples_factory.num_entities,
                  ),
              )
              for row_indices, col_indices in ((t, h), (h, t))
          ]
      else:
          self.head_per_tail = self.tail_per_head = None
  
imports: from typing import Optional
  import numpy
  import torch
  from .utils import get_csr_matrix, get_relation_similarity, marginal_score
  from ..base import Model
  from ...triples import CoreTriplesFactory
  from ...typing import InductiveMode
label_desc: Use image node_id 1 to create a new MarginalDistributionBaseline object from inherited base classes: EvaluationOnlyModel with example: obj = MarginalDistributionBaseline(triples_factory, entity_margin, relation_margin)