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 rs.utils.weighted_pearsonr and tests #189

Merged
merged 10 commits into from
Oct 19, 2022
Merged

add rs.utils.weighted_pearsonr and tests #189

merged 10 commits into from
Oct 19, 2022

Conversation

kmdalton
Copy link
Member

I wrote a function to compute weighted Pearson correlation coefficients and added it to utils/stats.py.

@kmdalton kmdalton requested a review from JBGreisman October 18, 2022 15:39

Note
----
x, y, and w may be arbitrarily batched. the correlation coefficient will be computed pairwise along the last axis.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand the use of "batched" in this context. Perhaps an example with the corresponding array shapes would help?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this better?


import reciprocalspaceship as rs


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your tests look good, but are there any simple cases that can be used to test the output for non uniform weight cases?

Right now the tests only compare to scipy (requires np.ones weights) or tests execution. Is there a good test for correctness in the more general case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know any. i'm happy to incorporate any examples you can find.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep -- unsure. I'm ok with this as is given there isn't another reference implementation for the general case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can add a regression test. is that a good idea?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps -- do you mean by including a test against the current implementation? Also, is useful to test against scipy using uniform weights that aren't np.ones? Any uniform array should be equivalent, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes test against the current implementation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay i added a test against non-one weights and a test against a current result. i'll merge after ci.

Copy link
Member

@JBGreisman JBGreisman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good -- two small requests:

  1. I was a bit confused by your use of "batched" in the docstring. Please clarify with an example or by saying something about the shapes of the input and the expected output.
  2. I am wondering if there's an additional test of correctness that can be done for the non-uniform weights case. Right now, that only gets tested for execution, but not correctness.

@codecov-commenter
Copy link

codecov-commenter commented Oct 19, 2022

Codecov Report

Base: 98.35% // Head: 98.36% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (fa9e7e1) compared to base (8d90ddc).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #189      +/-   ##
==========================================
+ Coverage   98.35%   98.36%   +0.01%     
==========================================
  Files          44       44              
  Lines        1764     1775      +11     
==========================================
+ Hits         1735     1746      +11     
  Misses         29       29              
Flag Coverage Δ
unittests 98.36% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
reciprocalspaceship/utils/__init__.py 100.00% <100.00%> (ø)
reciprocalspaceship/utils/stats.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@kmdalton kmdalton requested a review from JBGreisman October 19, 2022 01:35
Copy link
Member

@JBGreisman JBGreisman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the docstring

@kmdalton kmdalton merged commit 28f6c93 into main Oct 19, 2022
@kmdalton kmdalton deleted the weighted_pearsonr branch October 19, 2022 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants