Skip to content

Commit a81f057

Browse files
committed
more fixes
1 parent eceb532 commit a81f057

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

src/pyhf/infer/calculators.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ def generate_asimov_data(
4040
Example:
4141
4242
>>> import pyhf
43+
>>> import numpy as np
4344
>>> pyhf.set_backend("numpy")
4445
>>> model = pyhf.simplemodels.uncorrelated_background(
4546
... signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
4647
... )
4748
>>> observations = [51, 48]
4849
>>> data = observations + model.config.auxdata
4950
>>> mu_test = 1.0
50-
>>> pyhf.infer.calculators.generate_asimov_data(mu_test, data, model, None, None, None)
51-
array([ 60.61229858, 56.52802479, 270.06832542, 48.31545488])
51+
>>> asimov_data = pyhf.infer.calculators.generate_asimov_data(mu_test, data, model, None, None, None)
52+
>>> np.isclose(asimov_data, [ 60.61229858, 56.52802479, 270.06832542, 48.31545488])
5253
>>> pyhf.infer.calculators.generate_asimov_data(
5354
... mu_test, data, model, None, None, None, return_fitted_pars=True
5455
... )
@@ -339,6 +340,7 @@ def teststatistic(self, poi_test):
339340
Example:
340341
341342
>>> import pyhf
343+
>>> import numpy as np
342344
>>> pyhf.set_backend("numpy")
343345
>>> model = pyhf.simplemodels.uncorrelated_background(
344346
... signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
@@ -347,8 +349,9 @@ def teststatistic(self, poi_test):
347349
>>> data = observations + model.config.auxdata
348350
>>> mu_test = 1.0
349351
>>> asymptotic_calculator = pyhf.infer.calculators.AsymptoticCalculator(data, model, test_stat="qtilde")
350-
>>> asymptotic_calculator.teststatistic(mu_test)
351-
array(0.14043184)
352+
>>> test_stat = asymptotic_calculator.teststatistic(mu_test)
353+
>>> np.isclose(test_stat, 0.14043184)
354+
True
352355
>>> asymptotic_calculator.fitted_pars
353356
HypoTestFitResults(asimov_pars=array([0. , 1.0030482 , 0.96264534]), free_fit_to_data=array([0. , 1.0030512 , 0.96266961]), free_fit_to_asimov=array([0. , 1.00304893, 0.96263365]), fixed_poi_fit_to_data=array([1. , 0.97224597, 0.87553894]), fixed_poi_fit_to_asimov=array([1. , 0.97276864, 0.87142047]))
354357
>>> asymptotic_calculator.fitted_pars.free_fit_to_asimov # best-fit parameters to Asimov dataset
@@ -478,6 +481,7 @@ def expected_pvalues(self, sig_plus_bkg_distribution, bkg_only_distribution):
478481
Example:
479482
480483
>>> import pyhf
484+
>>> import numpy as np
481485
>>> pyhf.set_backend("numpy")
482486
>>> model = pyhf.simplemodels.uncorrelated_background(
483487
... signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
@@ -491,8 +495,8 @@ def expected_pvalues(self, sig_plus_bkg_distribution, bkg_only_distribution):
491495
>>> _ = asymptotic_calculator.teststatistic(mu_test)
492496
>>> sig_plus_bkg_dist, bkg_dist = asymptotic_calculator.distributions(mu_test)
493497
>>> CLsb_exp_band, CLb_exp_band, CLs_exp_band = asymptotic_calculator.expected_pvalues(sig_plus_bkg_dist, bkg_dist)
494-
>>> CLs_exp_band
495-
[array(0.00260626), array(0.01382005), array(0.06445321), array(0.23525644), array(0.57303621)]
498+
>>> np.isclose(CLs_exp_band, [0.00260626, 0.01382005, 0.06445321, 0.23525644, 0.57303621])
499+
True
496500
497501
Args:
498502
sig_plus_bkg_distribution (~pyhf.infer.calculators.AsymptoticTestStatDistribution):
@@ -611,6 +615,7 @@ def expected_value(self, nsigma):
611615
Examples:
612616
613617
>>> import pyhf
618+
>>> import numpy as np
614619
>>> import numpy.random as random
615620
>>> random.seed(0)
616621
>>> pyhf.set_backend("numpy")
@@ -646,9 +651,9 @@ def expected_value(self, nsigma):
646651
... )
647652
... )
648653
>>> n_sigma = pyhf.tensorlib.astensor([-2, -1, 0, 1, 2])
649-
>>> dist.expected_value(n_sigma)
650-
array([0.00000000e+00, 0.00000000e+00, 5.53671231e-04, 8.29987137e-01,
651-
2.99592664e+00])
654+
>>> exp_values = dist.expected_value(n_sigma)
655+
>>> np.isclose(exp_values, [0.00000000e+00, 0.00000000e+00, 5.53671231e-04, 8.29987137e-01, 2.99592664e+00])
656+
True
652657
653658
Args:
654659
nsigma (:obj:`int` or :obj:`tensor`): The number of standard deviations.

src/pyhf/infer/intervals/upper_limits.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def toms748_scan(
4646
>>> obs_limit, exp_limits = pyhf.infer.intervals.upper_limits.toms748_scan(
4747
... data, model, 0., 5., rtol=0.01
4848
... )
49-
>>> obs_limit
50-
array(1.0115693...)
51-
>>> exp_limits
52-
[array(0.5600747), array(0.75702605), array(1.06234693), array(1.50116923), array(2.05078912)]
49+
>>> np.isclose(obs_limit, 1.01156939)
50+
True
51+
>>> np.isclose(exp_limits, [0.5600747, 0.75702605, 1.06234693, 1.50116923, 2.05078912])
52+
array([ True, True, True, True, True])
5353
5454
Args:
5555
data (:obj:`tensor`): The observed data.
@@ -161,10 +161,10 @@ def linear_grid_scan(
161161
>>> obs_limit, exp_limits, (scan, results) = pyhf.infer.intervals.upper_limits.upper_limit(
162162
... data, model, scan, return_results=True
163163
... )
164-
>>> obs_limit
165-
array(1.0176408...)
166-
>>> exp_limits
167-
[array(0.59576921), array(0.76169166), array(1.08504773), array(1.50170482), array(2.06654952)]
164+
>>> np.isclose(obs_limit, 1.01764089)
165+
True
166+
>>> np.isclose(exp_limits, [0.59576921, 0.76169166, 1.08504773, 1.50170482, 2.06654952])
167+
array([ True, True, True, True, True])
168168
169169
Args:
170170
data (:obj:`tensor`): The observed data.
@@ -225,10 +225,10 @@ def upper_limit(
225225
>>> obs_limit, exp_limits, (scan, results) = pyhf.infer.intervals.upper_limits.upper_limit(
226226
... data, model, scan, return_results=True
227227
... )
228-
>>> obs_limit
229-
array(1.01764089)
230-
>>> exp_limits
231-
[array(0.59576921), array(0.76169166), array(1.08504773), array(1.50170482), array(2.06654952)]
228+
>>> np.isclose(obs_limit, 1.01764089)
229+
True
230+
>>> np.isclose(exp_limits, [0.59576921, 0.76169166, 1.08504773, 1.50170482, 2.06654952])
231+
array([ True, True, True, True, True])
232232
233233
Args:
234234
data (:obj:`tensor`): The observed data.

src/pyhf/infer/mle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def fit(data, pdf, init_pars=None, par_bounds=None, fixed_params=None, **kwargs)
9595
>>> data = pyhf.tensorlib.astensor(observations + model.config.auxdata)
9696
>>> bestfit_pars, twice_nll = pyhf.infer.mle.fit(data, model, return_fitted_val=True)
9797
>>> np.isclose(bestfit_pars, [0. , 1.0030512 , 0.96266961])
98-
True
98+
array([ True, True, True])
9999
>>> twice_nll
100100
array(24.98393521)
101101
>>> -2 * model.logpdf(bestfit_pars, data) == twice_nll
@@ -170,7 +170,7 @@ def fixed_poi_fit(
170170
... test_poi, data, model, return_fitted_val=True
171171
... )
172172
>>> np.isclose(bestfit_pars, [1. , 0.97224597, 0.87553894])
173-
True
173+
array([ True, True, True])
174174
>>> twice_nll
175175
array(28.92218013)
176176
>>> -2 * model.logpdf(bestfit_pars, data) == twice_nll

src/pyhf/infer/test_statistics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def qmu_tilde(
195195
... test_mu, data, model, init_pars, par_bounds, fixed_params
196196
... )
197197
array(3.93824492)
198-
>>> test_stat, constrained, unconstrained = pyhf.infer.test_statistics.qmu_tilde(
198+
>>> test_stat, (constrained, unconstrained) = pyhf.infer.test_statistics.qmu_tilde(
199199
... test_mu, data, model, init_pars, par_bounds, fixed_params, return_fitted_pars=True
200200
... )
201201
>>> test_stat
@@ -284,7 +284,7 @@ def tmu(mu, data, pdf, init_pars, par_bounds, fixed_params, return_fitted_pars=F
284284
... test_mu, data, model, init_pars, par_bounds, fixed_params
285285
... )
286286
array(3.9549891)
287-
>>> test_stat, constrained, unconstrained = pyhf.infer.test_statistics.tmu(
287+
>>> test_stat, (constrained, unconstrained) = pyhf.infer.test_statistics.tmu(
288288
... test_mu, data, model, init_pars, par_bounds, fixed_params, return_fitted_pars=True
289289
... )
290290
>>> test_stat
@@ -380,7 +380,7 @@ def tmu_tilde(
380380
... test_mu, data, model, init_pars, par_bounds, fixed_params
381381
... )
382382
array(3.93824492)
383-
>>> test_stat, constrained, unconstrained = pyhf.infer.test_statistics.tmu_tilde(
383+
>>> test_stat, (constrained, unconstrained) = pyhf.infer.test_statistics.tmu_tilde(
384384
... test_mu, data, model, init_pars, par_bounds, fixed_params, return_fitted_pars=True
385385
... )
386386
>>> test_stat
@@ -464,7 +464,7 @@ def q0(mu, data, pdf, init_pars, par_bounds, fixed_params, return_fitted_pars=Fa
464464
>>> fixed_params = model.config.suggested_fixed()
465465
>>> pyhf.infer.test_statistics.q0(test_mu, data, model, init_pars, par_bounds, fixed_params)
466466
array(2.98339447)
467-
>>> test_stat, constrained, unconstrained = pyhf.infer.test_statistics.q0(
467+
>>> test_stat, (constrained, unconstrained) = pyhf.infer.test_statistics.q0(
468468
... test_mu, data, model, init_pars, par_bounds, fixed_params, return_fitted_pars=True
469469
... )
470470
>>> test_stat

0 commit comments

Comments
 (0)