class_docstr: A rank-based evaluator for KGE models.
class_docstr_tok: ["A","rank-based","evaluator","for","KGE","models","."]
docstr: Initialize rank-based evaluator.
  
  :param filtered:
      Whether to use the filtered evaluation protocol. If enabled, ranking another true triple higher than the
      currently considered one will not decrease the score.
  :param metrics:
      the rank-based metrics to compute
  :param metrics_kwargs:
      additional keyword parameter
  :param add_defaults:
      whether to add all default metrics besides the ones specified by `metrics` / `metrics_kwargs`.
  :param clear_on_finalize:
      whether to clear buffers on `finalize` call
  
      .. warning ::
          disabling this option may lead to memory leaks and incorrect results when used from the pipeline
  
  :param kwargs:
      Additional keyword arguments that are passed to the base class.
code: def __init__(
      self,
      filtered: bool = True,
      metrics: Optional[Sequence[HintOrType[RankBasedMetric]]] = None,
      metrics_kwargs: OptionalKwargs = None,
      add_defaults: bool = True,
      clear_on_finalize: bool = True,
      **kwargs,
  ):
      """Initialize rank-based evaluator.
  
      :param filtered:
          Whether to use the filtered evaluation protocol. If enabled, ranking another true triple higher than the
          currently considered one will not decrease the score.
      :param metrics:
          the rank-based metrics to compute
      :param metrics_kwargs:
          additional keyword parameter
      :param add_defaults:
          whether to add all default metrics besides the ones specified by `metrics` / `metrics_kwargs`.
      :param clear_on_finalize:
          whether to clear buffers on `finalize` call
  
          .. warning ::
              disabling this option may lead to memory leaks and incorrect results when used from the pipeline
  
      :param kwargs:
          Additional keyword arguments that are passed to the base class.
      """
      super().__init__(
          filtered=filtered,
          requires_positive_mask=False,
          **kwargs,
      )
      if metrics is None:
          add_defaults = True
          metrics = []
      self.metrics = rank_based_metric_resolver.make_many(
          metrics, metrics_kwargs
      )
      if add_defaults:
          hits_at_k_keys = [
              rank_based_metric_resolver.normalize_cls(cls)
              for cls in HITS_METRICS
          ]
          ks = (1, 3, 5, 10)
          metrics = [
              key
              for key in rank_based_metric_resolver.lookup_dict
              if key not in hits_at_k_keys
          ]
          metrics_kwargs = [None] * len(metrics)
          for hits_at_k_key in hits_at_k_keys:
              metrics += [hits_at_k_key] * len(ks)
              metrics_kwargs += [dict(k=k) for k in ks]
          self.metrics.extend(
              rank_based_metric_resolver.make_many(
                  metrics, metrics_kwargs
              )
          )
      self.ranks = defaultdict(list)
      self.num_candidates = defaultdict(list)
      self.num_entities = None
      self.clear_on_finalize = clear_on_finalize
  
imports: from __future__ import annotations
  import functools
  import itertools
  import logging
  import math
  import random
  import re
  from collections import defaultdict
  from typing import Callable, DefaultDict, Iterable, List, Mapping, MutableMapping, NamedTuple, Optional, Sequence, Tuple, Type, TypeVar, Union, cast
  import numpy
  import numpy.random
  import pandas
  import torch
  from class_resolver import HintOrType, OptionalKwargs
  from .evaluator import Evaluator, MetricResults, prepare_filter_triples
  from .ranks import Ranks
  from ..constants import COLUMN_LABELS, TARGET_TO_KEY_LABELS, TARGET_TO_KEYS
  from ..metrics.ranking import HITS_METRICS, RankBasedMetric, rank_based_metric_resolver
  from ..metrics.utils import Metric
  from ..triples.triples_factory import CoreTriplesFactory
  from ..typing import LABEL_HEAD, LABEL_TAIL, RANK_REALISTIC, RANK_TYPE_SYNONYMS, RANK_TYPES, SIDE_BOTH, SIDES, ExtendedTarget, MappedTriples, RankType, Target, normalize_rank_type, normalize_target
label_desc: Use image node_id 1 to create a new RankBasedEvaluator object from inherited base classes: Evaluator with example: obj = RankBasedEvaluator(filtered, metrics, metrics_kwargs, add_defaults, clear_on_finalize)