Skip to content

Commit

Permalink
Fixed #872
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhp committed Apr 24, 2017
1 parent c302a5d commit 1eaaeb9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions pgmpy/models/BayesianModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ def get_cpds(self, node=None):
for cpd in self.cpds:
if cpd.variable == node:
return cpd
raise ValueError("CPD not added for the node: {node}".format(node=node))
else:
return None
else:
return self.cpds

Expand Down Expand Up @@ -346,7 +347,9 @@ def check_model(self):
for node in self.nodes():
cpd = self.get_cpds(node=node)

if isinstance(cpd, TabularCPD):
if cpd is None:
raise ValueError('No CPD associated with {}'.format(node))
elif isinstance(cpd, TabularCPD):
evidence = cpd.variables[:0:-1]
parents = self.get_parents(node)
if set(evidence if evidence else []) != set(parents if parents else []):
Expand Down
2 changes: 1 addition & 1 deletion pgmpy/tests/test_models/test_BayesianModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def test_get_cpds1(self):
self.assertRaises(ValueError, self.model.get_cpds, 'B')

self.model.add_node('B')
self.assertRaises(ValueError, self.model.get_cpds, 'B')
self.assertIsNone(self.model.get_cpds('B'))

def test_add_single_cpd(self):
cpd_s = TabularCPD('s', 2, np.random.rand(2, 2), ['i'], [2])
Expand Down

0 comments on commit 1eaaeb9

Please sign in to comment.