From 6f298bdae49261b79fc1a07e334b68291f2a6a42 Mon Sep 17 00:00:00 2001 From: dlanci <33418551+dlanci@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:20:18 +0100 Subject: [PATCH 1/4] Update sweights.py Added customisable tolerance in compute_sweights. This is helpful in test modes. --- src/hepstats/splot/sweights.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hepstats/splot/sweights.py b/src/hepstats/splot/sweights.py index 0fbe1f69..6a397dfe 100644 --- a/src/hepstats/splot/sweights.py +++ b/src/hepstats/splot/sweights.py @@ -26,7 +26,7 @@ def is_sum_of_extended_pdfs(model) -> bool: return all(m.is_extended for m in model.get_models()) and model.is_extended -def compute_sweights(model, x: np.ndarray) -> dict[Any, np.ndarray]: +def compute_sweights(model, x: np.ndarray, atol_exceptions : float | None = None) -> dict[Any, np.ndarray]: """Computes sWeights from probability density functions for different components/species in a fit model (for instance signal and background) fitted on some data `x`. @@ -108,7 +108,8 @@ def compute_sweights(model, x: np.ndarray) -> dict[Any, np.ndarray]: MLSR = pN.sum(axis=0) atol_warning = 5e-3 - atol_exceptions = 5e-2 + if not atol_exceptions: + atol_exceptions = 5e-2 def msg_fn(tolerance): msg = ( From c64bc3fb7549882de5f0bbad2f039cb3c3e411e8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 14:22:09 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/hepstats/splot/sweights.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hepstats/splot/sweights.py b/src/hepstats/splot/sweights.py index 6a397dfe..9f125317 100644 --- a/src/hepstats/splot/sweights.py +++ b/src/hepstats/splot/sweights.py @@ -26,7 +26,7 @@ def is_sum_of_extended_pdfs(model) -> bool: return all(m.is_extended for m in model.get_models()) and model.is_extended -def compute_sweights(model, x: np.ndarray, atol_exceptions : float | None = None) -> dict[Any, np.ndarray]: +def compute_sweights(model, x: np.ndarray, atol_exceptions: float | None = None) -> dict[Any, np.ndarray]: """Computes sWeights from probability density functions for different components/species in a fit model (for instance signal and background) fitted on some data `x`. From 3964418116b0386c98250b60c0dc92aa36d8fa24 Mon Sep 17 00:00:00 2001 From: Jonas Eschle Date: Tue, 8 Oct 2024 16:05:26 -0400 Subject: [PATCH 3/4] Add docs --- src/hepstats/splot/sweights.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hepstats/splot/sweights.py b/src/hepstats/splot/sweights.py index 9f125317..0a777ec3 100644 --- a/src/hepstats/splot/sweights.py +++ b/src/hepstats/splot/sweights.py @@ -26,7 +26,7 @@ def is_sum_of_extended_pdfs(model) -> bool: return all(m.is_extended for m in model.get_models()) and model.is_extended -def compute_sweights(model, x: np.ndarray, atol_exceptions: float | None = None) -> dict[Any, np.ndarray]: +def compute_sweights(model, x: np.ndarray, *,atol_exceptions: float | None = None) -> dict[Any, np.ndarray]: """Computes sWeights from probability density functions for different components/species in a fit model (for instance signal and background) fitted on some data `x`. @@ -35,6 +35,9 @@ def compute_sweights(model, x: np.ndarray, atol_exceptions: float | None = None) Args: model: sum of extended pdfs. x: data on which `model` is fitted + atol_exceptions: absolute tolerance to check if the Maximum Likelihood Sum Rule sanity check, + described in equation 17 of arXiv:physics/0402083, failed. Sum of yields should be 1 with + an absolute tolerance of `atol_exceptions`. Returns: dictionary with yield parameters as keys, and sWeights for correspoind species as values. @@ -108,7 +111,7 @@ def compute_sweights(model, x: np.ndarray, atol_exceptions: float | None = None) MLSR = pN.sum(axis=0) atol_warning = 5e-3 - if not atol_exceptions: + if atol_exceptions is None: atol_exceptions = 5e-2 def msg_fn(tolerance): From a935ce0c4510b14a9e0351c93bf3d0891e2d1998 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 20:05:57 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/hepstats/splot/sweights.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hepstats/splot/sweights.py b/src/hepstats/splot/sweights.py index 0a777ec3..32703299 100644 --- a/src/hepstats/splot/sweights.py +++ b/src/hepstats/splot/sweights.py @@ -26,7 +26,7 @@ def is_sum_of_extended_pdfs(model) -> bool: return all(m.is_extended for m in model.get_models()) and model.is_extended -def compute_sweights(model, x: np.ndarray, *,atol_exceptions: float | None = None) -> dict[Any, np.ndarray]: +def compute_sweights(model, x: np.ndarray, *, atol_exceptions: float | None = None) -> dict[Any, np.ndarray]: """Computes sWeights from probability density functions for different components/species in a fit model (for instance signal and background) fitted on some data `x`.