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

Add TruncatedPrior #779

Open
tomicapretto opened this issue Feb 16, 2024 · 4 comments · May be fixed by #875
Open

Add TruncatedPrior #779

tomicapretto opened this issue Feb 16, 2024 · 4 comments · May be fixed by #875

Comments

@tomicapretto
Copy link
Collaborator

tomicapretto commented Feb 16, 2024

So users can truncate any distribution

Edit after seeing #875

We want to give users the option to truncate any prior distribution. Under the hood, this should be done via pymc.Truncated().

I still don't know what this would look like, but I can throw the following ideas.

# Option 1
bmb.Prior("Normal", mu=0, sigma=1, transform=pm.Truncated, transform_kwargs={"lower": -1})

# Option 2
bmb.Prior("Normal", mu=0, sigma=1, transform=lambda x: pm.Truncated(x, lower=-1))

# Option 3
bmb.Truncated(bmb.Prior("Normal", mu=0, sigma=1), lower=-1)

# Option 4
bmb.Transform(bmb.Prior("Normal", mu=0, sigma=1), pm.Truncated, {"lower": -1})

I think I prefer Option 3, but still I like how general Option 4 can be.

@speco29
Copy link

speco29 commented Jan 22, 2025

Should I add TruncatedPrior here - https://github.com/bambinos/bambi/tree/main/bambi?

@speco29
Copy link

speco29 commented Jan 22, 2025

Image

I think this should do.
This sample function truncates a normal distribution. You can adapt it to other distributions as needed:)

@Schefflera-Arboricola
Copy link
Contributor

I think it should go here - https://github.com/bambinos/bambi/tree/main/bambi/priors ; and I think you can take inspiration from the Prior and PriorScaler classes. Hope that helps!

speco29 added a commit to speco29/bambi that referenced this issue Jan 22, 2025
fixes bambinos#779 
This function leverages the truncnorm distribution from the SciPy library to generate samples from a truncated normal distribution. You can adapt the function to other distributions by changing the import statement and parameters.
@speco29 speco29 linked a pull request Jan 22, 2025 that will close this issue
@speco29
Copy link

speco29 commented Jan 24, 2025

So users can truncate any distribution

Edit after seeing #875

We want to give users the option to truncate any prior distribution. Under the hood, this should be done via pymc.Truncated().

I still don't know what this would look like, but I can throw the following ideas.

Option 1

bmb.Prior("Normal", mu=0, sigma=1, transform=pm.Truncated, transform_kwargs={"lower": -1})

Option 2

bmb.Prior("Normal", mu=0, sigma=1, transform=lambda x: pm.Truncated(x, lower=-1))

Option 3

bmb.Truncated(bmb.Prior("Normal", mu=0, sigma=1), lower=-1)

Option 4

bmb.Transform(bmb.Prior("Normal", mu=0, sigma=1), pm.Truncated, {"lower": -1})
I think I prefer Option 3, but still I like how general Option 4 can be.

option 3 i guess is better as it seems simple and easy to implement then other ones, let me know your review then i'll add option 3 in the priors;)
Also should I extend the PriorScaler class to include the option for creating truncated priors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants