class_docstr: Computes normalized discounted cumulative gain.
class_docstr_tok: ["Computes","normalized","discounted","cumulative","gain","."]
code: def add_input(
      self, accumulator: _State, query_fpl: query_types.QueryFPL
  ) -> _State:
      weight = 1.0
      if self._weight_key:
          weights = [
              float(_get_feature_value(fpl, self._weight_key))
              for fpl in query_fpl.fpls
          ]
          if weights:
              if min(weights) != max(weights):
                  raise ValueError(
                      "weights were not identical for all examples in the "
                      "query. query_id was: %s, weights were: %s"
                      % (query_fpl.query_id, weights)
                  )
              weight = weights[0]
  
      ndcg_dict = {}
      for at in self._at_vals:
          rank_gain = [
              (pos + 1, float(_get_feature_value(fpl, self._gain_key)))
              for pos, fpl in enumerate(query_fpl.fpls)
          ]
          ndcg_dict[at] = self._calculate_ndcg(rank_gain, at) * weight
  
      return self._add_states(
          accumulator, _State(ndcg=ndcg_dict, weight=weight)
      )
  
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 7 for calling the NdcgMetricCombineFn obj's underlying member method code with example usage: obj.add_input(accumulator, query_fpl) and returns: self