Skip to content

sample_prior_predictive does not work for simple model with LKJ distribution #3246

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

Closed
FedericoV opened this issue Nov 8, 2018 · 4 comments · Fixed by #3293
Closed

sample_prior_predictive does not work for simple model with LKJ distribution #3246

FedericoV opened this issue Nov 8, 2018 · 4 comments · Fixed by #3293
Labels

Comments

@FedericoV
Copy link

If you have questions about a specific use case, or you are not sure whether this is a bug or not, please post it to our discourse channel: https://discourse.pymc.io

Description of your problem

Sampling the prior predictive distribution of an LKJ distribution gives an error

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

import pymc3 as pm

with pm.Model() as model:
    sd_dist = pm.HalfCauchy.dist(beta=1, shape=10)
    chol_packed = pm.LKJCholeskyCov(name='chol_packed', n=20,
                                    eta=1.0, sd_dist=sd_dist)
    chol = pm.expand_packed_triangular(20, chol_packed)

with model:
    pm.sample_prior_predictive(50)

Please provide the full traceback.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-7300cc3c60ce> in <module>()
      8
      9 with model:
---> 10     pm.sample_prior_predictive(50)
     11

~/anaconda3/lib/python3.6/site-packages/pymc3-3.5-py3.6.egg/pymc3/sampling.py in sample_prior_predictive(samples, model, vars, random_seed)
   1332     names = get_default_varnames(model.named_vars, include_transformed=False)
   1333     # draw_values fails with auto-transformed variables. transform them later!
-> 1334     values = draw_values([model[name] for name in names], size=samples)
   1335
   1336     data = {k: v for k, v in zip(names, values)}

~/anaconda3/lib/python3.6/site-packages/pymc3-3.5-py3.6.egg/pymc3/distributions/distribution.py in draw_values(params, point, size)
    310     while to_eval or missing_inputs:
    311         if to_eval == missing_inputs:
--> 312             raise ValueError('Cannot resolve inputs for {}'.format([str(params[j]) for j in to_eval]))
    313         to_eval = set(missing_inputs)
    314         missing_inputs = set()

ValueError: Cannot resolve inputs for ['chol_packed']

Please provide any additional information below.

Versions and main components

  • PyMC3 Version: git commit: cd453bc (master branch, bleeding edge)
  • Theano Version: 1.03
  • Python Version: 3.06
  • Operating system: osX
  • How did you install PyMC3: (conda/pip) git clone
@junpenglao
Copy link
Member

Random method is not implemented for LKJCholeskyCov.

@ColCarroll
Copy link
Member

The lack of a random method is a good point, so this wouldn't work anyways, but the exception is being thrown earlier than that.

If anyone wants to "fix" this, it would mean figuring out how to find that chol_packed's sd_dist has a random method. Note that this would just cause the right error to be thrown a little bit later!

@junpenglao
Copy link
Member

Good point, following some recent terminology: the LKJCholeskyCov is intercepted by PyMC3 internally to generate multiple random variables, and draw_value did not track these new random variables properly.

@junpenglao junpenglao added the bug label Nov 10, 2018
@lucianopaz
Copy link
Member

I actually ran into this issue independently while writing down PR #3293. The strange error was caused by model._get_named_nodes_and_relations, that did not pass the proper parent for chol_packed. When #3293 is finally finished, this issue can be closed too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants