Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing higher_is_better attribute to metrics #584

Merged
merged 7 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support for float targets in `nDCG` metric ([#437](https://github.com/PyTorchLightning/metrics/pull/437))
- Added `average` argument to `AveragePrecision` metric for reducing multi-label and multi-class problems ([#477](https://github.com/PyTorchLightning/metrics/pull/477))
- Added `MultioutputWrapper` ([#510](https://github.com/PyTorchLightning/metrics/pull/510))
- Added metric sweeping `higher_is_better` as constant attribute ([#544](https://github.com/PyTorchLightning/metrics/pull/544))
- Added metric sweeping:
- `higher_is_better` as constant attribute ([#544](https://github.com/PyTorchLightning/metrics/pull/544))
- `higher_is_better` to rest of codebase ([#584](https://github.com/PyTorchLightning/metrics/pull/584))
- Added simple aggregation metrics: `SumMetric`, `MeanMetric`, `CatMetric`, `MinMetric`, `MaxMetric` ([#506](https://github.com/PyTorchLightning/metrics/pull/506))
- Added pairwise submodule with metrics ([#553](https://github.com/PyTorchLightning/metrics/pull/553))
- `pairwise_cosine_similarity`
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/audio/snr.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class SNR(Metric):

"""
is_differentiable = True
higher_is_better = True
sum_snr: Tensor
total: Tensor

Expand Down
1 change: 1 addition & 0 deletions torchmetrics/classification/accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class Accuracy(StatScores):

"""
is_differentiable = False
higher_is_better = True
correct: Tensor
total: Tensor

Expand Down
1 change: 1 addition & 0 deletions torchmetrics/classification/auroc.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class AUROC(Metric):

"""
is_differentiable = False
higher_is_better = True
preds: List[Tensor]
target: List[Tensor]

Expand Down
1 change: 1 addition & 0 deletions torchmetrics/classification/calibration_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class CalibrationError(Metric):
default: None (which selects the entire world)
"""
DISTANCES = {"l1", "l2", "max"}
higher_is_better = False
confidences: List[Tensor]
accuracies: List[Tensor]

Expand Down
1 change: 1 addition & 0 deletions torchmetrics/classification/cohen_kappa.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class labels.

"""
is_differentiable = False
higher_is_better = True
confmat: Tensor

def __init__(
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/classification/f_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class F1(FBeta):
"""

is_differentiable = False
higher_is_better = True

def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/classification/hamming_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class HammingDistance(Metric):

"""
is_differentiable = False
higher_is_better = False
correct: Tensor
total: Tensor

Expand Down
1 change: 1 addition & 0 deletions torchmetrics/classification/hinge.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Hinge(Metric):

"""
is_differentiable = True
higher_is_better = False
measure: Tensor
total: Tensor

Expand Down
1 change: 1 addition & 0 deletions torchmetrics/classification/iou.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class IoU(ConfusionMatrix):

"""
is_differentiable = False
higher_is_better = True

def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/classification/kl_divergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class KLDivergence(Metric):

"""
is_differentiable = True
higher_is_better = False
# TODO: canot be used because if scripting
# measures: Union[List[Tensor], Tensor]
total: Tensor
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/classification/matthews_corrcoef.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class MatthewsCorrcoef(Metric):

"""
is_differentiable = False
higher_is_better = True
confmat: Tensor

def __init__(
Expand Down
2 changes: 2 additions & 0 deletions torchmetrics/classification/precision_recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class Precision(StatScores):

"""
is_differentiable = False
higher_is_better = True

def __init__(
self,
Expand Down Expand Up @@ -271,6 +272,7 @@ class Recall(StatScores):

"""
is_differentiable = False
higher_is_better = True

def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/classification/specificity.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Specificity(StatScores):

"""
is_differentiable = False
higher_is_better = True

def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/image/fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class FID(Metric):
"""
real_features: List[Tensor]
fake_features: List[Tensor]
higher_is_better = False

def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/image/inception.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class IS(Metric):

"""
features: List
higher_is_better = True

def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/image/kid.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class KID(Metric):
"""
real_features: List[Tensor]
fake_features: List[Tensor]
higher_is_better = False

def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/image/lpip_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class LPIPS(Metric):
"""

is_differentiable = True
higher_is_better = False
real_features: List[Tensor]
fake_features: List[Tensor]

Expand Down
1 change: 1 addition & 0 deletions torchmetrics/image/psnr.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class PSNR(Metric):
"""
min_target: Tensor
max_target: Tensor
higher_is_better = False

def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/image/ssim.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SSIM(Metric):

preds: List[Tensor]
target: List[Tensor]
higher_is_better = True

def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/regression/cosine_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class CosineSimilarity(Metric):

"""
is_differentiable = True
higher_is_better = True
preds: List[Tensor]
target: List[Tensor]

Expand Down
1 change: 1 addition & 0 deletions torchmetrics/regression/explained_variance.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ExplainedVariance(Metric):

"""
is_differentiable = True
higher_is_better = True
n_obs: Tensor
sum_error: Tensor
sum_squared_error: Tensor
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/regression/mean_absolute_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class MeanAbsoluteError(Metric):
tensor(0.5000)
"""
is_differentiable = True
higher_is_better = False
sum_abs_error: Tensor
total: Tensor

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MeanAbsolutePercentageError(Metric):

"""
is_differentiable = True
higher_is_better = False
sum_abs_per_error: Tensor
total: Tensor

Expand Down
1 change: 1 addition & 0 deletions torchmetrics/regression/mean_squared_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class MeanSquaredError(Metric):

"""
is_differentiable = True
higher_is_better = False
sum_squared_error: Tensor
total: Tensor

Expand Down
1 change: 1 addition & 0 deletions torchmetrics/regression/mean_squared_log_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class MeanSquaredLogError(Metric):

"""
is_differentiable = True
higher_is_better = False
sum_squared_log_error: Tensor
total: Tensor

Expand Down
1 change: 1 addition & 0 deletions torchmetrics/regression/pearson.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class PearsonCorrcoef(Metric):

"""
is_differentiable = True
higher_is_better = None # both -1 and 1 are optimal
preds: List[Tensor]
target: List[Tensor]
mean_x: Tensor
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/regression/r2.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class R2Score(Metric):

"""
is_differentiable = True
higher_is_better = True
sum_squared_error: Tensor
sum_error: Tensor
residual: Tensor
Expand Down
1 change: 1 addition & 0 deletions torchmetrics/regression/spearman.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SpearmanCorrcoef(Metric):

"""
is_differentiable = False
higher_is_better = True
preds: List[Tensor]
target: List[Tensor]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SymmetricMeanAbsolutePercentageError(Metric):
tensor(0.2290)
"""
is_differentiable = True
higher_is_better = False
sum_abs_per_error: Tensor
total: Tensor

Expand Down
1 change: 1 addition & 0 deletions torchmetrics/regression/tweedie_deviance.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TweedieDevianceScore(Metric):

"""
is_differentiable = True
higher_is_better = None # TODO: both -1 and 1 are optimal
sum_deviance_score: Tensor
num_observations: Tensor

Expand Down