Apply init_to_median in unconstrained space.#1994
Merged
fehiepsi merged 4 commits intopyro-ppl:masterfrom Mar 6, 2025
Merged
Conversation
fehiepsi
reviewed
Mar 6, 2025
| sample_shape=(num_samples,) + sample_shape, rng_key=rng_key | ||
| ) | ||
| return jnp.median(samples, axis=0) | ||
| from numpyro.infer.util import helpful_support_errors |
Member
There was a problem hiding this comment.
Just curious, you put the import here because of circular import?
Collaborator
Author
There was a problem hiding this comment.
Yes, I borrowed that line from init_to_uniform here.
numpyro/numpyro/infer/initialization.py
Lines 108 to 109 in 627d19a
fehiepsi
approved these changes
Mar 6, 2025
0dc5fb1 to
bb73982
Compare
bb73982 to
1471244
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The elementwise median of a random variable does not necessarily belong to the support of the generating distribution. I recently ran into this issue with
ZeroSumNormaldistributions whereinit_to_mediangave samples that did not sum to zero.This PR updates
init_to_medianto work in the unconstrained space, guaranteeing valid samples. It also fixes a small bug whereinit_to_meandoes not return a value.This change should not change the initialization given fixed random key for simple bijections to the support, but it will affect more complex transformations when
median(transform(x)) != transform(median(x)).