Skip to content

Shape broadcast error in sample_prior_predictive  #3481

@rpgoldman

Description

@rpgoldman

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.

import pickle
import pymc3 as pm

with open('model.pickle', 'rb') as file:
    model = pickle.load(file)

with model:
    pre_trace = pm.sample_prior_predictive()

Pickled model may be found here.

Please provide the full traceback.

ValueError                                Traceback (most recent call last)
~/projects/xplan/xplan-experiment-analysis/sample_prior_predictive_error.py in <module>
      8 
      9 with model:
---> 10     pre_trace = pm.sample_prior_predictive()

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymc3/sampling.py in sample_prior_predictive(samples, model, vars, var_names, random_seed)
   1320     names = get_default_varnames(model.named_vars, include_transformed=False)
   1321     # draw_values fails with auto-transformed variables. transform them later!
-> 1322     values = draw_values([model[name] for name in names], size=samples)
   1323 
   1324     data = {k: v for k, v in zip(names, values)}

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymc3/distributions/distribution.py in draw_values(params, point, size)
    393                                         point=point,
    394                                         givens=temp_givens,
--> 395                                         size=size)
    396                     givens[next_.name] = (next_, value)
    397                     drawn[(next_, size)] = value

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymc3/distributions/distribution.py in _draw_value(param, point, givens, size)
    579                         else:
    580                             dist_tmp.shape = val.shape
--> 581                 return dist_tmp.random(point=point, size=size)
    582             else:
    583                 return param.distribution.random(point=point, size=size)

/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pymc3/distributions/continuous.py in random(self, point, size)
    668             [self.mu, self.sigma, self.lower, self.upper], point=point, size=size)
    669         return generate_samples(stats.truncnorm.rvs,
--> 670                                 a=(a_v - mu_v)/std_v,
    671                                 b=(b_v - mu_v) / std_v,
    672                                 loc=mu_v,

ValueError: operands could not be broadcast together with shapes (500,1031) (500,) 

Additional Information

If it helps, the observed variable is a TruncatedNormal, which has failed before, but I'm running with master as of today, and this is supposed to be fixed, AFAICT.

Versions and main components

  • PyMC3 Version: 3.6 from source
  • Theano Version: 1.0.4
  • Python Version: 3.7.3
  • Operating system: MacOS Mojave
  • How did you install PyMC3: pip from Github source

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions