Beispiel #1
0
"""Example test for a pdf or function"""

import zfit
# Important, do the imports below
from zfit.core.testing import setup_function, teardown_function, tester

import zfit_physics as zphys

# specify globals here. Do NOT add any TensorFlow but just pure python
param1_true = 0.3
param2_true = 1.2


def test_special_property1():
    # test special properties  here
    assert True


# register the pdf here and provide sets of working parameter configurations


def gauss_params_factory():
    mu = zfit.Parameter('mu', param1_true)
    sigma = zfit.Parameter('sigma', param2_true)
    return {"mu": mu, "sigma": sigma}


tester.register_pdf(pdf_class=zfit.pdf.Gauss,
                    params_factories=gauss_params_factory)
Beispiel #2
0
    kde = zphys.unstable.pdf.GaussianKDE(data=data, bandwidth=sigma, obs=obs)

    probs = kde.pdf(x=data + 0.03)

    from zfit.loss import UnbinnedNLL
    data = tf.random.normal(shape=(100, 1))
    data = zfit.Data.from_tensor(tensor=data, obs=obs)
    nll = UnbinnedNLL(model=kde, data=data)

    minimizer = zfit.minimize.Minuit()

    minimum = minimizer.minimize(loss=nll)
    assert minimum.converged


# register the pdf here and provide sets of working parameter configurations


def _kde_params_factory():
    data = np.random.normal(size=(100, 3))
    sigmas = [0.5, 1., 2]
    lower = ((-5, -5, -5), )
    upper = ((5, 5, 5), )
    obs = zfit.Space(["obs1", "obs2", "obs3"], limits=(lower, upper))
    return {"data": data, "sigma": sigmas, "obs": obs}


tester.register_pdf(pdf_class=zphys.unstable.pdf.GaussianKDE,
                    params_factories=_kde_params_factory())
Beispiel #3
0
nr = 4.0

bounds = (-10, 3.0)
lbounds = (bounds[0], mu)
rbounds = (mu, bounds[1])


def _cb_params_factory(name_add=""):
    mu_ = zfit.Parameter('mu_cb' + name_add, mu)
    sigma_ = zfit.Parameter('sigma_cb' + name_add, sigma)
    alphal_ = zfit.Parameter('alphal_cb' + name_add, alphal)
    nl_ = zfit.Parameter('nl_cb' + name_add, nl)
    return {"mu": mu_, "sigma": sigma_, "alpha": alphal_, "n": nl_}


tester.register_pdf(pdf_class=CrystalBall, params_factories=_cb_params_factory)


def sample_testing(pdf):
    sample = pdf.sample(n=1000, limits=(-0.5, 1.5))
    sample_np = sample.numpy()
    assert not any(np.isnan(sample_np))


def eval_testing(pdf, x):
    probs = pdf.pdf(x).numpy()
    assert not any(np.isnan(probs))
    return probs


def test_cb_dcb():