Bug
normalized_mutual_info_score and adjusted_mutual_info_score return 0.0 for two identical single-cluster labelings, where scikit-learn (the documented reference for these metrics) returns 1.0, a perfect match.
Repro
import torch, numpy as np
import sklearn.metrics as skm
import torchmetrics.functional.clustering as tmc
a = np.array([0, 0, 0, 0]); ta = torch.tensor(a)
print(float(tmc.normalized_mutual_info_score(ta, ta)), skm.normalized_mutual_info_score(a, a)) # 0.0 vs 1.0
print(float(tmc.adjusted_mutual_info_score(ta, ta)), skm.adjusted_mutual_info_score(a, a)) # 0.0 vs 1.0
Why
Both labelings have zero entropy, so they trivially agree. scikit-learn treats this limit case as a perfect match and returns 1.0. torchmetrics falls through to the mutual_info == 0 short-circuit and returns 0.0. The asymmetric case (one single cluster, the other not) already returns 0.0 in both libraries and is correct.
Environment: torchmetrics 1.9.0 / current master.
I have a fix ready and will open a PR referencing this issue.
Bug
normalized_mutual_info_scoreandadjusted_mutual_info_scorereturn0.0for two identical single-cluster labelings, where scikit-learn (the documented reference for these metrics) returns1.0, a perfect match.Repro
Why
Both labelings have zero entropy, so they trivially agree. scikit-learn treats this limit case as a perfect match and returns
1.0. torchmetrics falls through to themutual_info == 0short-circuit and returns0.0. The asymmetric case (one single cluster, the other not) already returns0.0in both libraries and is correct.Environment: torchmetrics 1.9.0 / current
master.I have a fix ready and will open a PR referencing this issue.