From d5ee16a2b2b5c21b2af1f5a0464921a8baf47fbf Mon Sep 17 00:00:00 2001 From: CosmoMatt Date: Wed, 1 May 2024 15:53:33 +0100 Subject: [PATCH] make checks sensitive to inf values in evidence --- harmonic/evidence.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/harmonic/evidence.py b/harmonic/evidence.py index 13cb794..7b21f9b 100644 --- a/harmonic/evidence.py +++ b/harmonic/evidence.py @@ -424,7 +424,7 @@ def compute_evidence(self): evidence_inv = np.exp(self.ln_evidence_inv) evidence_inv_var = np.exp(self.ln_evidence_inv_var) - if np.isnan(evidence_inv) or np.isnan(evidence_inv_var): + if np.isinf(np.nan_to_num(evidence_inv, nan=np.inf)) or np.isinf(np.nan_to_num(evidence_inv_var, nan=np.inf)): raise ValueError("Evidence is too large to represent in non-log space. Use log-space values instead.") common_factor = 1.0 + evidence_inv_var / (evidence_inv**2) @@ -574,9 +574,9 @@ def compute_bayes_factor(ev1, ev2): evidence_inv_ev2 = np.exp(ev2.ln_evidence_inv) evidence_inv_var_ev2 = np.exp(ev2.ln_evidence_inv_var) - if np.isnan(evidence_inv_ev1) or np.isnan(evidence_inv_var_ev1): + if np.isinf(np.nan_to_num(evidence_inv_ev1, nan=np.inf)) or np.isinf(np.nan_to_num(evidence_inv_var_ev1, nan=np.inf)): raise ValueError("Evidence for model 1 is too large to represent in non-log space. Use log-space values instead.") - if np.isnan(evidence_inv_ev2) or np.isnan(evidence_inv_var_ev2): + if np.isinf(np.nan_to_num(evidence_inv_ev2, nan=np.inf)) or np.isinf(np.nan_to_num(evidence_inv_var_ev2, nan=np.inf)): raise ValueError("Evidence for model 2 is too large to represent in non-log space. Use log-space values instead.") common_factor = 1.0 + evidence_inv_var_ev1 / (evidence_inv_ev1**2)