Skip to content

Commit

Permalink
Add Kendall Rank Correlation Coefficient (Kendall's tau) (#1271)
Browse files Browse the repository at this point in the history
* wip

* WIP: Overhaul

* Do some polishing

* WIP: Add class metric + another refactor

* Add sorting for the other sequence to calcualte ties properly

* Add hypothesis testing + links to docs

* chlog

* WIP: Add some tests

* Fix dimension handling

* Fix doctest

* Add some docs + handle some mypy errors

* Update docs + fix some mypy errors

* Re-run mypy

* Refactor: Separate calculate tau method

* Refactor + Add variant c

* Refactor: Internally, represent metric variant as enumerate
* Add variant 'c'
* Update docs

* Fix a typo

* Add testing for ddp=True and dist_sync_on_step=True options

* Fix doctest

* .

* Fix tests for scipy<1.8.0

* Fix some stuff in docs

* Add missing device placement

* Fix some nits + add t-test examples to docs

* Refactor: Move _check_data_shape_for_corr_coef to utils file

* Fix a typo

* Fix docs example for class metric

* Try to fix docs

* .

* Use different link to check if works

* sphinx: Ignore jstor link for linkcheck as cannot be accesed from python

* Apply suggestions from code review

Co-authored-by: Nicki Skafte Detlefsen <skaftenicki@gmail.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 3, 2022
1 parent 0c66f03 commit ec27df1
Show file tree
Hide file tree
Showing 14 changed files with 784 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added option to pass `distributed_available_fn` to metrics to allow checks for custom communication backend for making `dist_sync_fn` actually useful ([#1301](https://github.com/Lightning-AI/metrics/pull/1301))


- Added `KendallRankCorrCoef` to regression package ([#1271](https://github.com/Lightning-AI/metrics/pull/1271))


### Changed

- Changed `MeanAveragePrecision` to vectorize `_find_best_gt_match` operation ([#1259](https://github.com/Lightning-AI/metrics/pull/1259))
Expand Down
4 changes: 4 additions & 0 deletions docs/source/conf.py
Expand Up @@ -385,3 +385,7 @@ def find_source():
"""
coverage_skip_undoc_in_source = True

linkcheck_ignore = [
"https://www.jstor.org/stable/2332303" # jstor cannot be accessed from python, but link work fine in a local doc
]
2 changes: 2 additions & 0 deletions docs/source/links.rst
Expand Up @@ -93,3 +93,5 @@
.. _AB divergence: https://pdfs.semanticscholar.org/744b/1166de34cb099100f151f3b1459f141ae25b.pdf
.. _Rényi divergence: https://static.renyi.hu/renyi_cikkek/1961_on_measures_of_entropy_and_information.pdf
.. _Fisher-Rao distance: http://www.scholarpedia.org/article/Fisher-Rao_metric
.. _Kendall Rank Correlation Coefficient: https://en.wikipedia.org/wiki/Kendall_rank_correlation_coefficient
.. _The Treatment of Ties in Ranking Problems: https://www.jstor.org/stable/2332303
22 changes: 22 additions & 0 deletions docs/source/regression/kendall_rank_corr_coef.rst
@@ -0,0 +1,22 @@
.. customcarditem::
:header: Kendall Rank Correlation Coefficient
:image: https://pl-flash-data.s3.amazonaws.com/assets/thumbnails/tabular_classification.svg
:tags: Regression

.. include:: ../links.rst

#######################
Kendal Rank Corr. Coef.
#######################

Module Interface
________________

.. autoclass:: torchmetrics.KendallRankCorrCoef
:noindex:

Functional Interface
____________________

.. autofunction:: torchmetrics.functional.kendall_rank_corrcoef
:noindex:
2 changes: 2 additions & 0 deletions src/torchmetrics/__init__.py
Expand Up @@ -57,6 +57,7 @@
ConcordanceCorrCoef,
CosineSimilarity,
ExplainedVariance,
KendallRankCorrCoef,
KLDivergence,
MeanAbsoluteError,
MeanAbsolutePercentageError,
Expand Down Expand Up @@ -129,6 +130,7 @@
"HammingDistance",
"HingeLoss",
"JaccardIndex",
"KendallRankCorrCoef",
"KLDivergence",
"MatchErrorRate",
"MatthewsCorrCoef",
Expand Down
2 changes: 2 additions & 0 deletions src/torchmetrics/functional/__init__.py
Expand Up @@ -49,6 +49,7 @@
from torchmetrics.functional.regression.concordance import concordance_corrcoef
from torchmetrics.functional.regression.cosine_similarity import cosine_similarity
from torchmetrics.functional.regression.explained_variance import explained_variance
from torchmetrics.functional.regression.kendall import kendall_rank_corrcoef
from torchmetrics.functional.regression.kl_divergence import kl_divergence
from torchmetrics.functional.regression.log_mse import mean_squared_log_error
from torchmetrics.functional.regression.mae import mean_absolute_error
Expand Down Expand Up @@ -112,6 +113,7 @@
"hinge_loss",
"image_gradients",
"jaccard_index",
"kendall_rank_corrcoef",
"kl_divergence",
"match_error_rate",
"matthews_corrcoef",
Expand Down
1 change: 1 addition & 0 deletions src/torchmetrics/functional/regression/__init__.py
Expand Up @@ -14,6 +14,7 @@
from torchmetrics.functional.regression.concordance import concordance_corrcoef # noqa: F401
from torchmetrics.functional.regression.cosine_similarity import cosine_similarity # noqa: F401
from torchmetrics.functional.regression.explained_variance import explained_variance # noqa: F401
from torchmetrics.functional.regression.kendall import kendall_rank_corrcoef # noqa: F401
from torchmetrics.functional.regression.kl_divergence import kl_divergence # noqa: F401
from torchmetrics.functional.regression.log_mse import mean_squared_log_error # noqa: F401
from torchmetrics.functional.regression.mae import mean_absolute_error # noqa: F401
Expand Down

0 comments on commit ec27df1

Please sign in to comment.