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

Make prior sampling more robust.

parent 7ddbcf6d
No related branches found
No related tags found
1 merge request!738Resolve "Make initial draws more robust"
Pipeline #107876 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