Skip to content

Commit

Permalink
first attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasheinrich authored and kratsg committed Jul 5, 2024
1 parent 89a6c13 commit 0b05b53
Showing 1 changed file with 41 additions and 18 deletions.
59 changes: 41 additions & 18 deletions src/pyhf/infer/calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ def __init__(
test_stat="qtilde",
ntoys=2000,
track_progress=True,
skip_failing_toys = False,
):
r"""
Toy-based Calculator.
Expand Down Expand Up @@ -705,6 +706,7 @@ def __init__(
~pyhf.infer.calculators.ToyCalculator: The calculator for toy-based quantities.
"""
self.skip_failing_toys = skip_failing_toys
self.ntoys = ntoys
self.data = data
self.pdf = pdf
Expand Down Expand Up @@ -754,6 +756,9 @@ def distributions(self, poi_test, track_progress=None):
Tuple (~pyhf.infer.calculators.EmpiricalDistribution): The distributions under the hypotheses.
"""

print('skip?',self.skip_failing_toys)

tensorlib, _ = get_backend()
sample_shape = (self.ntoys,)

Expand Down Expand Up @@ -792,29 +797,47 @@ def distributions(self, poi_test, track_progress=None):

signal_teststat = []
for sample in tqdm.tqdm(signal_sample, **tqdm_options, desc='Signal-like'):
signal_teststat.append(
teststat_func(
poi_test,
sample,
self.pdf,
self.init_pars,
self.par_bounds,
self.fixed_params,
try:
value = teststat_func(
poi_test,
sample,
self.pdf,
self.init_pars,
self.par_bounds,
self.fixed_params,
)
except RuntimeError:
if self.skip_failing_toys:
value = None
else:
raise

if (value is not None) and (tensorlib.isfinite(value)):
signal_teststat.append(
value
)
)

bkg_teststat = []
for sample in tqdm.tqdm(bkg_sample, **tqdm_options, desc='Background-like'):
bkg_teststat.append(
teststat_func(
poi_test,
sample,
self.pdf,
self.init_pars,
self.par_bounds,
self.fixed_params,
try:
value = teststat_func(
poi_test,
sample,
self.pdf,
self.init_pars,
self.par_bounds,
self.fixed_params,
)
except RuntimeError:
if self.skip_failing_toys:
value = None
else:
raise

if (value is not None) and (tensorlib.isfinite(value)):
bkg_teststat.append(
value
)
)

s_plus_b = EmpiricalDistribution(tensorlib.astensor(signal_teststat))
b_only = EmpiricalDistribution(tensorlib.astensor(bkg_teststat))
Expand Down

0 comments on commit 0b05b53

Please sign in to comment.