docstr: compute and return the ranking scores for one query.
  for definition of these metrics, please refer to
  https://www.cs.cornell.edu/courses/cs4300/2013fa/lectures/metrics-2-4pp.pdf
  
  Parameters
  ----------
  idx:
      the index of the query
  k:
      the cutoff value for NDCG, MAP, Recall, MRR, and Precision
  
  Returns
  -------
  Computed score.
docstr_tok: ["compute","and","return","the","ranking","scores","for","one","query",".","for","definition","of","these","metrics",",","please","refer","to","https",":","\/\/www.cs.cornell.edu\/courses\/cs4300\/2013fa\/lectures\/metrics-2-4pp.pdf","Parameters","--","--","--","--","--","idx",":","the","index","of","the","query","k",":","the","cutoff","value","for","NDCG",",","MAP",",","Recall",",","MRR",",","and","Precision","Returns","--","--","--","-","Computed","score","."]
code: def _compute_one(self, idx, k):
      """
      compute and return the ranking scores for one query.
      for definition of these metrics, please refer to
      https://www.cs.cornell.edu/courses/cs4300/2013fa/lectures/metrics-2-4pp.pdf
  
      Parameters
      ----------
      idx:
          the index of the query
      k:
          the cutoff value for NDCG, MAP, Recall, MRR, and Precision
  
      Returns
      -------
      Computed score.
      """
      precision, recall, mrr, mAP, ndcg = 0, 0, 0, 0, 0
      target, pred = self.results[idx][0], self.results[idx][1]
  
      # sort the ground truth and predictions in descending order
      sorted_target = dict(
          sorted(
              target.items(),
              key=operator.itemgetter(1),
              reverse=self.is_higher_better,
          )
      )
      sorted_pred = dict(
          sorted(
              pred.items(),
              key=operator.itemgetter(1),
              reverse=self.is_higher_better,
          )
      )
      sorted_target_values = list(sorted_target.values())
      sorted_pred_values = list(sorted_pred.values())
  
      # number of positive relevance in target
      # negative numbers and zero are considered as negative response
      num_pos_target = len(
          [val for val in sorted_target_values if val > 0]
      )
  
      at_k = k if num_pos_target > k else num_pos_target
  
      first_k_items_list = list(sorted_pred.items())[0:k]
  
      rank = 0
      hit_rank = []  # correctly retrieved items
      for key, value in first_k_items_list:
          if key in sorted_target and sorted_target[key] > 0:
              hit_rank.append(rank)
          rank += 1
      count = len(hit_rank)
      # compute the precision and recall
      precision = count / k
      recall = count / num_pos_target
  
      dcg = 0
      if hit_rank:  # not empty
          # compute the mean reciprocal rank
          mrr = 1 / (hit_rank[0] + 1)
          # compute the mean average precision
          mAP = np.sum(
              [
                  sorted_pred_values[rank] * (i + 1) / (rank + 1)
                  for i, rank in enumerate(hit_rank)
              ]
          )
          # compute the discounted cumulative gain
          dcg = np.sum([1 / math.log(rank + 2, 2) for rank in hit_rank])
  
      # compute the ideal discounted cumulative gain
      idcg = np.sum([1 / math.log(i + 2, 2) for i in range(at_k)])
      # compute the normalized discounted cumulative gain
      ndcg = dcg / idcg
      mAP /= at_k
  
      return precision, recall, mrr, mAP, ndcg
  
imports: import logging
  import math
  import operator
  import warnings
  from typing import Dict, List, Optional, Tuple, Union
  import evaluate
  import numpy
  from sklearn.metrics import f1_score
  from autogluon.core.metrics import Scorer, get_metric
  from ..constants import ACCURACY, AVERAGE_PRECISION, BINARY, DIRECT_LOSS, F1, FEW_SHOT_CLASSIFICATION, IOU, MAP, MATCHING_METRICS, MATCHING_METRICS_WITHOUT_PROBLEM_TYPE, MAX, METRIC_MODE_MAP, MIN, MULTICLASS, NDCG, NER, NER_TOKEN_F1, NUMERICAL, OBJECT_DETECTION, OPEN_VOCABULARY_OBJECT_DETECTION, OVERALL_ACCURACY, OVERALL_F1, PRECISION, RECALL, REGRESSION, RETRIEVAL_METRICS, RMSE, ROC_AUC, SEMANTIC_SEGMENTATION, SPEARMANR, Y_PRED, Y_PRED_PROB, Y_TRUE
  from ..problem_types import PROBLEM_TYPES_REG
label_desc: Use image node_id 3 for calling the RankingMetrics obj's underlying member method code with example usage: obj._compute_one(idx, k) and returns: precision,  recall,  mrr,  mAP,  ndcg