Commit d19b2d7e authored by Hendrik Buschmeier's avatar Hendrik Buschmeier Committed by GitHub
Browse files

Merge pull request #22 from jpoeppel/factorBug

Only add edges in factor Tree when node is connected in BN
parents 2609c789 9fbc643c
......@@ -227,6 +227,7 @@ class FactorTree(object):
clusterSeq.insert(idx, move)
# Construct jointree
tree = nx.Graph(messagesValid=False)
if len(clusterSeq) > 0:
......@@ -240,12 +241,13 @@ class FactorTree(object):
jointreeProp = set(clusterSeq[i]).intersection(
for cl in clusterSeq[i+1:]:
if jointreeProp.issubset(set(cl)):
if len(jointreeProp) != 0 and jointreeProp.issubset(set(cl)):
tree.add_edge("".join(clusterSeq[i]), "".join(cl),
# Assign factors to clusters
for f in factors:
for treeNode, treeData in tree.nodes_iter(data=True):
......@@ -153,6 +153,19 @@ class FactorEliminationTest(unittest.TestCase): = XMLBIFParser.parse("primo2/tests/slippery.xbif")
def test_not_connected_node_without_cpt(self):
# bn = BayesianNetwork()
from primo2.nodes import DiscreteNode
n = DiscreteNode("a")
ft = FactorTree.create_jointree(
ft.set_evidence({"a": "False"})
res = ft.marginals(["a"])
#Even with evidence set, when we do not have a cpt the result should remain
#at 0! Even if only to indicate that something might be wrong with that
np.testing.assert_array_almost_equal(res.get_potential(), np.array([0.0, 0.0]))
def test_empty_cpt(self):
bn = BayesianNetwork()
from primo2.nodes import DiscreteNode
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment