From 56e60c4e91c74cf3d2d1a7d8bdfc021101cc0fa2 Mon Sep 17 00:00:00 2001 From: sschmidt23 Date: Tue, 28 May 2024 18:46:51 -0700 Subject: [PATCH 1/2] add check of f0 sum, norm if >1 --- src/rail/estimation/algos/bpz_lite.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rail/estimation/algos/bpz_lite.py b/src/rail/estimation/algos/bpz_lite.py index 199d3ec..4d797b9 100644 --- a/src/rail/estimation/algos/bpz_lite.py +++ b/src/rail/estimation/algos/bpz_lite.py @@ -138,7 +138,13 @@ def _find_fractions(self): self.fo_arr = np.array([frac_results[0]]) self.kt_arr = np.array([frac_results[1]]) else: - self.fo_arr = frac_results[:self.ntyp - 1] + tmpfo = frac_results[:self.ntyp - 1] + # minimizer can sometimes give fractions greater than one, if so normalize + fracnorm = np.sum(tmpfo) + if fracnorm > 1.: + print("bad norm for f0, normalizing") + tmpfo /= fracnorm + self.fo_arr = tmpfo self.kt_arr = frac_results[self.ntyp - 1:] def _dndz_likelihood(self, params): From 415a9fb2722a858f2c50bcda312b7c46c2d21060 Mon Sep 17 00:00:00 2001 From: sschmidt23 Date: Tue, 28 May 2024 18:50:17 -0700 Subject: [PATCH 2/2] add pragma, I've tested this and it's hard to trigger --- src/rail/estimation/algos/bpz_lite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rail/estimation/algos/bpz_lite.py b/src/rail/estimation/algos/bpz_lite.py index 4d797b9..1480123 100644 --- a/src/rail/estimation/algos/bpz_lite.py +++ b/src/rail/estimation/algos/bpz_lite.py @@ -141,7 +141,7 @@ def _find_fractions(self): tmpfo = frac_results[:self.ntyp - 1] # minimizer can sometimes give fractions greater than one, if so normalize fracnorm = np.sum(tmpfo) - if fracnorm > 1.: + if fracnorm > 1.: # pragma: no cover print("bad norm for f0, normalizing") tmpfo /= fracnorm self.fo_arr = tmpfo