Skip to content
Snippets Groups Projects
Commit 63ac9d2b authored by Colm Talbot's avatar Colm Talbot
Browse files

Merge branch '467-make-initial-draws-more-robust' into 'master'

Resolve "Make initial draws more robust"

Closes #467

See merge request !738
parents 7ddbcf6d 04398ab3
No related branches found
No related tags found
1 merge request!738Resolve "Make initial draws more robust"
Pipeline #110041 passed
......@@ -439,7 +439,10 @@ class Sampler(object):
return np.array(unit_cube), np.array(parameters), np.array(likelihood)
def check_draw(self, theta, warning=True):
""" Checks if the draw will generate an infinite prior or likelihood
"""
Checks if the draw will generate an infinite prior or likelihood
Also catches the output of `numpy.nan_to_num`.
Parameters
----------
......@@ -452,11 +455,12 @@ class Sampler(object):
True if the likelihood and prior are finite, false otherwise
"""
if np.isinf(self.log_prior(theta)):
bad_values = [np.inf, np.nan_to_num(np.inf), np.nan]
if abs(self.log_prior(theta)) in bad_values:
if warning:
logger.warning('Prior draw {} has inf prior'.format(theta))
return False
if np.isinf(self.log_likelihood(theta)):
if abs(self.log_likelihood(theta)) in bad_values:
if warning:
logger.warning('Prior draw {} has inf likelihood'.format(theta))
return False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment