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

Use scipy chi2 & ncx2 #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
23 changes: 6 additions & 17 deletions titrate/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np
from gammapy.modeling import Fit
from scipy.stats import kstwo, norm
from scipy.stats import chi2, kstwo, ncx2, norm

from titrate.datasets import AsimovMapDataset

Expand Down Expand Up @@ -116,24 +116,14 @@ def asympotic_approximation_pdf(
self, ts_val, poi_val, same=True, poi_true_val=None
):
if same:
return (
1
/ (2 * np.sqrt(2 * np.pi * ts_val))
* np.exp(-0.5 * (np.sqrt(ts_val)) ** 2)
)
return 0.5 * chi2.pdf(ts_val, df=1)

if not isinstance(self.dataset, AsimovMapDataset):
raise AsimovApproximationError(
"`dataset` must be an `AsimovMapDataset` in order to use the"
" `asympotic_approximation`"
)
return (
1
/ (2 * np.sqrt(2 * np.pi * ts_val))
* np.exp(
-0.5 * (np.sqrt(ts_val) - (poi_val - poi_true_val) / self.sigma()) ** 2
)
)
return ncx2.pdf(ts_val, df=1, nc=((poi_val - poi_true_val) / self.sigma()) ** 2)

def asympotic_approximation_cdf(
self, ts_val, poi_val, same=True, poi_true_val=None
Expand Down Expand Up @@ -266,7 +256,7 @@ def asympotic_approximation_pdf(
* (ts_val + poi_val**2 / sigma**2) ** 2
/ (2 * poi_val / sigma) ** 2
),
1 / (2 * np.sqrt(2 * np.pi * ts_val)) * np.exp(-0.5 * ts_val),
0.5 * chi2.pdf(ts_val, df=1),
)

return np.where(
Expand All @@ -279,9 +269,8 @@ def asympotic_approximation_pdf(
** 2
/ (2 * poi_val / sigma) ** 2
),
1
/ (2 * np.sqrt(2 * np.pi * ts_val))
* np.exp(-0.5 * (np.sqrt(ts_val) - (poi_val - poi_true_val) / sigma) ** 2),
0.5
* ncx2.pdf(ts_val, df=1, nc=((poi_val - poi_true_val) / self.sigma()) ** 2),
)

def asympotic_approximation_cdf(
Expand Down
Loading