class_docstr: Discounted cumulative gain (DCG).
  
  Discounted cumulative gain ([Järvelin et al, 2002][jarvelin2002]).
  
  For each list of scores `s` in `y_pred` and list of labels `y` in `y_true`:
  
  ```
  DCG(y, s) = sum_i gain(y_i) * rank_discount(rank(s_i))
  ```
  
  NOTE: The `gain_fn` and `rank_discount_fn` should be keras serializable.
  Please see `tfr.keras.utils.pow_minus_1` and `tfr.keras.utils.log2_inverse` as
  examples when defining user customized functions.
  
  Standalone usage:
  
  >>> y_true = [[0., 1., 1.]]
  >>> y_pred = [[3., 1., 2.]]
  >>> dcg = tfr.keras.metrics.DCGMetric()
  >>> dcg(y_true, y_pred).numpy()
  1.1309297
  
  >>> # Using ragged tensors
  >>> y_true = tf.ragged.constant([[0., 1.], [1., 2., 0.]])
  >>> y_pred = tf.ragged.constant([[2., 1.], [2., 5., 4.]])
  >>> dcg = tfr.keras.metrics.DCGMetric(ragged=True)
  >>> dcg(y_true, y_pred).numpy()
  2.065465
  
  Usage with the `compile()` API:
  
  ```python
  model.compile(optimizer='sgd', metrics=[tfr.keras.metrics.DCGMetric()])
  ```
  
  Definition:
  
  $$
  \text{DCG}(\{y\}, \{s\}) =
  \sum_i \text{gain}(y_i) \cdot \text{rank_discount}(\text{rank}(s_i))
  $$
  
  where $\text{rank}(s_i)$ is the rank of item $i$ after sorting by scores
  $s$ with ties broken randomly.
  
  References:
  
    - [Cumulated gain-based evaluation of IR techniques, Järvelin et al,
       2002][jarvelin2002]
  
  [jarvelin2002]: https://dl.acm.org/doi/10.1145/582415.582418
class_docstr_tok: ["Discounted","cumulative","gain","(","DCG",")",".","Discounted","cumulative","gain","(","[","J\u00e4rvelin","et","al",",","2002","]","[","jarvelin2002","]",")",".","For","each","list","of","scores","`","s","`","in","`","y_pred","`","and","list","of","labels","`","y","`","in","`","y_true","`",":","``","`","DCG","(","y",",","s",")","=","sum_i","gain","(","y_i",")","*","rank_discount","(","rank","(","s_i",")",")","``","`","NOTE",":","The","`","gain_fn","`","and","`","rank_discount_fn","`","should","be","keras","serializable",".","Please","see","`","tfr.keras.utils.pow_minus_1","`","and","`","tfr.keras.utils.log2_inverse","`","as","examples","when","defining","user","customized","functions",".","Standalone","usage",":",">",">",">","y_true","=","[","[","0.",",","1.",",","1",".","]","]",">",">",">","y_pred","=","[","[","3.",",","1.",",","2",".","]","]",">",">",">","dcg","=","tfr.keras.metrics.DCGMetric","(",")",">",">",">","dcg","(","y_true",",","y_pred",")",".numpy","(",")","1.1309297",">",">",">","#","Using","ragged","tensors",">",">",">","y_true","=","tf.ragged.constant","(","[","[","0.",",","1",".","]",",","[","1.",",","2.",",","0",".","]","]",")",">",">",">","y_pred","=","tf.ragged.constant","(","[","[","2.",",","1",".","]",",","[","2.",",","5.",",","4",".","]","]",")",">",">",">","dcg","=","tfr.keras.metrics.DCGMetric","(","ragged=True",")",">",">",">","dcg","(","y_true",",","y_pred",")",".numpy","(",")","2.065465","Usage","with","the","`","compile","(",")","`","API",":","``","`","python","model.compile","(","optimizer='sgd","'",",","metrics=","[","tfr.keras.metrics.DCGMetric","(",")","]",")","``","`","Definition",":","$","$","\\text","{","DCG","}","(","\\","{","y\\","}",",","\\","{","s\\","}",")","=","\\sum_i","\\text","{","gain","}","(","y_i",")","\\cdot","\\text","{","rank_discount","}","(","\\text","{","rank","}","(","s_i",")",")","$","$","where","$","\\text","{","rank","}","(","s_i",")","$","is","the","rank","of","item","$","i","$","after","sorting","by","scores","$","s","$","with","ties","broken","randomly",".","References",":","-","[","Cumulated","gain-based","evaluation","of","IR","techniques",",","J\u00e4rvelin","et","al",",","2002","]","[","jarvelin2002","]","[","jarvelin2002","]",":","https",":","\/\/dl.acm.org\/doi\/10.1145\/582415.582418"]
code: def get_config(self):
      base_config = super(DCGMetric, self).get_config()
      config = {
          "topn": self._topn,
          "gain_fn": self._gain_fn,
          "rank_discount_fn": self._rank_discount_fn,
      }
      config.update(base_config)
      return config
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Any, Dict, List, Optional
  import tensorflow.compat.v2
  from tensorflow_ranking.python import metrics_impl
  from tensorflow_ranking.python.keras import utils
label_desc: Use image node_id 2 for calling the DCGMetric obj's underlying member method code with example usage: obj.get_config() and returns: config