Skip to content
Open
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion titrate/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ def plot(
statistic_bkg,
axs,
):
print(self.poi_val)
axs["diff"].hist(
toys_ts_diff,
bins=bins_diff,
Expand Down
2 changes: 1 addition & 1 deletion titrate/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def validation_file(measurement_dataset, tmp_path_factory):


@pytest.mark.parametrize("statistic", ["qmu", "qtildemu"])
def test_AsmyptoticValidator(measurement_dataset, statistic, validation_file):
def test_AsymptoticValidator(measurement_dataset, statistic, validation_file):
from titrate.validation import AsymptoticValidator

validator = AsymptoticValidator(
Expand Down
8 changes: 2 additions & 6 deletions titrate/upperlimits.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import numpy as np
from astropy.table import QTable
from gammapy.astro.darkmatter import DarkMatterAnnihilationSpectralModel
from gammapy.modeling import Covariance, Fit
from gammapy.modeling.fit import OptimizeResult
from gammapy.modeling import Fit
from gammapy.modeling.models import (
FoVBackgroundModel,
Models,
Expand Down Expand Up @@ -84,11 +83,9 @@ def compute(self):
poi_ul = 1e-2
else:
poi_ul = poi_best
prev_pval = 0
while (
(pval := self.pvalue(poi_ul, cl_type=self.cl_type)) > 1 - self.cl
) or np.isnan(pval):
prev_pval = pval
poi_ul *= 2

interp_ul_points = np.linspace(poi_ul / 2, poi_ul, 5)
Expand All @@ -105,7 +102,6 @@ def compute(self):

poi_ul = brentq(interpolation, poi_ul / 2, poi_ul)

print("FOUND:", poi_ul)
self.poi_ul = poi_ul

return poi_ul
Expand Down Expand Up @@ -139,7 +135,7 @@ def expected_uls(self):
target_ts = norm.ppf(1 - 0.5 * (1 - self.cl)) ** 2

poi_ul = 1e-2
while (ts := self.no_signal_statistic.evaluate(poi_ul)) < target_ts:
while self.no_signal_statistic.evaluate(poi_ul) < target_ts:
poi_ul *= 2

interp_ul_points = np.linspace(poi_ul / 2, poi_ul, 10)
Expand Down
8 changes: 5 additions & 3 deletions titrate/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from gammapy.datasets import Datasets


def CopyModelError(AttributeError):
class CopyModelError(AttributeError):
"""Something went wrong during copying a model."""
pass


def calc_ts_toyMC(dataset, test_statistic, poi_val, poi_true_val, poi_name):
"""Evaluates given test statistic for toy MCs.

The given dataset will be copied and a new measurement will be simulated.
The test statistic is evaluated for this dataset.
The `poi_true_val` is used to set the parameter of interest in the model
before simulating the new measurement from which the test statistic is
evaluated.
"""
toy_dataset = copy_dataset_with_models(dataset)
toy_dataset.models.parameters[poi_name].value = poi_true_val
Expand Down
3 changes: 1 addition & 2 deletions titrate/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from gammapy.modeling.models import SkyModel

from titrate.datasets import AsimovMapDataset, AsimovSpectralDataset
from titrate.statistics import QMuTestStatistic, QTildeMuTestStatistic, kstest
from titrate.statistics import QMuTestStatistic, QTildeMuTestStatistic
from titrate.utils import calc_ts_toyMC, copy_dataset_with_models

STATISTICS = {"qmu": QMuTestStatistic, "qtildemu": QTildeMuTestStatistic}
Expand Down Expand Up @@ -109,7 +109,6 @@ def validate(self, n_toys=1000):
poi_val=self.poi_val, ts_val=x
),
).pvalue
print(ks_diff, ks_same)

valid = ks_diff > 0.05 and ks_same > 0.05

Expand Down
Loading