class_docstr: Alpha discounted cumulative gain (alphaDCG).
  
  Alpha discounted cumulative gain ([Clarke et al, 2008][clarke2008];
  [Clarke et al, 2009][clarke2009]) is a cumulative gain metric that operates
  on subtopics and is typically used for diversification tasks.
  
  For each list of scores `s` in `y_pred` and list of labels `y` in `y_true`:
  
  ```
  alphaDCG(y, s) = sum_t sum_i gain(y_{i,t}) * rank_discount(rank(s_i))
  gain(y_{i,t}) = (1 - alpha)^(sum_j I[rank(s_j) < rank(s_i)] * gain(y_{j,t}))
  ```
  
  NOTE: The labels `y_true` should be of shape
  `[batch_size, list_size, subtopic_size]`, indicating relevance for each
  subtopic in the last dimension.
  
  NOTE: The `rank_discount_fn` should be keras serializable. Please see
  `tfr.keras.utils.log2_inverse` as an example when defining user customized
  functions.
  
  Standalone usage:
  
  >>> y_true = [[[0., 1.], [1., 0.], [1., 1.]]]
  >>> y_pred = [[3., 1., 2.]]
  >>> alpha_dcg = tfr.keras.metrics.AlphaDCGMetric()
  >>> alpha_dcg(y_true, y_pred).numpy()
  2.1963947
  
  >>> # Using ragged tensors
  >>> y_true = tf.ragged.constant(
  ...   [[[0., 0.], [1., 0.]], [[1., 1.], [0., 2.], [1., 0.]]])
  >>> y_pred = tf.ragged.constant([[2., 1.], [2., 5., 4.]])
  >>> alpha_dcg = tfr.keras.metrics.AlphaDCGMetric(ragged=True)
  >>> alpha_dcg(y_true, y_pred).numpy()
  1.8184297
  
  Usage with the `compile()` API:
  
  ```python
  model.compile(optimizer='sgd', metrics=[tfr.keras.metrics.AlphaDCGMetric()])
  ```
  
  Definition:
  
  $$
  \alpha\text{DCG}(y, s) =
  \sum_t \sum_i \text{gain}(y_{i, t}, \alpha)
  \text{ rank_discount}(\text{rank}(s_i))\\
  \text{gain}(y_{i, t}, \alpha) =
  y_{i, t} (1 - \alpha)^{\sum_j I[\text{rank}(s_j) < \text{rank}(s_i)] y_{j, t}}
  $$
  
  where $\text{rank}(s_i)$ is the rank of item $i$ after sorting by scores
  $s$ with ties broken randomly and $I[]$ is the indicator function:
  
  $$
  I[\text{cond}] = \begin{cases}
  1 & \text{if cond is true}\\
  0 & \text{else}\end{cases}
  $$
  
  References:
  
    - [Novelty and diversity in information retrieval evaluation, Clarke et al,
       2008][clarke2008]
    - [Overview of the TREC 2009 Web Track, Clarke et al, 2009][clarke2009]
  
  [clarke2008]: https://dl.acm.org/doi/10.1145/1390334.1390446
  [clarke2009]: https://trec.nist.gov/pubs/trec18/papers/ENT09.OVERVIEW.pdf
class_docstr_tok: ["Alpha","discounted","cumulative","gain","(","alphaDCG",")",".","Alpha","discounted","cumulative","gain","(","[","Clarke","et","al",",","2008","]","[","clarke2008","]",";","[","Clarke","et","al",",","2009","]","[","clarke2009","]",")","is","a","cumulative","gain","metric","that","operates","on","subtopics","and","is","typically","used","for","diversification","tasks",".","For","each","list","of","scores","`","s","`","in","`","y_pred","`","and","list","of","labels","`","y","`","in","`","y_true","`",":","``","`","alphaDCG","(","y",",","s",")","=","sum_t","sum_i","gain","(","y_","{","i",",","t","}",")","*","rank_discount","(","rank","(","s_i",")",")","gain","(","y_","{","i",",","t","}",")","=","(","1","-","alpha",")","^","(","sum_j","I","[","rank","(","s_j",")","<","rank","(","s_i",")","]","*","gain","(","y_","{","j",",","t","}",")",")","``","`","NOTE",":","The","labels","`","y_true","`","should","be","of","shape","`","[","batch_size",",","list_size",",","subtopic_size","]","`",",","indicating","relevance","for","each","subtopic","in","the","last","dimension",".","NOTE",":","The","`","rank_discount_fn","`","should","be","keras","serializable",".","Please","see","`","tfr.keras.utils.log2_inverse","`","as","an","example","when","defining","user","customized","functions",".","Standalone","usage",":",">",">",">","y_true","=","[","[","[","0.",",","1",".","]",",","[","1.",",","0",".","]",",","[","1.",",","1",".","]","]","]",">",">",">","y_pred","=","[","[","3.",",","1.",",","2",".","]","]",">",">",">","alpha_dcg","=","tfr.keras.metrics.AlphaDCGMetric","(",")",">",">",">","alpha_dcg","(","y_true",",","y_pred",")",".numpy","(",")","2.1963947",">",">",">","#","Using","ragged","tensors",">",">",">","y_true","=","tf.ragged.constant","(","...","[","[","[","0.",",","0",".","]",",","[","1.",",","0",".","]","]",",","[","[","1.",",","1",".","]",",","[","0.",",","2",".","]",",","[","1.",",","0",".","]","]","]",")",">",">",">","y_pred","=","tf.ragged.constant","(","[","[","2.",",","1",".","]",",","[","2.",",","5.",",","4",".","]","]",")",">",">",">","alpha_dcg","=","tfr.keras.metrics.AlphaDCGMetric","(","ragged=True",")",">",">",">","alpha_dcg","(","y_true",",","y_pred",")",".numpy","(",")","1.8184297","Usage","with","the","`","compile","(",")","`","API",":","``","`","python","model.compile","(","optimizer='sgd","'",",","metrics=","[","tfr.keras.metrics.AlphaDCGMetric","(",")","]",")","``","`","Definition",":","$","$","\\alpha\\text","{","DCG","}","(","y",",","s",")","=","\\sum_t","\\sum_i","\\text","{","gain","}","(","y_","{","i",",","t","}",",","\\alpha",")","\\text","{","rank_discount","}","(","\\text","{","rank","}","(","s_i",")",")","\\\\","\\text","{","gain","}","(","y_","{","i",",","t","}",",","\\alpha",")","=","y_","{","i",",","t","}","(","1","-","\\alpha",")","^","{","\\sum_j","I","[","\\text","{","rank","}","(","s_j",")","<","\\text","{","rank","}","(","s_i",")","]","y_","{","j",",","t","}","}","$","$","where","$","\\text","{","rank","}","(","s_i",")","$","is","the","rank","of","item","$","i","$","after","sorting","by","scores","$","s","$","with","ties","broken","randomly","and","$","I","[","]","$","is","the","indicator","function",":","$","$","I","[","\\text","{","cond","}","]","=","\\begin","{","cases","}","1","&","\\text","{","if","cond","is","true","}","\\\\","0","&","\\text","{","else","}","\\end","{","cases","}","$","$","References",":","-","[","Novelty","and","diversity","in","information","retrieval","evaluation",",","Clarke","et","al",",","2008","]","[","clarke2008","]","-","[","Overview","of","the","TREC","2009","Web","Track",",","Clarke","et","al",",","2009","]","[","clarke2009","]","[","clarke2008","]",":","https",":","\/\/dl.acm.org\/doi\/10.1145\/1390334.1390446","[","clarke2009","]",":","https",":","\/\/trec.nist.gov\/pubs\/trec18\/papers\/ENT09.OVERVIEW.pdf"]
code: def get_config(self):
      config = super(AlphaDCGMetric, self).get_config()
      config.update(
          {
              "topn": self._topn,
              "alpha": self._alpha,
              "rank_discount_fn": self._rank_discount_fn,
              "seed": self._seed,
          }
      )
      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 AlphaDCGMetric obj's underlying member method code with example usage: obj.get_config() and returns: config