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

Extending channel_capacity() function #284

Closed
wants to merge 0 commits into from
Closed

Conversation

htjb
Copy link
Collaborator

@htjb htjb commented Apr 20, 2023

Description

Updated the channel_capacity() function to effective_samples() and added a method option which is defaulted to `channel' but allows users to calculate a Kish estimate of the effective number of samples given by

n_{eff} = \frac{(\sum_i w_i)^2}{\sum_i w_i^2}.

This was briefly mentioned in #280.

If anybody has a suggestion on how to test this bit of code that would be super helpful @williamjameshandley @AdamOrmondroyd @lukashergt?

Checklist:

  • I have performed a self-review of my own code
  • My code is PEP8 compliant (flake8 anesthetic tests)
  • My code contains compliant docstrings (pydocstyle --convention=numpy anesthetic)
  • New and existing unit tests pass locally with my changes (python -m pytest)
  • I have added tests that prove my fix is effective or that my feature works
  • I have appropriately incremented the semantic version number in both README.rst and anesthetic/_version.py

@lukashergt
Copy link
Collaborator

lukashergt commented Apr 20, 2023

Hi @htjb,

thanks for initiating this. I see that you are pushing from your master branch, are you sure that you want to do that? Normally you would create a new branch dedicated to the change that you want to make, and only merge that into master once all the changes are fully addressed.

The tests are failing because of the renaming from channel_capacity to effective_samples, which needs adjusting also in the various test files where there is still from anesthetic.utils import channel_capacity.

If anybody has a suggestion on how to test this bit of code that would be super helpful @williamjameshandley @AdamOrmondroyd @lukashergt?

How about:

import numpy as np
from pytest import approx
from anesthetic.utils import effective_samples

@pytest.mark.parametrize('method', ['channel', 'kish'])
def test_effective_samples(method):
    w = np.ones(20)
    assert effective_samples(w, method=method) == approx(20, rel=1e-6)
    w[10:] = 1e-3
    assert effective_samples(w, method=method) == approx(10, rel=1e-2)

Would we want a skipna kwarg for this?

@htjb
Copy link
Collaborator Author

htjb commented Apr 21, 2023

@lukashergt My bad, I was rushing to do this between meetings! I've moved my code onto another branch and will update the tests and make another PR from there. Thanks for the test suggestion!

@htjb htjb mentioned this pull request Apr 21, 2023
6 tasks
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.

2 participants