Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pymc/model_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def make_compute_graph(
if hasattr(var.tag, "observations"):
try:
obs_name = var.tag.observations.name
if obs_name:
if obs_name and obs_name != var_name:
input_map[var_name] = input_map[var_name].difference({obs_name})
input_map[obs_name] = input_map[obs_name].union({var_name})
except AttributeError:
Expand Down
55 changes: 32 additions & 23 deletions pymc/tests/test_model_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ def model_with_dims():
return pmodel, compute_graph, plates


def model_unnamed_observed_node():
"""
Model at the source of the following issue: https://github.com/pymc-devs/pymc/issues/5892
"""
data = [-1, 0, 0.5, 1]

with pm.Model() as model:
mu = pm.Normal(name="mu", mu=0.0, sigma=5.0)
y = pm.Normal(name="y", mu=mu, sigma=3.0, observed=data)

compute_graph = {
"mu": set(),
"y": {"mu"},
}
plates = {
"": {"mu"},
"4": {"y"},
}

return model, compute_graph, plates


class BaseModelGraphTest(SeededTest):
model_func = None

Expand Down Expand Up @@ -202,21 +224,16 @@ def model_with_different_descendants():
return pmodel2


class TestParents:
@pytest.mark.parametrize(
"var_name, parent_names",
[
("L", {"pred"}),
("pred", {"intermediate"}),
("intermediate", {"a", "b"}),
("c", {"a", "b"}),
("a", set()),
("b", set()),
],
)
def test_get_parent_names(self, var_name, parent_names):
mg = ModelGraph(model_with_different_descendants())
mg.get_parent_names(mg.model[var_name]) == parent_names
class TestImputationModel(BaseModelGraphTest):
model_func = model_with_imputations


class TestModelWithDims(BaseModelGraphTest):
model_func = model_with_dims


class TestUnnamedObservedNodes(BaseModelGraphTest):
model_func = model_unnamed_observed_node


class TestVariableSelection:
Expand Down Expand Up @@ -260,11 +277,3 @@ def test_subgraph(self, var_names, vars_to_plot, compute_graph):
mg = ModelGraph(model_with_different_descendants())
assert set(mg.vars_to_plot(var_names=var_names)) == set(vars_to_plot)
assert mg.make_compute_graph(var_names=var_names) == compute_graph


class TestImputationModel(BaseModelGraphTest):
model_func = model_with_imputations


class TestModelWithDims(BaseModelGraphTest):
model_func = model_with_dims