From 9392cd585921b6098bf07aed20397401adad8033 Mon Sep 17 00:00:00 2001 From: lukashergt Date: Fri, 5 Jun 2020 18:33:10 +0100 Subject: [PATCH 1/2] change pc_prior to make use of scipy's .ppf * Use scipy's .ppf (inverse cdf) that comes with all major 1d distributions for PolyChord's prior function, which needs to map the unit hypercube to the physical parameters. Previously the prior bounds were used to effectively turn any 1d prior into a uniform prior. That's fine for the evidence, but causes problems e.g. for the relative entropy from prior to posterior. * Pass the loglikelihood to PolyChord instead of logposterior+logvolume. --- cobaya/samplers/polychord/polychord.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cobaya/samplers/polychord/polychord.py b/cobaya/samplers/polychord/polychord.py index 9665c2b20..df046c081 100644 --- a/cobaya/samplers/polychord/polychord.py +++ b/cobaya/samplers/polychord/polychord.py @@ -180,7 +180,7 @@ def initialize(self): locs = bounds[:, 0] scales = bounds[:, 1] - bounds[:, 0] # This function re-scales the parameters AND puts them in the right order - self.pc_prior = lambda x: (locs + np.array(x)[self.ordering] * scales).tolist() + self.pc_prior = lambda x: [self.model.prior.pdf[i].ppf(xi) for i, xi in enumerate(np.array(x)[self.ordering])] # We will need the volume of the prior domain, since PolyChord divides by it self.logvolume = np.log(np.prod(scales)) # Prepare callback function @@ -250,7 +250,7 @@ def logpost(params_values): loglikes = np.full(self.n_likes, np.nan) derived = list(derived) + list(logpriors) + list(loglikes) return ( - max(logposterior + self.logvolume, self.pc_settings.logzero), + max(loglikes.sum(), self.pc_settings.logzero), derived) sync_processes() From a86deb4522fe2e1ae2f8205dc7cebb1b9dcff241 Mon Sep 17 00:00:00 2001 From: lukashergt Date: Fri, 5 Jun 2020 19:03:06 +0100 Subject: [PATCH 2/2] add missing \log to the tex entry for logprior --- cobaya/samplers/polychord/polychord.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cobaya/samplers/polychord/polychord.py b/cobaya/samplers/polychord/polychord.py index df046c081..ed26fd7fa 100644 --- a/cobaya/samplers/polychord/polychord.py +++ b/cobaya/samplers/polychord/polychord.py @@ -278,7 +278,7 @@ def dump_paramnames(self, prefix): for p in self.model.prior: f_paramnames.write("%s*\t%s\n" % ( "logprior" + _separator + p, - r"\pi_\mathrm{" + p.replace("_", r"\ ") + r"}")) + r"\log\pi_\mathrm{" + p.replace("_", r"\ ") + r"}")) for p in self.model.likelihood: f_paramnames.write("%s*\t%s\n" % ( "loglike" + _separator + p,