Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PolyChord] use ppf for pc_prior instead of prior bounds #104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cobaya/samplers/polychord/polychord.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def initialize(self):
locs = bounds[:, 0]
scales = bounds[:, 1] - bounds[:, 0]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might remain some possible cleaning up to do, e.g. I expect that self.logvolume won't be needed anymore, right? Consequently also scales and locs can be removed. Maybe we don't even need bounds here anymore? Meaning we could even get rid of all lines from 170 to 181.

Or is there a different reason that PolyChord priors need to be bounded that isn't obvious to me? @williamjameshandley, maybe you can confirm whether by using the .ppf we indeed don't need to specify prior bounds anymore?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly most other interfaces to PolyChord don't put in these bounds, so if it is necessary it might be cobaya specific. These changes all look good to me, so it's up to @JesusTorrado to approve/comment on this.

# 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])]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pdf.ppf thing might read a bit confusing. The thing is that prior.pdf is really a scipy.stats.rv_continuous class that has .pdf, .logpdf and .ppf as functions. Might be worth considering to rename prior.pdf to something else? (e.g. prior.rv_continuous or prior.distributions?)

# We will need the volume of the prior domain, since PolyChord divides by it
self.logvolume = np.log(np.prod(scales))
# Prepare callback function
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"}"))
Comment on lines 279 to +281
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add this change to #233.

for p in self.model.likelihood:
f_paramnames.write("%s*\t%s\n" % (
"loglike" + _separator + p,
Expand Down