Ejemplo n.º 1
0
def test_ExtendedBinnedNLL_mask():
    c = ExtendedBinnedNLL([1, 1000, 2], [0, 1, 2, 3], expon_cdf)
    assert c.ndata == 3

    c_unmasked = c(2)
    c.mask = np.arange(3) != 1
    assert c(2) < c_unmasked
    assert c.ndata == 2
Ejemplo n.º 2
0
def test_weighted_ExtendedBinnedNLL():
    def cdf(x, a, b):
        return b * (1 - np.exp(-a * x))

    xe = np.array([0, 1, 10])
    n = np.diff(cdf(xe, 1, 100))
    m1 = Minuit(ExtendedBinnedNLL(n, xe, cdf), 1, 100)
    m1.migrad()
    assert_allclose(m1.values, (1, 100), rtol=1e-2)

    w = np.transpose((n, 4 * n))
    m2 = Minuit(ExtendedBinnedNLL(w, xe, cdf), 1, 100)
    m2.migrad()
    assert_allclose(m2.values, (1, 100), rtol=1e-2)

    assert m2.errors[0] == pytest.approx(2 * m1.errors[0], rel=1e-2)
Ejemplo n.º 3
0
def test_ExtendedBinnedNLL(binned, verbose):
    mle, nx, xe = binned

    def scaled_cdf(x, n, mu, sigma):
        return n * norm(mu, sigma).cdf(x)

    cost = ExtendedBinnedNLL(nx, xe, scaled_cdf, verbose=verbose)
    m = Minuit(cost, n=mle[0], mu=0, sigma=1)
    m.limits["n"] = (0, None)
    m.limits["sigma"] = (0, None)
    m.migrad()
    # binning loses information compared to unbinned case
    assert_allclose(m.values, mle, rtol=0.15)
    assert m.errors["mu"] == pytest.approx(1000 ** -0.5, rel=0.05)
Ejemplo n.º 4
0
def test_ExtendedBinnedNLL_properties():
    def cdf(x, a):
        return 0

    c = ExtendedBinnedNLL([1], [1, 2], cdf)
    assert c.scaled_cdf is cdf
Ejemplo n.º 5
0
def test_ExtendedBinnedNLL_bad_input():
    with pytest.raises(ValueError):
        ExtendedBinnedNLL([1], [1], lambda x, a: 0)
Ejemplo n.º 6
0
def test_ExtendedBinnedNLL_mask():
    c = ExtendedBinnedNLL([1, 1000, 2], [0, 1, 2, 3], lambda x, a: a * x)

    assert c(2) == pytest.approx(-700, rel=0.1)
    c.mask = np.arange(3) != 1
    assert c(2) == pytest.approx(2, rel=0.1)