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 Pearson correlation coefficient #157

Merged
merged 26 commits into from
Apr 13, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
inline
  • Loading branch information
Borda authored Apr 6, 2021
commit e939d278c2c6c85cba3368fa4e2a3e68738223c7
9 changes: 3 additions & 6 deletions torchmetrics/functional/regression/pearson.py
Original file line number Diff line number Diff line change
@@ -63,12 +63,9 @@ def _pearson_corrcoef_update(
raise ValueError('Expected both predictions and target to be 1 dimensional tensors.')
data = torch.stack([preds, target], dim=1)

if old_mean is None:
old_mean = 0
if old_cov is None:
old_cov = 0
if old_nobs is None:
old_nobs = 0
old_mean = 0 if old_mean is None else old_mean
old_cov = 0 if old_cov is None else old_cov
old_nobs = 0 if old_nobs is None else old_nobs

new_mean = _update_mean(old_mean, old_nobs, data)
new_cov = _update_cov(old_cov, old_mean, new_mean, data)