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

sample_prior_predictive() failing based solely on samples parameter #3421

Closed
gbernstein6 opened this issue Mar 21, 2019 · 0 comments · Fixed by #3456
Closed

sample_prior_predictive() failing based solely on samples parameter #3421

gbernstein6 opened this issue Mar 21, 2019 · 0 comments · Fixed by #3456

Comments

@gbernstein6
Copy link

gbernstein6 commented Mar 21, 2019

Description of your problem

Bug based on internal shape handling. MWE draws n iid vectors of dim dimensions from a normal distribution with a single covariance drawn from an Inverse Gamma. When samples <= dim it works fine, but otherwise it gets the error below.

Please provide a minimal, self-contained, and reproducible example.

import numpy as np
import pymc3 as pm

samples = 4
n = 10
dim = 3
mu = np.array([1] * dim)

with pm.Model():
    cov = pm.distributions.continuous.InverseGamma('cov', alpha=1, beta=1)
    pm.distributions.continuous.Normal('x', mu=mu, sd=pm.math.sqrt(cov), shape=(n, dim))

    pm.sample_prior_predictive(samples=samples)

Please provide the full traceback.

Traceback (most recent call last):
  File "/test.py", line 13, in <module>
    pm.sample_prior_predictive(samples=samples)
  File "//anaconda3/lib/python3.7/site-packages/pymc3/sampling.py", line 1325, in sample_prior_predictive
    values = draw_values([model[name] for name in names], size=samples)
  File "//anaconda3/lib/python3.7/site-packages/pymc3/distributions/distribution.py", line 369, in draw_values
    size=size)
  File "//anaconda3/lib/python3.7/site-packages/pymc3/distributions/distribution.py", line 463, in _draw_value
    return param.random(point=point, size=size)
  File "//anaconda3/lib/python3.7/site-packages/pymc3/model.py", line 43, in __call__
    return getattr(self.obj, self.method_name)(*args, **kwargs)
  File "//anaconda3/lib/python3.7/site-packages/pymc3/distributions/continuous.py", line 460, in random
    size=size)
  File "//anaconda3/lib/python3.7/site-packages/pymc3/distributions/distribution.py", line 584, in generate_samples
    broadcast_shape = np.broadcast(*inputs).shape  # size of generator(size=1)
ValueError: shape mismatch: objects cannot be broadcast to a single shape

Please provide any additional information below.

Note that it works fine as far as I can tell when drawing using the 'pm.sampling.sample()' instead.

See here for corresponding discourse discussion.

Versions and main components

  • PyMC3 Version: 3.6
  • Theano Version: 1.0.3
  • Python Version: 3.7.1
  • Operating system: Mac OSX 10.13.6
  • How did you install PyMC3: conda
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.

2 participants