class_docstr: Ranks for different ranking types.
class_docstr_tok: ["Ranks","for","different","ranking","types","."]
docstr: Compute ranks given scores.
  
  :param true_score: torch.Tensor, shape: (batch_size, 1)
      The score of the true triple.
  :param all_scores: torch.Tensor, shape: (batch_size, num_entities)
      The scores of all corrupted triples (including the true triple).
  
  :return:
      a data structure containing the (filtered) ranks.
docstr_tok: ["Compute","ranks","given","scores",".",":","param","true_score",":","torch.Tensor",",","shape",":","(","batch_size",",","1",")","The","score","of","the","true","triple",".",":","param","all_scores",":","torch.Tensor",",","shape",":","(","batch_size",",","num_entities",")","The","scores","of","all","corrupted","triples","(","including","the","true","triple",")",".",":","return",":","a","data","structure","containing","the","(","filtered",")","ranks","."]
code: def from_scores(
      cls,
      true_score: torch.FloatTensor,
      all_scores: torch.FloatTensor,
  ) -> "Ranks":
      """Compute ranks given scores.
  
      :param true_score: torch.Tensor, shape: (batch_size, 1)
          The score of the true triple.
      :param all_scores: torch.Tensor, shape: (batch_size, num_entities)
          The scores of all corrupted triples (including the true triple).
  
      :return:
          a data structure containing the (filtered) ranks.
      """
      # The optimistic rank is the rank when assuming all options with an
      # equal score are placed behind the currently considered. Hence, the
      # rank is the number of options with better scores, plus one, as the
      # rank is one-based.
      optimistic_rank = (all_scores > true_score).sum(dim=1) + 1
  
      # The pessimistic rank is the rank when assuming all options with an
      # equal score are placed in front of the currently considered. Hence,
      # the rank is the number of options which have at least the same score
      # minus one (as the currently considered option in included in all
      # options). As the rank is one-based, we have to add 1, which nullifies
      # the "minus 1" from before.
      pessimistic_rank = (all_scores >= true_score).sum(dim=1)
  
      # The realistic rank is the average of the optimistic and pessimistic
      # rank, and hence the expected rank over all permutations of the elements
      # with the same score as the currently considered option.
      realistic_rank = (
          optimistic_rank + pessimistic_rank
      ).float() * 0.5
  
      # We set values which should be ignored to NaN, hence the number of options
      # which should be considered is given by
      number_of_options = torch.isfinite(all_scores).sum(dim=1)
  
      return cls(
          optimistic=optimistic_rank,
          pessimistic=pessimistic_rank,
          realistic=realistic_rank,
          number_of_options=number_of_options,
      )
  
file_path: pykeen/src/pykeen/evaluation/ranks.py
imports: from dataclasses import dataclass
  from typing import Iterable, Mapping, Tuple, Union
  import torch
  from ..typing import RANK_OPTIMISTIC, RANK_PESSIMISTIC, RANK_REALISTIC, RankType
label_desc: Use image node_id 3 for calling the Ranks obj's underlying member method code with example usage: obj.from_scores(cls, true_score, all_scores) and returns: cls