I am trying to understand the gradient of the Generalized Dice Loss (GDL) shown here Link. It says that the GDL for two classes is: $$ GDL = 1 - 2 \frac{\sum_{l=1}^2w_l \sum_{n=1}^{N} r_{ln}p_{ln}}{\sum_{l=1}^2w_l \sum_{n=1}^{N} r_{ln} + p_{ln}} $$ Also, it says that the gradient with respect to $p_i$ is: $$ \frac{\partial GDL}{\partial p_i} = - 2 \frac{ (w_1^2-w_2^2) \left[ \sum_{n=1}^N p_nr_n - r_i \sum_{n=1}^N (p_n + r_n) \right] + Nw_2(w_1+w_2)(1-2r_i)}{ \left[ (w_1-w_2) \sum_{n=1}^N(p_n+r_n) + 2Nw_2 \right]^2 } $$
My two questions are:
- How this gradient was calculated? Shouldn't it be something like: $$ \frac{\partial GDL}{\partial p_i}= -2\frac{\left[ \sum_{l=1}^2 w_l \sum_{n=1}^{N} r_{ln} + p_{ln} \right] \left( \sum_{l=1}^2 w_l \sum_{n=1}^{N} r_{ln} \right) + \left[ \sum_{l=1}^2 w_l \sum_{n=1}^{N} r_{ln}p_{ln} \right] \left( N \sum_{l=1}^2 w_l \right)}{\left[ \sum_{l=1}^2 w_l \sum_{n=1}^{N} r_{ln} + p_{ln} \right]^2} $$
- I assume that to extend it to more than two classes would be to make $l$ vary from $1$ to $L$, where $L$ is the number of classes. But how is this gradient extended?
Thanks