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

Add sample_prior function #2876

Closed
wants to merge 9 commits into from
6 changes: 3 additions & 3 deletions pymc3/distributions/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,14 @@ def draw_values(params, point=None, size=None):
missing_inputs = set(params)
while to_eval or missing_inputs:
if to_eval == missing_inputs:
raise ValueError('Cannot resolve inputs for {}'.format([str(j) for j in to_eval]))
raise ValueError('Cannot resolve inputs for {}'.format([str(params[j]) for j in to_eval]))
to_eval = set(missing_inputs)
missing_inputs = set()
for param in to_eval:
try: # might evaluate in a bad order,
evaluated[param] = _draw_value(params[param], point=point, givens=givens.values(), size=size)
if any(param in j for j in named_nodes_children.values()):
givens[param.name] = (params[param], evaluated[param])
if any(params[param] in j for j in named_nodes_children.values()):
Copy link
Contributor

@lucianopaz lucianopaz Mar 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops I actually commented on an older commit so it shows as outdated, sorry for the mess. First off, it looks very nice, however I think this line is confusing, You're trying to see if the node params[param] is a child of some other named node. If params[param] were to be a named node, that information should be available in the dictionary named_nodes_parents. If params[param] were not to be a named node, then it would not be registered neither in the named_nodes_parents nor the named_nodes_children dictionaries.
If params[param] is a named node, you should be able to replace this line by:
if named_nodes_parents[params[param]]:
If params[param] is not a named node, then I think it shouldn't bee added to givens but I may be overlooking something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much nicer, thank you!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also just checked out travis, and your suggestion will also fix failing tests)

givens[params[param].name] = (params[param], evaluated[param])
except theano.gof.fg.MissingInputError:
missing_inputs.add(param)

Expand Down