Skip to content

Conversation

@ColmTalbot
Copy link
Collaborator

For a long time, some prior classes have cast inputs to numpy arrays this MR removes that behaviour and adds a test to make sure that sampling and evaluating the CDF do not cast to array.

This caused an error when evaluating the CDF many times and then combining the results.

I also streamlined some other behaviour in applying prior constraints that were originally flagged by @cjhaster.

I noticed that the Fermi-Dirac CDF hadn't been implemented for some reason so I added that and added to the CI test suite.
Finally, there was an issue with sampling from joint distributions where the results could be returned out of order.

Copied from https://git.ligo.org/lscsoft/bilby/-/merge_requests/1285

@ColmTalbot ColmTalbot added bug Something isn't working 10-100 lines priors labels Nov 1, 2024
@ColmTalbot ColmTalbot changed the title Fix symmetric log uniform DEV: make sure all priors return float when needed Nov 1, 2024
@mj-will mj-will added this to the 2.5.0 milestone Nov 14, 2024
@mattpitkin mattpitkin self-requested a review February 4, 2025 14:28
@mattpitkin
Copy link
Collaborator

I've double checked the Fermi-Dirac prior CDF and it gives the correct expected result.

@ColmTalbot ColmTalbot requested a review from mj-will February 4, 2025 15:24
Copy link
Collaborator

@mj-will mj-will left a comment

Choose a reason for hiding this comment

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

LGTM, I just have a couple of questions before I approve.

Comment on lines 863 to 868
for names in joint.values():
values = list()
for key in names:
values = np.concatenate([values, result[key]])
for key, value in zip(names, values):
result[key] = value
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you help me understand what this loop is doing? I'm finding the logic of this part a bit hard to follow, it might benefit from a comment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looking at it, I really don't think I wrote this and suspect I picked it up from elsewhere, I can't find where immediately.

JointPrior.rescale either returns an empty list or a list with values for all of the parameters of the joint distribution, this loop is unpacking these by first converting something that might look like, {a: [], b: [], c: [1, 2, 3, 4], d: []} -> [1, 2, 3, 4] -> {a: 1, b: 2, c: 3, d: 4}. Is that ordering something we can assume is enforced? Probably since, dicts are ordered in py3, but I haven't checked recently.

I think #863 and #864 are related to this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, I think I follow. Is this tested somewhere?

Either way, I think it would be useful to add a comment explaining this.

def test_cdf_float_with_float_input(self):
for prior in self.priors:
if (
bilby.core.prior.JointPrior in prior.__class__.__mro__
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this test skipped for JointPriors with no finite upper bound?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great question, I think this should probably skip for any joint prior as I think the CDF isn't defined for those.

Copy link
Collaborator

@asb5468 asb5468 left a comment

Choose a reason for hiding this comment

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

Left a few questions in the code. Wondering what github will do when I press "submit review" with "request changes" chosen.

@mj-will
Copy link
Collaborator

mj-will commented Feb 10, 2025

@ColmTalbot it looks like there are conflicts following #849

@mj-will mj-will modified the milestones: 2.5.0, 2.6.0 Apr 3, 2025
@ColmTalbot
Copy link
Collaborator Author

Closing as #979 supercedes this.

@ColmTalbot ColmTalbot closed this Aug 21, 2025
@ColmTalbot ColmTalbot deleted the fix-symmetric-log-uniform branch October 13, 2025 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10-100 lines bug Something isn't working priors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants