Skip to content

Commit

Permalink
Added guard against NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
danielandresarcones committed Jul 15, 2024
1 parent 7201280 commit 345972b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion probeye/inference/koh/likelihood_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)) +
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 345972b

Please sign in to comment.