Skip to content

Commit

Permalink
Make warning level less conservative (was far too conservative before)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmcewen committed May 2, 2024
1 parent 2fdb5d9 commit f456755
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions harmonic/evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def check_basic_diagnostic(self):
"""

NSAMPLES_EFF_WARNING_LEVEL = 30
LNARG_WARNING_LEVEL = 400.0
LNARG_WARNING_LEVEL = 1000.0

tests_pass = True

Expand Down Expand Up @@ -390,8 +390,12 @@ def compute_evidence(self):
evidence_inv = np.exp(self.ln_evidence_inv)
evidence_inv_var = np.exp(self.ln_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.")
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)

Expand Down Expand Up @@ -520,8 +524,8 @@ def compute_bayes_factor(ev1, ev2):
ValueError: Raised if model 1 does not have chains added.
ValueError: Raised if model 2 does not have chains added.
ValueError: If inverse evidence or its variance for model 1 or model 2 too large
ValueError: If inverse evidence or its variance for model 1 or model 2 too large
to store in non-log space.
"""
Expand All @@ -540,10 +544,18 @@ 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.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.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.")
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.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)

Expand Down Expand Up @@ -598,9 +610,13 @@ def compute_ln_bayes_factor(ev1, ev2):
evidence_inv_var_ev2 = np.exp(ev2.ln_evidence_inv_var)

if np.isnan(evidence_inv_ev1) or np.isnan(evidence_inv_var_ev1):
raise ValueError("Evidence for model 1 is too large to represent in non-log space. Use log-space values instead.")
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):
raise ValueError("Evidence for model 2 is too large to represent in non-log space. Use log-space values instead.")
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)

Expand Down

0 comments on commit f456755

Please sign in to comment.