3 from __future__
import print_function
15 target = N*math.log(N)-N-0.5
18 mid = bot+0.5*(top-bot)
19 while top>mid
and mid>bot:
20 if N*math.log(mid)-mid >= target:
24 mid = bot+0.5*(top-bot)
30 target = N*math.log(N)-N-0.5
32 top = max(20., N+5.*math.sqrt(N))
33 mid = bot+0.5*(top-bot)
34 while top>mid
and mid>bot:
35 if N*math.log(mid)-mid > target:
39 mid = bot+0.5*(top-bot)
44 for N
in range(upper):
52 if mu >= bound[0]
and mu < bound[1]:
53 p += scipy.stats.poisson.pmf(N, mu)
57 bounds =
get_bounds(int(round(max(20, upper_lim+5.*math.sqrt(upper_lim)))))
59 h = ROOT.TH1D(
"",
"Wilk's Coverage;Poisson mean #mu;Coverage", num_pts, lower_lim, upper_lim)
60 g = ROOT.TH1D(
"",
"Wilk's Coverage;Poisson mean #mu;Coverage", num_pts, lower_lim, upper_lim)
63 h.SetTitleOffset(1.25,
"Y")
64 h.SetLineColor(ROOT.kRed)
65 g.SetLineColor(ROOT.kBlack)
68 ref_val = math.erf(1/math.sqrt(2.))
69 for i
in range(1, num_pts+1):
70 mu = h.GetBinCenter(i)
72 g.SetBinContent(i, ref_val)
77 c.Print(
"wilks_coverage.pdf")
79 if __name__ ==
"__main__":
80 parser = argparse.ArgumentParser(description=
"Test coverage of Poisson intervals from Wilk's theorem",
81 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
82 parser.add_argument(
"--num_pts", type=int, default=1000, help=
"Number of points at which to evaluate function")
83 parser.add_argument(
"--low", type=float, default=0., help=
"Lower limit of tested range")
84 parser.add_argument(
"--high", type=float, default=20., help=
"Upper limit of tested range")
86 args = parser.parse_args()
def get_coverage(mu, bounds)
def test_wilks_coverage(num_pts, lower_lim, upper_lim)