Example #1
0
def test_draw_ulh_with_minuit():
    np.random.seed(0)
    data = np.random.randn(1000)
    plt.figure()
    ulh = UnbinnedLH(gaussian, data)
    minuit = Minuit(ulh, mean=0, sigma=1)
    ulh.draw(minuit)
Example #2
0
def test_draw_residual_ulh_norm():
    np.random.seed(0)
    data = np.random.randn(1000)
    ulh = UnbinnedLH(gaussian, data)
    ulh.draw_residual(args=(0., 1.), norm=True)
    plt.ylim(-7., 3.)
    plt.xlim(-4., 3.)
Example #3
0
def test_draw_residual_ulh_norm_options():
    np.random.seed(0)
    data = np.random.randn(1000)
    ulh = UnbinnedLH(gaussian, data)
    ulh.draw_residual(args=(0., 1.),
                      norm=True,
                      color='green',
                      capsize=2,
                      grid=False,
                      zero_line=False)
Example #4
0
def test_ulh_with_parts():
    np.random.seed(0)
    data = np.random.randn(10000)
    shifted = data + 3.
    data = np.append(data, [shifted])
    g1 = rename(gaussian, ['x', 'lmu', 'lsigma'])
    g2 = rename(gaussian, ['x', 'rmu', 'rsigma'])
    allpdf = AddPdfNorm(g1, g2)
    ulh = UnbinnedLH(allpdf, data)
    ulh.draw(args=(0, 1, 3, 1, 0.5), parts=True)
Example #5
0
def test_draw_simultaneous():
    np.random.seed(0)
    data = np.random.randn(10000)
    shifted = data + 3.
    g1 = rename(gaussian, ['x', 'lmu', 'sigma'])
    g2 = rename(gaussian, ['x', 'rmu', 'sigma'])
    ulh1 = UnbinnedLH(g1, data)
    ulh2 = UnbinnedLH(g2, shifted)
    sim = SimultaneousFit(ulh1, ulh2)
    sim.draw(args=(0, 1, 3))
Example #6
0
def test_draw_simultaneous_prefix():
    np.random.seed(0)
    data = np.random.randn(10000)
    shifted = data + 3.
    g1 = rename(gaussian, ['x', 'lmu', 'sigma'])
    g2 = rename(gaussian, ['x', 'rmu', 'sigma'])
    ulh1 = UnbinnedLH(g1, data)
    ulh2 = UnbinnedLH(g2, shifted)
    sim = SimultaneousFit(ulh1, ulh2, prefix=['g1_', 'g2_'])
    minuit = Minuit(sim, g1_lmu=0., g1_sigma=1., g2_rmu=0., g2_sigma=1.,
                    print_level=0)
    minuit.migrad()
    sim.draw(minuit)
Example #7
0
def test_draw_simultaneous_prefix():
    np.random.seed(0)
    data = np.random.randn(10000)
    shifted = data + 3.0
    g1 = rename(gaussian, ["x", "lmu", "sigma"])
    g2 = rename(gaussian, ["x", "rmu", "sigma"])
    ulh1 = UnbinnedLH(g1, data)
    ulh2 = UnbinnedLH(g2, shifted)
    sim = SimultaneousFit(ulh1, ulh2, prefix=["g1_", "g2_"])
    minuit = Minuit(
        sim, g1_lmu=0.0, g1_sigma=1.0, g2_rmu=0.0, g2_sigma=1.0, print_level=0
    )
    minuit.migrad()
    sim.draw(minuit)
Example #8
0
 def test_UnbinnedLH(self):
     f = gaussian
     assert_equal(list(describe(f)), ['x', 'mean', 'sigma'])
     lh = UnbinnedLH(
         gaussian,
         self.data,
     )
     assert_equal(list(describe(lh)), ['mean', 'sigma'])
     assert_almost_equal(lh(0, 1), 28188.201229348757)
     minuit = iminuit.Minuit(lh)
     assert_equal(minuit.errordef, 0.5)
Example #9
0
 def test_UnbinnedLH(self):
     f = gaussian
     assert list(describe(f)) == ['x', 'mean', 'sigma']
     lh = UnbinnedLH(
         gaussian,
         self.data,
     )
     assert list(describe(lh)) == ['mean', 'sigma']
     assert_allclose(lh(0, 1), 28188.201229348757)
     minuit = iminuit.Minuit(lh)
     assert_allclose(minuit.errordef, 0.5)
Example #10
0
 def test_simultaneous(self):
     np.random.seed(0)
     data = np.random.randn(10000)
     shifted = data + 3.0
     g1 = rename(gaussian, ["x", "lmu", "sigma"])
     g2 = rename(gaussian, ["x", "rmu", "sigma"])
     ulh1 = UnbinnedLH(g1, data)
     ulh2 = UnbinnedLH(g2, shifted)
     sim = SimultaneousFit(ulh1, ulh2)
     assert describe(sim) == ["lmu", "sigma", "rmu"]
     minuit = iminuit.Minuit(sim, sigma=1.2, pedantic=False, print_level=0)
     minuit.migrad()
     assert minuit.migrad_ok()
     assert_allclose(minuit.values["lmu"],
                     0.0,
                     atol=2 * minuit.errors["lmu"])
     assert_allclose(minuit.values["rmu"],
                     3.0,
                     atol=2 * minuit.errors["rmu"])
     assert_allclose(minuit.values["sigma"],
                     1.0,
                     atol=2 * minuit.errors["sigma"])
Example #11
0
 def test_simultaneous(self):
     np.random.seed(0)
     data = np.random.randn(10000)
     shifted = data + 3.
     g1 = rename(gaussian, ['x', 'lmu', 'sigma'])
     g2 = rename(gaussian, ['x', 'rmu', 'sigma'])
     ulh1 = UnbinnedLH(g1, data)
     ulh2 = UnbinnedLH(g2, shifted)
     sim = SimultaneousFit(ulh1, ulh2)
     assert_equal(describe(sim), ['lmu', 'sigma', 'rmu'])
     minuit = iminuit.Minuit(sim, sigma=1.2, pedantic=False, print_level=0)
     minuit.migrad()
     assert (minuit.migrad_ok())
     assert_almost_equal(minuit.values['lmu'],
                         0.,
                         delta=2 * minuit.errors['lmu'])
     assert_almost_equal(minuit.values['rmu'],
                         3.,
                         delta=2 * minuit.errors['rmu'])
     assert_almost_equal(minuit.values['sigma'],
                         1.,
                         delta=2 * minuit.errors['sigma'])
Example #12
0
def test_draw_ulh_extend():
    np.random.seed(0)
    data = np.random.randn(1000)
    ulh = UnbinnedLH(Extended(gaussian), data, extended=True)
    ulh.draw(args=(0., 1., 1000))
Example #13
0
def test_draw_ulh():
    np.random.seed(0)
    data = np.random.randn(1000)
    ulh = UnbinnedLH(gaussian, data)
    ulh.draw(args=(0., 1.))
Example #14
0
def test_draw_ulh_with_minuit():
    np.random.seed(0)
    data = np.random.randn(1000)
    ulh = UnbinnedLH(gaussian, data)
    minuit = Minuit(ulh, mean=0, sigma=1)
    ulh.draw(minuit)
Example #15
0
def test_draw_ulh_extend_residual_norm():
    np.random.seed(0)
    data = np.random.randn(1000)
    ulh = UnbinnedLH(Extended(gaussian), data, extended=True)
    ulh.draw_residual(args=(0., 1., 1000), norm=True)
    plt.ylim(-7.,3.)
Example #16
0
def test_draw_residual_ulh_norm_options():
    np.random.seed(0)
    data = np.random.randn(1000)
    ulh = UnbinnedLH(gaussian, data)
    ulh.draw_residual(args=(0., 1.), norm=True, color='green', capsize=2,
                      grid=False, zero_line=False)
Example #17
0
def test_draw_residual_ulh_norm():
    np.random.seed(0)
    data = np.random.randn(1000)
    ulh = UnbinnedLH(gaussian, data)
    ulh.draw_residual(args=(0., 1.), norm=True, show_errbars=False)
Example #18
0
def test_draw_residual_ulh():
    np.random.seed(0)
    data = np.random.randn(1000)
    ulh = UnbinnedLH(gaussian, data)
    ulh.draw_residual(args=(0.0, 1.0))
Example #19
0
def test_draw_residual_ulh_norm():
    np.random.seed(0)
    data = np.random.randn(1000)
    plt.figure()
    ulh = UnbinnedLH(gaussian, data)
    ulh.draw_residual(args=(0., 1.), norm=True)