Пример #1
0
def test_extended_gauss():
    mu1 = Parameter("mu11", 1.0)
    mu2 = Parameter("mu21", 12.0)
    mu3 = Parameter("mu31", 3.0)
    sigma1 = Parameter("sigma11", 1.0)
    sigma2 = Parameter("sigma21", 12.0)
    sigma3 = Parameter("sigma31", 33.0)
    yield1 = Parameter("yield11", 150.0)
    yield2 = Parameter("yield21", 550.0)
    yield3 = Parameter("yield31", 2500.0)

    gauss1 = Gauss(mu=mu1, sigma=sigma1, obs=obs1, name="gauss11")
    gauss2 = Gauss(mu=mu2, sigma=sigma2, obs=obs1, name="gauss21")
    gauss3 = Gauss(mu=mu3, sigma=sigma3, obs=obs1, name="gauss31")
    gauss1 = gauss1.create_extended(yield1)
    gauss2 = gauss2.create_extended(yield2)
    gauss3 = gauss3.create_extended(yield3)

    gauss_dists = [gauss1, gauss2, gauss3]

    sum_gauss = SumPDF(pdfs=gauss_dists)
    integral_true = (sum_gauss.integrate((-1, 5), ) * sum_gauss.get_yield())

    assert zfit.run(integral_true) == pytest.approx(
        zfit.run(sum_gauss.ext_integrate((-1, 5), )))
    normalization_testing(pdf=sum_gauss, limits=obs1)
Пример #2
0
def test_extended_gauss():
    with tf.name_scope("gauss_params2"):
        mu1 = Parameter("mu11", 1.)
        mu2 = Parameter("mu21", 12.)
        mu3 = Parameter("mu31", 3.)
        sigma1 = Parameter("sigma11", 1.)
        sigma2 = Parameter("sigma21", 12.)
        sigma3 = Parameter("sigma31", 33.)
        yield1 = Parameter("yield11", 150.)
        yield2 = Parameter("yield21", 550.)
        yield3 = Parameter("yield31", 2500.)
        sum_yields = 150 + 550 + 2500

        gauss1 = Gauss(mu=mu1, sigma=sigma1, obs=obs1, name="gauss11")
        gauss2 = Gauss(mu=mu2, sigma=sigma2, obs=obs1, name="gauss21")
        gauss3 = Gauss(mu=mu3, sigma=sigma3, obs=obs1, name="gauss31")
        gauss1 = gauss1.create_extended(yield1)
        gauss2 = gauss2.create_extended(yield2)
        gauss3 = gauss3.create_extended(yield3)

        gauss_dists = [gauss1, gauss2, gauss3]

        sum_gauss = SumPDF(
            pdfs=gauss_dists,
            obs=obs1,
        )

    normalization_testing(pdf=sum_gauss, normalization_value=sum_yields)
Пример #3
0
def sum_prod_gauss():
    # define parameters
    mu1 = Parameter("mu1a123", mu1_true)
    mu2 = Parameter("mu2a123", mu2_true)
    mu3 = Parameter("mu3a123", mu3_true)
    sigma1 = Parameter("sigma1a123", sigma1_true)
    sigma2 = Parameter("sigma2a123", sigma2_true)
    sigma3 = Parameter("sigma3a123", sigma3_true)

    # Gauss for sum, same axes
    gauss1 = Gauss(mu=mu1, sigma=sigma1, obs=obs1, name="gauss1asum")
    gauss2 = Gauss(mu=mu2, sigma=sigma2, obs=obs1, name="gauss2asum")
    gauss3 = Gauss(mu=mu3, sigma=sigma3, obs=obs1, name="gauss3asum")
    gauss_dists = [gauss1, gauss2, gauss3]

    sum_gauss = SumPDF(pdfs=gauss_dists, fracs=fracs, obs=obs1)
    prod_gauss = ProductPDF(pdfs=gauss_dists, obs=obs1)

    # Gauss for product, independent
    gauss13 = Gauss(mu=mu1, sigma=sigma1, obs='a', name="gauss1a")
    gauss23 = Gauss(mu=mu2, sigma=sigma2, obs='b', name="gauss2a")
    gauss33 = Gauss(mu=mu3, sigma=sigma3, obs='c', name="gauss3a")
    gauss_dists3 = [gauss13, gauss23, gauss33]
    prod_gauss_3d = ProductPDF(pdfs=gauss_dists3, obs=['a', 'b', 'c'])
    # prod_gauss_3d.update_integration_options(draws_per_dim=33)

    gauss12 = Gauss(mu=mu1, sigma=sigma1, obs='d', name="gauss12a")
    gauss22 = Gauss(mu=mu2, sigma=sigma2, obs='a', name="gauss22a")
    gauss32 = Gauss(mu=mu3, sigma=sigma3, obs='c', name="gauss32a")
    gauss_dists2 = [gauss12, gauss22, gauss32]
    prod_gauss_4d = ProductPDF(pdfs=gauss_dists2 + [prod_gauss_3d],
                               obs=['a', 'b', 'c', 'd'])
    # prod_gauss_4d.update_integration_options(draws_per_dim=33)
    return sum_gauss, prod_gauss, prod_gauss_3d, prod_gauss_4d, gauss_dists3, gauss_dists2, gauss_dists
Пример #4
0
def test_implicit_extended():
    # return  # TODO(Mayou36): deps: impl_copy,

    param1 = Parameter('param1', 12.)
    yield1 = Parameter('yield1', 21.)
    param2 = Parameter('param2', 13., floating=False)
    yield2 = Parameter('yield2', 31., floating=False)
    pdf1 = SimplePDF(func=lambda self, x: x * param1, obs=obs1)
    pdf2 = SimplePDF(func=lambda self, x: x * param2, obs=obs1)
    extended_pdf = yield1 * pdf1 + yield2 * pdf2
    with pytest.raises(ModelIncompatibleError):
        true_extended_pdf = SumPDF(pdfs=[pdf1, pdf2], obs=obs1)
    assert isinstance(extended_pdf, SumPDF)
    assert extended_pdf.is_extended
Пример #5
0
def sum_gaussians():
    gauss_dists = create_gaussians()
    sum_gauss = SumPDF(pdfs=gauss_dists, fracs=fracs, obs=obs1)
    return sum_gauss