Skip to content

Added WeightedCategorical-Prior#893

Merged
mj-will merged 7 commits into
bilby-dev:mainfrom
JasperMartins:weighted-categorical-prior
Oct 9, 2025
Merged

Added WeightedCategorical-Prior#893
mj-will merged 7 commits into
bilby-dev:mainfrom
JasperMartins:weighted-categorical-prior

Conversation

@JasperMartins

Copy link
Copy Markdown
Contributor

This pull request adds a WeightedCategorical-prior that subsumes the existing Categorical-Prior. Functionally, the only difference between the two is that WeightedCategorical supports the setting of relative weights for all categories.

@mj-will mj-will added the priors label Jun 3, 2025
@mj-will

mj-will commented Jun 3, 2025

Copy link
Copy Markdown
Collaborator

Hi @JasperMartins, thank for implementing this and apologies for the delay in looking over it.

The changes look good to me but following a recent change to the Categorical prior (see #947) I think this will need slightly reworking to address the conflicts. Do you think you'd have time/capacity to do this?

@JasperMartins JasperMartins force-pushed the weighted-categorical-prior branch from aed4c4d to 842f3db Compare June 24, 2025 12:50
@ColmTalbot ColmTalbot added this to the 2.7.0 milestone Aug 27, 2025

@mj-will mj-will left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, just one question from my side.

Comment thread bilby/core/prior/analytical.py Outdated
@mj-will mj-will added the enhancement New feature or request label Sep 2, 2025

@ColmTalbot ColmTalbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I agree, this is generally in good shape, just a few small comments from me.

Comment thread bilby/core/prior/analytical.py Outdated
Comment thread bilby/core/prior/analytical.py Outdated
@JasperMartins JasperMartins force-pushed the weighted-categorical-prior branch from 842f3db to e36ee8b Compare September 4, 2025 13:04
@ColmTalbot

Copy link
Copy Markdown
Collaborator

I was testing this out today (it happened to be relevant to something I'm working on) and generally it looks good. I noticed that the new priors (and also the categorical prior currently) doesn't store some of the input arguments, this means that the __repr__ method fails and so it can't be used during sampling.

tl;dr: the __init__ methods need to set all input arguments in the class, e.g.,

    ....
    self.ncategories = ncategories
    ....

@ColmTalbot

Copy link
Copy Markdown
Collaborator

Hi @JasperMartins just a gentle ping to see if you still have bandwidth to work on this change?

@JasperMartins

Copy link
Copy Markdown
Contributor Author

Hi @ColmTalbot,

Sorry for the delay, I had been on vacation.
So, prompted by the init-from-repr issue, I have added the new priors to the general assembly of prior-tests, to catch other issues, which also uncovered a small bug in the cdf function for values below the minimum value in the prior-support.
I have fixed these issues and brought the branch up to date.

In principle, the tests in the file analytical_test.py could now probably be dropped.

@ColmTalbot ColmTalbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for making these changes! No worries about the delay. I'm happy with the small duplication in the tests.

@mj-will mj-will left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks for your work on this!

@mj-will mj-will added this pull request to the merge queue Oct 9, 2025
Merged via the queue into bilby-dev:main with commit 4042980 Oct 9, 2025
12 checks passed
mj-will pushed a commit to mj-will/bilby that referenced this pull request Oct 16, 2025
* Added WeightedCategorical-Prior

* Implemented suggestions

* Added WeightedDiscreteValues-priors to the general prior tests

* Fixed init-from-repr, docstring and cdf-function, simplified code

* Docstring fix
mj-will pushed a commit to mj-will/bilby that referenced this pull request Feb 19, 2026
* Added WeightedCategorical-Prior

* Implemented suggestions

* Added WeightedDiscreteValues-priors to the general prior tests

* Fixed init-from-repr, docstring and cdf-function, simplified code

* Docstring fix
fgittins pushed a commit to fgittins/bilby that referenced this pull request Mar 5, 2026
* Added WeightedCategorical-Prior

* Implemented suggestions

* Added WeightedDiscreteValues-priors to the general prior tests

* Fixed init-from-repr, docstring and cdf-function, simplified code

* Docstring fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request priors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants