def test_UnbinnedNLL_mask(): c = UnbinnedNLL([1, np.nan, 2], lambda x, a: x + a) assert c.mask is None assert np.isnan(c(0)) == True c.mask = np.arange(3) != 1 assert_equal(c.mask, (True, False, True)) assert np.isnan(c(0)) == False
def test_UnbinnedNLL(unbinned, verbose): mle, x = unbinned def pdf(x, mu, sigma): return norm(mu, sigma).pdf(x) cost = UnbinnedNLL(x, pdf, verbose=verbose) m = Minuit(cost, mu=0, sigma=1, limit_sigma=(0, None)) m.migrad() assert_allclose(m.args, mle[1:], atol=1e-3) assert m.errors["mu"] == pytest.approx(1000**-0.5, rel=0.05)
def test_UnbinnedNLL(unbinned, verbose): mle, x = unbinned def pdf(x, mu, sigma): return norm(mu, sigma).pdf(x) cost = UnbinnedNLL(x, pdf, verbose=verbose) assert cost.ndata == np.inf m = Minuit(cost, mu=0, sigma=1) m.limits["sigma"] = (0, None) m.migrad() assert_allclose(m.values, mle[1:], atol=1e-3) assert m.errors["mu"] == pytest.approx(1000**-0.5, rel=0.05) assert_equal(m.fmin.reduced_chi2, np.nan)
def test_UnbinnedNLL_properties(): def pdf(x, a, b): return 0 c = UnbinnedNLL([1, 2], pdf) assert c.pdf is pdf with pytest.raises(AttributeError): c.pdf = None assert_equal(c.data, [1, 2]) c.data = [2, 3] assert_equal(c.data, [2, 3]) with pytest.raises(ValueError): c.data = [1, 2, 3] assert c.verbose == 0 c.verbose = 1 assert c.verbose == 1
def test_UnbinnedNLL_mask(): c = UnbinnedNLL([1, np.nan, 2], lambda x, a: x + a) assert np.isnan(c(0)) == True c.mask = np.arange(3) != 1 assert np.isnan(c(0)) == False