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

Binomial uncertainty #171

Merged
merged 12 commits into from
Aug 22, 2024
Merged

Binomial uncertainty #171

merged 12 commits into from
Aug 22, 2024

Conversation

javierggt
Copy link
Contributor

@javierggt javierggt commented Aug 16, 2024

Description

Add binomial uncertainty interval to star_probs.py

Interface impacts

Testing

Unit tests

  • No unit tests
  • Mac
  • Linux
  • Windows

Independent check of unit tests by [REVIEWER NAME]

  • [PLATFORM]:

Functional tests

This notebook: coverage.ipynb

Copy link
Member

@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

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

This test case should work:

In [7]: star_probs.binomial_confidence_interval(1, [1, 2])
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[7], line 1
----> 1 star_probs.binomial_confidence_interval(1, [1, 2])

File ~/git/chandra_aca/chandra_aca/star_probs.py:1161, in binomial_confidence_interval(n_true, n_trials, coverage)
   1159 n_trials = np.ma.MaskedArray(n_trials, mask=(n_trials == 0))
   1160 ratio = np.ones_like(n_true) * np.nan
-> 1161 ratio[~n_trials.mask] = n_true[~n_trials.mask] / n_trials[~n_trials.mask]
   1163 # try:
   1164 #     float(coverage)
   1165 # except ValueError:
   1166 #     raise Exception("The coverage must be a float!") from None
   1168 alpha = (1 - coverage) / 2

IndexError: boolean index did not match indexed array along dimension 0; dimension is 1 but corresponding boolean dimension is 2

In [8]: np.broadcast_arrays(1, [1, 2])
Out[8]: [array([1, 1]), array([1, 2])]

In [9]: np.broadcast_arrays(1, 1)
Out[9]: [array(1), array(1)]

chandra_aca/star_probs.py Show resolved Hide resolved
@javierggt
Copy link
Contributor Author

@taldcroft I think I addressed all your comments.

@taldcroft
Copy link
Member

@javierggt - thanks, looking much better. Just one more nitpick, returning a scalar array is technically OK but just not nice.

In [2]: star_probs.binomial_confidence_interval(0, 1, 0.6)
Out[2]: (array(0.), array(0.), array(0.47203609))

If you look at acq_success_prob there is a decent idiom for dealing with this. The chandra_aca.transform.broadcast_arrays() function does the atleast_1d for the inputs and returns an is_scalar bool. Then at the end if is_scalar=True then return value[0].



def binomial_confidence_interval(n_true, n_trials, coverage=0.682689):
"""Binomial error calculation using the Jeffreys prior.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"""Binomial error calculation using the Jeffreys prior.
"""Binomial confidence interval calculation using the Jeffreys prior.


Parameters
----------
n_success : numpy array
Copy link
Member

Choose a reason for hiding this comment

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

The first two can both be int.

Copy link
Member

@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

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

Looks good thanks!

@javierggt javierggt merged commit 0a3a411 into master Aug 22, 2024
2 checks passed
@javierggt javierggt deleted the binomial-uncert branch August 22, 2024 23:43
@javierggt javierggt mentioned this pull request Aug 23, 2024
@javierggt javierggt mentioned this pull request Nov 7, 2024
@javierggt javierggt mentioned this pull request Nov 19, 2024
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