-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Shape broadcast error in sample_prior_predictive #3481
Comments
A little more information. This is the random variable in question:
The error is
and the (default) number of samples is 500. There are 1031 observations. So perhaps it's the observations that are causing the issue? |
Thanks for reporting! The problem is happening before entering |
So do we need to take the transpose of the Or is it: |
No, it's a bit more complicated, but all the required functionality is in
|
So: mu_v, std_v, a_v, b_v = draw_values(
[self.mu, self.sigma, self.lower, self.upper], point=point, size=size) Becomes
and then we do:
If that's right, I can try to test it out. |
Yeah, both options will work. Upon further thought I think that option 1 is the best. Option 2 will always recompile the theano function because it will use different tensors each time If you want to try to solve this, take a look at the documentation in |
@rpgoldman, I realize that I might have discouraged you by saying that option 1 should be used, and that it involved reading through new documentation and docstrings in the source. That wasn't my intention, the fix using option 1 should be as simple as this: mu_v, std_v, a_v, b_v = broadcast_distribution_samples(
draw_values(
[self.mu, self.sigma, self.lower, self.upper],
point=point,
size=size),
size=size,
) The only extra work would be to write some new tests, track down other distributions in continuous.py and discrete.py that could suffer from the same problem, and finally add all of the fixes to the release notes. I wont have time to do it this weekend, so if you are willing to give it a shot, you're more than welcome! |
I will give a try at that patch (once I have my other PR ready for merge). For some reason, I didn't get an email notification of your comments -- sorry to take so long to respond. |
Fix to issue pymc-devs#3481, from @lucianopaz.
I'll try to explain what is the cause of the error you saw, to help you understand why other distributions might be prone to this. Consider the following model, inspired by your example that had the error: with pm.Model():
means_vector = pm.Normal('means', 0, 1, len(self.df))
err_sd = pm.Halfnormal('err_sd', 1)
obs = pm.TruncatedNormal("obs", mu=pred + means_vector, sd=err_sd,
observed=self.df['mean_log_gfp_live'].to_numpy(),
lower=0.0, upper=12.0) The RVs The problem comes when you want to draw a sample (really more than 1 sample) from a given distribution. If you call So what can we do? The lucky thing is that the |
Fix to issue pymc-devs#3481, from @lucianopaz.
Fix to issue pymc-devs#3481, from @lucianopaz.
Fix to issue pymc-devs#3481, from @lucianopaz.
Fix to issue pymc-devs#3481, from @lucianopaz.
Fix to issue pymc-devs#3481, from @lucianopaz.
Fix to issue pymc-devs#3481, from @lucianopaz.
Fix to issue pymc-devs#3481, from @lucianopaz.
Fix to issue pymc-devs#3481, from @lucianopaz.
Description of your problem
When trying to sample the prior predictive -- for a model which can be successfully sampled using NUTS, and whose resulting trace can be successfully used with
sample_posterior_predictive()
-- I get an error broadcasting with different shapes (see below).Please provide a minimal, self-contained, and reproducible example.
Pickled model may be found here.
Please provide the full traceback.
Additional Information
If it helps, the observed variable is a
TruncatedNormal
, which has failed before, but I'm running withmaster
as of today, and this is supposed to be fixed, AFAICT.Versions and main components
The text was updated successfully, but these errors were encountered: