Skip to content

Commit

Permalink
Always add values from drawn dict to givens
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianopaz authored and rpgoldman committed Jan 29, 2020
1 parent db7c493 commit 4018d1d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- `DEMetropolis` can now tune both `lambda` and `scaling` parameters, but by default neither of them are tuned. See [#3743](https://github.com/pymc-devs/pymc3/pull/3743) for more info.

### Maintenance
- Fixed bug in `draw_values`, in which values that had been drawn in a separate `_DrawValuesContext` were not added to the `givens` dictionary and lead to `ValueError: Cannot resolve inputs for ...` exceptions. Fixes issue [#3789](https://github.com/pymc-devs/pymc3/issues/3789)
- Remove `sample_ppc` and `sample_ppc_w` that were deprecated in 3.6.

## PyMC3 3.8 (November 29 2019)
Expand Down
20 changes: 3 additions & 17 deletions pymc3/distributions/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ def draw_values(params, point=None, size=None):
while stack:
next_ = stack.pop(0)
if (next_, size) in drawn:
# If the node already has a givens value, skip it
continue
# If the node already has a givens value, add it to givens
givens[next_.name] = (next_, drawn[(next_, size)])
elif isinstance(next_, (theano_constant,
tt.sharedvar.SharedVariable)):
# If the node is a theano.tensor.TensorConstant or a
Expand Down Expand Up @@ -640,7 +640,7 @@ def draw_values(params, point=None, size=None):
# nodes in the `params` list.
stack.extend([node for node in named_nodes_parents[next_]
if node is not None and
(node, size) not in drawn])
getattr(node, "name", None) not in givens])

# the below makes sure the graph is evaluated in order
# test_distributions_random::TestDrawValues::test_draw_order fails without it
Expand All @@ -658,20 +658,6 @@ def draw_values(params, point=None, size=None):
evaluated[param_idx] = drawn[(param, size)]
else:
try: # might evaluate in a bad order,
# Sometimes _draw_value recurrently calls draw_values.
# This may set values for certain nodes in the drawn
# dictionary, but they don't get added to the givens
# dictionary. Here, we try to fix that.
if param in named_nodes_children:
for node in named_nodes_children[param]:
if (
node.name not in givens and
(node, size) in drawn
):
givens[node.name] = (
node,
drawn[(node, size)]
)
value = _draw_value(param,
point=point,
givens=givens.values(),
Expand Down

0 comments on commit 4018d1d

Please sign in to comment.