From 4e2e271a87016b85a70c4d2be5e8ef90dc6afac1 Mon Sep 17 00:00:00 2001 From: iasonkrom Date: Fri, 15 Mar 2024 17:00:52 +0100 Subject: [PATCH] put m parameter first --- tests/test_pdf_cmsshape.py | 15 ++++++++------- zfit_physics/models/pdf_cmsshape.py | 24 ++++++++++++------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/tests/test_pdf_cmsshape.py b/tests/test_pdf_cmsshape.py index 9f123a7..f91d859 100644 --- a/tests/test_pdf_cmsshape.py +++ b/tests/test_pdf_cmsshape.py @@ -11,20 +11,20 @@ import zfit_physics as zphys # specify globals here. Do NOT add any TensorFlow but just pure python +m_true = 90.0 beta_true = 0.2 gamma_true = 0.3 -m_true = 90.0 -def create_cmsshape(gamma, beta, m, limits): +def create_cmsshape(m, beta, gamma, limits): obs = zfit.Space("obs1", limits) - cmsshape = zphys.pdf.CMSShape(gamma=gamma, beta=beta, m=m, obs=obs) + cmsshape = zphys.pdf.CMSShape(m=m, beta=beta, gamma=gamma, obs=obs) return cmsshape, obs def test_cmsshape_pdf(): # Test PDF here - cmsshape, _ = create_cmsshape(gamma=gamma_true, beta=beta_true, m=m_true, limits=(50, 130)) + cmsshape, _ = create_cmsshape(m=m_true, beta=beta_true, gamma=gamma_true, limits=(50, 130)) assert zfit.run(cmsshape.pdf(90.0)) == pytest.approx( cmsshape_numba.pdf(90.0, beta=beta_true, gamma=gamma_true, loc=m_true).item(), rel=1e-5 ) @@ -43,7 +43,7 @@ def test_cmsshape_pdf(): def test_cmsshape_integral(): # Test CDF and integral here - cmsshape, obs = create_cmsshape(gamma=gamma_true, beta=beta_true, m=m_true, limits=(50, 130)) + cmsshape, obs = create_cmsshape(m=m_true, beta=beta_true, gamma=gamma_true, limits=(50, 130)) full_interval_analytic = zfit.run(cmsshape.analytic_integrate(obs, norm_range=False)) full_interval_numeric = zfit.run(cmsshape.numeric_integrate(obs, norm_range=False)) true_integral = 0.99999 @@ -66,10 +66,11 @@ def test_cmsshape_integral(): # register the pdf here and provide sets of working parameter configurations def cmsshape_params_factory(): + m = zfit.Parameter("m", m_true) beta = zfit.Parameter("beta", beta_true) gamma = zfit.Parameter("gamma", gamma_true) - m = zfit.Parameter("m", m_true) - return {"beta": beta, "gamma": gamma, "m": m} + + return {"m": m, "beta": beta, "gamma": gamma} tester.register_pdf(pdf_class=zphys.pdf.CMSShape, params_factories=cmsshape_params_factory) diff --git a/zfit_physics/models/pdf_cmsshape.py b/zfit_physics/models/pdf_cmsshape.py index b3db5fe..58c4324 100644 --- a/zfit_physics/models/pdf_cmsshape.py +++ b/zfit_physics/models/pdf_cmsshape.py @@ -8,14 +8,14 @@ @z.function(wraps="tensor") -def cmsshape_pdf_func(x, beta, gamma, m): +def cmsshape_pdf_func(x, m, beta, gamma): """Calculate the CMSShape PDF. Args: x: value(s) for which the PDF will be calculated. + m: approximate center of the disribution. beta: steepness of the error function. gamma: steepness of the exponential distribution. - m: approximate center of the distribution. Returns: `tf.Tensor`: The calculated PDF values. @@ -44,14 +44,14 @@ def cmsshape_pdf_func(x, beta, gamma, m): @z.function(wraps="tensor") -def cmsshape_cdf_func(x, beta, gamma, m): +def cmsshape_cdf_func(x, m, beta, gamma): """Analtical function for the CDF of the CMSShape distribution. Args: x: value(s) for which the CDF will be calculated. + m: approximate center of the distribution. beta: steepness of the error function. gamma: steepness of the exponential distribution. - m: approximate center of the distribution. Returns: `tf.Tensor`: The calculated CDF values. @@ -81,11 +81,11 @@ def cmsshape_integral(limits: ztyping.SpaceType, params: dict, model) -> tf.Tens The calculated integral. """ lower, upper = limits.limit1d + m = params["m"] beta = params["beta"] gamma = params["gamma"] - m = params["m"] - lower_cdf = cmsshape_cdf_func(x=lower, beta=beta, gamma=gamma, m=m) - upper_cdf = cmsshape_cdf_func(x=upper, beta=beta, gamma=gamma, m=m) + lower_cdf = cmsshape_cdf_func(x=lower, m=m, beta=beta, gamma=gamma) + upper_cdf = cmsshape_cdf_func(x=upper, m=m, beta=beta, gamma=gamma) return upper_cdf - lower_cdf @@ -94,9 +94,9 @@ class CMSShape(zfit.pdf.BasePDF): def __init__( self, + m: ztyping.ParamTypeInput, beta: ztyping.ParamTypeInput, gamma: ztyping.ParamTypeInput, - m: ztyping.ParamTypeInput, obs: ztyping.ObsTypeInput, *, extended: Optional[ztyping.ExtendedInputType] = None, @@ -116,9 +116,9 @@ def __init__( and [numba-stats](https://github.com/HDembinski/numba-stats/blob/main/src/numba_stats/cmsshape.py) Args: + m: Approximate center of the distribution. beta: Steepness of the error function. gamma: Steepness of the exponential distribution. - m: Approximate center of the distribution. obs: |@doc:pdf.init.obs| Observables of the model. This will be used as the default space of the PDF and, if not given explicitly, as the normalization range. @@ -140,14 +140,14 @@ def __init__( the PDF for better identification. Has no programmatical functional purpose as identification. |@docend:pdf.init.name| """ - params = {"beta": beta, "gamma": gamma, "m": m} + params = {"m": m, "beta": beta, "gamma": gamma} super().__init__(obs=obs, params=params, name=name, extended=extended, norm=norm) def _unnormalized_pdf(self, x: tf.Tensor) -> tf.Tensor: + m = self.params["m"] beta = self.params["beta"] gamma = self.params["gamma"] - m = self.params["m"] - return cmsshape_pdf_func(x, beta, gamma, m) + return cmsshape_pdf_func(x=x, m=m, beta=beta, gamma=gamma) cmsshape_integral_limits = Space(axes=(0,), limits=(((ANY_LOWER,),), ((ANY_UPPER,),)))