Skip to content

Commit

Permalink
avoid numerical issues with low likelihood values
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesBuchner committed May 7, 2020
1 parent 1bbb356 commit 124b2ea
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions snowline.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def create_logger(module_name, log_dir=None, level=logging.INFO):
registered.
"""
logger = logging.getLogger(str(module_name))
logger.setLevel(logging.DEBUG)
first_logger = logger.handlers == []
if log_dir is not None and first_logger:
# create file handler which logs even debug messages
Expand Down Expand Up @@ -412,7 +413,8 @@ def log_target(u):
if (u > 1).any() or (u < 0).any():
return -np.inf
p = transform(u)
return loglike(p)
L = loglike(p)
return L - self.optL

gauss = Gauss(optu, cov)
N = num_gauss_samples
Expand Down Expand Up @@ -477,7 +479,7 @@ def log_target(u):
ess_fraction = ess(weights)
if self.log:
self.logger.debug(" sampling efficiency: %.3f%%" % (ess_fraction * 100))
self.logger.debug(" obtained %d new effective samples" % (ess_fraction * len(weights)))
self.logger.debug(" obtained %.0f new effective samples" % (ess_fraction * len(weights)))

samples, weights = self._collect_samples(sampler, all=True, mixes=mixes)
ess_fraction = ess(weights)
Expand Down Expand Up @@ -663,9 +665,9 @@ def _update_results(self, samples, weights):
eqsamples = np.asarray([self.transform(u) for u in eqsamples_u])

results = dict(
z=integral_estimator,
zerr=integral_uncertainty_estimator,
logz=logZ,
z=integral_estimator * np.exp(self.optL),
zerr=integral_uncertainty_estimator * np.exp(self.optL),
logz=logZ + self.optL,
logzerr=logZerr,
ess=ess_fraction,
paramnames=self.paramnames,
Expand Down

0 comments on commit 124b2ea

Please sign in to comment.