Skip to content

Commit dab8518

Browse files
committed
modify docstring and latex
1 parent f892292 commit dab8518

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/metrax/ranking_metrics.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,30 @@
2323

2424
@flax.struct.dataclass
2525
class DCGAtK(base.Average):
26-
r"""Computes DCG@k (Discounted Cumulative Gain at k) metrics.
26+
r"""Computes Discounted Cumulative Gain at k metric.
2727
28-
This implementation calculates DCG@k based on the principle:
29-
$DCG@k(y, s) = \sum_{i | \text{rank}(s_i) \le k} \text{gain}(y_i) \times
30-
\text{rank\_discount}(\text{rank}(s_i))$
31-
where $y_i$ is the label of item $i$, $s_i$ is its score,
32-
and $\text{rank}(s_i)$ is the 1-based rank of item $i$ based on its score.
28+
DCG tells how good a list of search results or recommendations is, based on
29+
the relevance of the items and their positions in the list.
3330
34-
The gain is $gain(y_i) = 2^{y_i} - 1$.
35-
The rank_discount is $1 / \log_2(\text{rank} + 1)$.
31+
This implementation calculates :math:`DCG@k` based on the following formula:
32+
33+
.. math::
34+
DCG@K(y, s) = \sum_{i=1}^{K} \text{gain}(y_i) \times
35+
\text{rank_discount}(\text{rank}(s_i))
36+
37+
where
38+
39+
- :math:`y_i` is the relevance label from the labels,
40+
- :math:`s_i` is its score from the prediction,
41+
- :math:`\text{rank}(s_i)` is the 1-based rank of item :math:`i`.
42+
- :math:`\text{gain}(y_i) = 2^{y_i} - 1`.
43+
- :math:`\text{rank_discount}(\text{rank}(s_i)) = \frac{1}{\log_2(\text{rank}(s_i) + 1)}`.
44+
45+
We get the final formula:
46+
47+
.. math::
48+
DCG@K(y, s) = \sum_{i=1}^{K} \frac{2^{y_i} - 1}{\log_2(\text{rank}(s_i) +
49+
1)}
3650
"""
3751

3852
@classmethod

0 commit comments

Comments
 (0)