From 345972ba3fb9a2eb7f51623dbf93810240cfd22b Mon Sep 17 00:00:00 2001 From: darcones Date: Mon, 15 Jul 2024 14:02:54 +0200 Subject: [PATCH] Added guard against NaN --- probeye/inference/koh/likelihood_models.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/probeye/inference/koh/likelihood_models.py b/probeye/inference/koh/likelihood_models.py index 4669b1d..efccb98 100644 --- a/probeye/inference/koh/likelihood_models.py +++ b/probeye/inference/koh/likelihood_models.py @@ -84,6 +84,10 @@ def loglike( # in this case, 'variance' is a scalar # Uses Sargsyan2019 Eq. 15 as ABC likelihood function # FIXME: modified to incorporate the noise model, now through the tolerance + + if np.isnan(response_vector).any(): + return -np.inf + if not hasattr(self, "weight_mean"): self.weight_mean = 1 if not hasattr(self, "weight_std"): @@ -132,6 +136,8 @@ def loglike( Computes the log-likelihood of this model. For more information, check out the doc-string of the parent class (SolverLikelihoodBase). """ + if np.isnan(response_vector).any(): + return -np.inf std_model, std_meas, stds_are_scalar = self.std_values(prms) variance = np.power(std_model, 2) @@ -172,10 +178,14 @@ def loglike( doc-string of the parent class (SolverLikelihoodBase). """ + if np.isnan(response_vector).any(): + return -np.inf + std_model, std_meas, stds_are_scalar = self.std_values(prms) variance = np.power(std_model, 2) n = len(residual_vector) - sigma_model_population = np.sqrt(self.gamma**2 * np.square(residual_vector)) + + sigma_model_population = np.sqrt(self.gamma**2 * np.square(residual_vector)+variance) sigma_model_sample = np.sqrt(np.square(response_vector[1])+variance) population_variance = (np.var(np.divide(residual_vector, sigma_model_population)) + 1) # std_model**2*np.var(np.reciprocal(sigma_model_population)) + @@ -215,6 +225,9 @@ def loglike( doc-string of the parent class (SolverLikelihoodBase). """ + if np.isnan(response_vector).any(): + return -np.inf + std_model, std_meas, stds_are_scalar = self.std_values(prms) variance = np.power(std_model, 2) n = len(residual_vector)