-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Prior predictive sampling with pm.Bound gives wrong results #4643
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
Comments
This could be helpful in implementing a fix: https://mc-stan.org/docs/2_18/stan-users-guide/truncated-random-number-generation.html |
The thing is that Bound does not really correspond to a Truncated distribution. If it did, it would not affect the prior of the hyperparameters during (correctly implemented) prior predictive sampling. |
The with pm.Model() as m:
pop = pm.Normal('pop', 2, 1)
ind = pm.TruncatedNormal('ind', lower=-2, upper=2, mu=pop, sigma=.5)
prior = pm.sample_prior_predictive()
trace = pm.sample() The prior for the Truncated is different, note the smaller left tail sns.kdeplot(prior['ind'])
sns.kdeplot(trace['ind']) The prior for the hyperparameter is not affected by the Truncation downstream sns.kdeplot(prior['pop'])
sns.kdeplot(trace['pop']) |
@OriolAbril your point made me recheck the Bound random method and I am very unsure as to whether it's logic is sound (although I couldn't confirm it's not either): In particular it ignores the order of the |
@ricardoV94 was this |
It's an issue in V3. Bound hasn't been refactored to V4 but will be the same. Anyway no point in changing things for V3 so I'll put a label accordingly |
Using
pm.Bound
for distributions whose arguments include other model parameters (instead of constants) will lead to a model that is wrongly sampled insample_prior_predictive()
The samples for the bounded distribution are fine (i.e., one obtains the same results if doing prior_predictive or sampling without data):
But the samples for the hyper-parameters do not match:
What is going on? I think the way
pm.Bound
is implemented, it corresponds to adding an arbitrary factor to the model logp of the kind:Which obviously is not (and cannot) be accounted for in predictive sampling.
The text was updated successfully, but these errors were encountered: