class_docstr: Computes normalized discounted cumulative gain.
class_docstr_tok: ["Computes","normalized","discounted","cumulative","gain","."]
docstr: Calculate nDCG@k, based on given rank and gain values.
  
  Args:
    values: A list of tuples representing rank order and gain values.
    k: The maximum position to consider in calculating nDCG
  
  Returns:
    The value of nDCG@k, for the given list of values.
docstr_tok: ["Calculate","nDCG","@","k",",","based","on","given","rank","and","gain","values",".","Args",":","values",":","A","list","of","tuples","representing","rank","order","and","gain","values",".","k",":","The","maximum","position","to","consider","in","calculating","nDCG","Returns",":","The","value","of","nDCG","@","k",",","for","the","given","list","of","values","."]
code: def _calculate_ndcg(
      self, values: List[Tuple[int, float]], k: int
  ) -> float:
      """Calculate nDCG@k, based on given rank and gain values.
  
      Args:
        values: A list of tuples representing rank order and gain values.
        k: The maximum position to consider in calculating nDCG
  
      Returns:
        The value of nDCG@k, for the given list of values.
      """
      max_rank = min(k, len(values))
      ranked_values = [
          gain
          for _, gain in sorted(
              values, key=lambda x: x[0], reverse=False
          )
      ]
      optimal_values = [
          gain
          for _, gain in sorted(
              values, key=lambda x: x[1], reverse=True
          )
      ]
      dcg = self._calculate_dcg_at_k(max_rank, ranked_values)
      optimal_dcg = self._calculate_dcg_at_k(max_rank, optimal_values)
      if optimal_dcg > 0:
          return dcg / optimal_dcg
      else:
          return 0
  
file_path: model-analysis/tensorflow_model_analysis/evaluators/query_metrics/ndcg.py
imports: from typing import Any, Dict, Iterable, List, NamedTuple, Tuple
  import apache_beam
  import numpy
  from tensorflow_model_analysis.evaluators.query_metrics import query_types
  from tensorflow_model_analysis.post_export_metrics import metric_keys
label_desc: Use image node_id 3 for calling the NdcgMetricCombineFn obj's underlying member method code with example usage: obj._calculate_ndcg(values, k) and returns: unknown, int