Repository: Lightning-AI/torchmetrics

Issue:
Specificity if TN + FN = 0
The specificity is defined as $\text{Specificity} = \frac{\text{TN}}{\text{TN} + \text{FP}}$. As far as I see, in case $\text{FP} = 0$, the specificity should be 1. 

The docs say that in case $\text{FP} + \text{TP} = 0$, the metric is not defined (see reference below). To put this into words, this means that if the dataset does not contain any positive samples, the metric is not defined and it will return 0. 

Is this really intended? It might be a weird edge case. But from the metric definition, I see no argument why the metric should not be defined in case there are no positive samples in the data. In case $\text{FP} + \text{TP} = 0$, I think the metric should return 1, not 0.

`torchmetrics` version: 1.3.2
https://github.com/Lightning-AI/torchmetrics/blob/c1f83341c5c5d62bc711d3bd6288291b81e29c1a/src/torchmetrics/classification/specificity.py#L450-L459
Specificity if TN + FN = 0
The specificity is defined as $\text{Specificity} = \frac{\text{TN}}{\text{TN} + \text{FP}}$. As far as I see, in case $\text{FP} = 0$, the specificity should be 1. 

The docs say that in case $\text{FP} + \text{TP} = 0$, the metric is not defined (see reference below). To put this into words, this means that if the dataset does not contain any positive samples, the metric is not defined and it will return 0. 

Is this really intended? It might be a weird edge case. But from the metric definition, I see no argument why the metric should not be defined in case there are no positive samples in the data. In case $\text{FP} + \text{TP} = 0$, I think the metric should return 1, not 0.

`torchmetrics` version: 1.3.2
https://github.com/Lightning-AI/torchmetrics/blob/c1f83341c5c5d62bc711d3bd6288291b81e29c1a/src/torchmetrics/classification/specificity.py#L450-L459


Discussion:
I just saw that this might be just a documentation issue. The classes `BinarySpecificity`, `MulticlassSpecificity`, and `Multilabelspecificity` all have the correct description:

https://github.com/Lightning-AI/torchmetrics/blob/c1f83341c5c5d62bc711d3bd6288291b81e29c1a/src/torchmetrics/classification/specificity.py#L31-L39

Also, the implementation seems to follow this definition.
I just saw that this might be just a documentation issue. The classes `BinarySpecificity`, `MulticlassSpecificity`, and `Multilabelspecificity` all have the correct description:

https://github.com/Lightning-AI/torchmetrics/blob/c1f83341c5c5d62bc711d3bd6288291b81e29c1a/src/torchmetrics/classification/specificity.py#L31-L39

Also, the implementation seems to follow this definition.

Resolving patch:
diff --git a/src/torchmetrics/classification/specificity.py b/src/torchmetrics/classification/specificity.py
--- a/src/torchmetrics/classification/specificity.py
+++ b/src/torchmetrics/classification/specificity.py
@@ -453,7 +453,7 @@ class Specificity(_ClassificationTaskWrapper):
     .. math:: \text{Specificity} = \frac{\text{TN}}{\text{TN} + \text{FP}}
 
     Where :math:`\text{TN}` and :math:`\text{FP}` represent the number of true negatives and false positives
-    respectively. The metric is only proper defined when :math:`\text{TP} + \text{FP} \neq 0`. If this case is
+    respectively. The metric is only proper defined when :math:`\text{TN} + \text{FP} \neq 0`. If this case is
     encountered for any class/label, the metric for that class/label will be set to 0 and the overall metric may
     therefore be affected in turn.
 


Test patch: