docstr: compute mrr
  y_pred_neg is an array with shape (batch size, num_entities_neg).
  y_pred_pos is an array with shape (batch size, )
docstr_tok: ["compute","mrr","y_pred_neg","is","an","array","with","shape","(","batch","size",",","num_entities_neg",")",".","y_pred_pos","is","an","array","with","shape","(","batch","size",",",")"]
code: def _eval_mrr(self, y_pred_pos, y_pred_neg, type_info):
      """
      compute mrr
      y_pred_neg is an array with shape (batch size, num_entities_neg).
      y_pred_pos is an array with shape (batch size, )
      """
  
      if type_info == "torch":
          # calculate ranks
          y_pred_pos = y_pred_pos.view(-1, 1)
          # optimistic rank: "how many negatives have a larger score than the positive?"
          # ~> the positive is ranked first among those with equal score
          optimistic_rank = (y_pred_neg > y_pred_pos).sum(dim=1)
          # pessimistic rank: "how many negatives have at least the positive score?"
          # ~> the positive is ranked last among those with equal score
          pessimistic_rank = (y_pred_neg >= y_pred_pos).sum(dim=1)
          ranking_list = 0.5 * (optimistic_rank + pessimistic_rank) + 1
          hits1_list = (ranking_list <= 1).to(torch.float)
          hits3_list = (ranking_list <= 3).to(torch.float)
          hits10_list = (ranking_list <= 10).to(torch.float)
          mrr_list = 1.0 / ranking_list.to(torch.float)
  
          return {
              "hits@1_list": hits1_list,
              "hits@3_list": hits3_list,
              "hits@10_list": hits10_list,
              "mrr_list": mrr_list,
          }
  
      else:
          y_pred_pos = y_pred_pos.reshape(-1, 1)
          optimistic_rank = (y_pred_neg >= y_pred_pos).sum(dim=1)
          pessimistic_rank = (y_pred_neg > y_pred_pos).sum(dim=1)
          ranking_list = 0.5 * (optimistic_rank + pessimistic_rank) + 1
          hits1_list = (ranking_list <= 1).astype(np.float32)
          hits3_list = (ranking_list <= 3).astype(np.float32)
          hits10_list = (ranking_list <= 10).astype(np.float32)
          mrr_list = 1.0 / ranking_list.astype(np.float32)
  
          return {
              "hits@1_list": hits1_list,
              "hits@3_list": hits3_list,
              "hits@10_list": hits10_list,
              "mrr_list": mrr_list,
          }
  
file_path: ogb/ogb/linkproppred/evaluate.py
imports: import os
  import numpy
  import pandas
  from sklearn.metrics import roc_auc_score
label_desc: Use image node_id 7 for calling the Evaluator obj's underlying member method code with example usage: obj._eval_mrr(y_pred_pos, y_pred_neg, type_info) and returns: dict, dict