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

Allow inclusive bounds in Adapter.constrain() #338

Merged
merged 5 commits into from
Feb 27, 2025

Conversation

LarsKue
Copy link
Contributor

@LarsKue LarsKue commented Feb 25, 2025

Simply adds a small value to bounds that are specified as inclusive.

@LarsKue LarsKue added the sugar Syntactical sugar or quality of life improvements label Feb 25, 2025
@LarsKue LarsKue added this to the BayesFlow 2.0 milestone Feb 25, 2025
@LarsKue LarsKue self-assigned this Feb 25, 2025
@paul-buerkner
Copy link
Contributor

thank you! looks good. Question: Why would you make the lower bound inclusive but the upper exclusive by default?

@LarsKue
Copy link
Contributor Author

LarsKue commented Feb 25, 2025

@paul-buerkner In my opinion, the most common case for double-bounded variables is uniform distribution. This is typically in the half-open interval [lower, upper).

@LarsKue LarsKue requested review from paul-buerkner and removed request for stefanradev93 February 25, 2025 15:39
@codecov-commenter
Copy link

codecov-commenter commented Feb 25, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
bayesflow/adapters/transforms/constrain.py 88.88% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Files with missing lines Coverage Δ
bayesflow/adapters/adapter.py 74.49% <ø> (ø)
bayesflow/adapters/transforms/constrain.py 67.44% <88.88%> (+21.85%) ⬆️

... and 1 file with indirect coverage changes

@paul-buerkner
Copy link
Contributor

In statistics, we do not treat upper and lower bounds differently, specifically if variables are continuous (which they need to be for now if we use them as parameters in generative neural networks). I would treat upper and lower boundaries the same. So probably inclusive = "both" as default straight. This would of course internally translate to "lower" or "upper" for single bounded variables.

Copy link
Contributor

@paul-buerkner paul-buerkner left a comment

Choose a reason for hiding this comment

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

Looks good except for my suggestion for symmetric default values that I added as direct comment to the issue.

@paul-buerkner
Copy link
Contributor

@LarsKue do i have permission to edit this PR in the direction I mentioned aboved?

@LarsKue
Copy link
Contributor Author

LarsKue commented Feb 27, 2025

@paul-buerkner yes. I do feel like it could be a bit opaque to new users though, since most randomly generated numbers are in open or half-open intervals, regardless of the statistical interpretation of the bounds.

@paul-buerkner
Copy link
Contributor

Is there even a difference for continuous distributions? I mean, the probability of sampling exactly from the boundary is zero. So I am confused by your statement that intervals would ever be half open in software. For discrete variables perhaps but those are not our main concern in the adapter transformations.

@paul-buerkner
Copy link
Contributor

paul-buerkner commented Feb 27, 2025

Just to add one thought. Our point here is not to determine whether a null-set is included in an interval or not, but to ensure numerical stability. And for the latter, we need the epsilon, i.e., both inclusive bounds.

Copy link
Contributor

@paul-buerkner paul-buerkner left a comment

Choose a reason for hiding this comment

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

From my side, the PR is ready now. I change the default inclusive to "both" and added some tests. During testing, I also noticed that epsilon 1e-16 is too small to ensure finite outputs if the input is exactly at the upper boundary. So I changed it to 1e-15 which seems to work well.

@paul-buerkner
Copy link
Contributor

I further extended the tests to now hopefully cover all relevant cases. Will merge now.

@paul-buerkner paul-buerkner merged commit a822d01 into dev Feb 27, 2025
13 checks passed
@paul-buerkner paul-buerkner deleted the allow-inclusive-bounds branch February 27, 2025 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sugar Syntactical sugar or quality of life improvements
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants