Integer keys not working
jluttine opened this issue · comments
For some reason, integer keys for variables aren't working:
>>> x = "x"; y = "y"; jt.create_junction_tree([ [x], [x, y] ], {x: 10, y: 20})
JunctionTree(tree=[0], separators=[], clique_tree=CliqueGraph(maxcliques=[['x', 'y']], factor_to_maxclique=[0, 0], factor_graph=FactorGraph(factors=[['x'], ['x', 'y']], sizes={'x': 10, 'y': 20})))
>>> x = 0; y = 1; jt.create_junction_tree([ [x], [x, y] ], {x: 10, y: 20})
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-9-55375988fd6f> in <module>()
----> 1 x = 0; y = 1; jt.create_junction_tree([ [x], [x, y] ], {x: 10, y: 20})
/nix/store/h87wncs2h5w7fmfh0yf55m36bbgk6kvd-python3.6-junctiontree-0.1.2/lib/python3.6/site-packages/junctiontree/junctiontree.py in create_junction_tree(factors, sizes)
13 assert all(type(l) == list for l in factors), "Provided factor is not a list"
14 fg = FactorGraph(factors=factors, sizes=sizes)
---> 15 return fg.triangulate().create_junction_tree()
16
17
/nix/store/h87wncs2h5w7fmfh0yf55m36bbgk6kvd-python3.6-junctiontree-0.1.2/lib/python3.6/site-packages/junctiontree/junctiontree.py in triangulate(self)
106 (_, _, maxcliques, factor_to_maxclique) = bp.find_triangulation(
107 self.factors,
--> 108 self.sizes
109 )
110
/nix/store/h87wncs2h5w7fmfh0yf55m36bbgk6kvd-python3.6-junctiontree-0.1.2/lib/python3.6/site-packages/junctiontree/beliefpropagation.py in find_triangulation(factors, key_sizes)
147 heap, entry_finder = initialize_triangulation_heap(
148 key_sizes,
--> 149 edges
150 )
151
/nix/store/h87wncs2h5w7fmfh0yf55m36bbgk6kvd-python3.6-junctiontree-0.1.2/lib/python3.6/site-packages/junctiontree/beliefpropagation.py in initialize_triangulation_heap(key_sizes, edges)
245 """
246
--> 247 heap, entry_finder = update_heap(key_sizes.keys(), edges, key_sizes)
248
249 return heap, entry_finder
/nix/store/h87wncs2h5w7fmfh0yf55m36bbgk6kvd-python3.6-junctiontree-0.1.2/lib/python3.6/site-packages/junctiontree/beliefpropagation.py in update_heap(remaining_keys, edges, key_sizes, heap, entry_finder)
279 for key in remaining_keys:
280 rem_neighbors = [(set(edge) - set(key)).pop()
--> 281 for edge in edges if key in edge and len(set(remaining_keys).intersection(edge)) == 2]
282
283 # determine how many of key's remaining neighbors need to be connected
/nix/store/h87wncs2h5w7fmfh0yf55m36bbgk6kvd-python3.6-junctiontree-0.1.2/lib/python3.6/site-packages/junctiontree/beliefpropagation.py in <listcomp>(.0)
279 for key in remaining_keys:
280 rem_neighbors = [(set(edge) - set(key)).pop()
--> 281 for edge in edges if key in edge and len(set(remaining_keys).intersection(edge)) == 2]
282
283 # determine how many of key's remaining neighbors need to be connected
TypeError: 'int' object is not iterable
It shouldn't matter what the keys are as long as they are something that can be used as keys in a dictionary. Why doesn't it work? I don't see any reason why a variable key should be iterable. Any ideas @dar326?
This should be an easy fix. I’ll look into it this weekend
…On Sat, Sep 15, 2018 at 8:50 AM Jaakko Luttinen ***@***.***> wrote:
For some reason, integer keys for variables aren't working:
>>> x = "x"; y = "y"; jt.create_junction_tree([ [x], [x, y] ], {x: 10, y: 20})
JunctionTree(tree=[0], separators=[], clique_tree=CliqueGraph(maxcliques=[['x', 'y']], factor_to_maxclique=[0, 0], factor_graph=FactorGraph(factors=[['x'], ['x', 'y']], sizes={'x': 10, 'y': 20})))
>>> x = 0; y = 1; jt.create_junction_tree([ [x], [x, y] ], {x: 10, y: 20})
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-9-55375988fd6f> in <module>()
----> 1 x = 0; y = 1; jt.create_junction_tree([ [x], [x, y] ], {x: 10, y: 20})
/nix/store/h87wncs2h5w7fmfh0yf55m36bbgk6kvd-python3.6-junctiontree-0.1.2/lib/python3.6/site-packages/junctiontree/junctiontree.py in create_junction_tree(factors, sizes)
13 assert all(type(l) == list for l in factors), "Provided factor is not a list"
14 fg = FactorGraph(factors=factors, sizes=sizes)
---> 15 return fg.triangulate().create_junction_tree()
16
17
/nix/store/h87wncs2h5w7fmfh0yf55m36bbgk6kvd-python3.6-junctiontree-0.1.2/lib/python3.6/site-packages/junctiontree/junctiontree.py in triangulate(self)
106 (_, _, maxcliques, factor_to_maxclique) = bp.find_triangulation(
107 self.factors,
--> 108 self.sizes
109 )
110
/nix/store/h87wncs2h5w7fmfh0yf55m36bbgk6kvd-python3.6-junctiontree-0.1.2/lib/python3.6/site-packages/junctiontree/beliefpropagation.py in find_triangulation(factors, key_sizes)
147 heap, entry_finder = initialize_triangulation_heap(
148 key_sizes,
--> 149 edges
150 )
151
/nix/store/h87wncs2h5w7fmfh0yf55m36bbgk6kvd-python3.6-junctiontree-0.1.2/lib/python3.6/site-packages/junctiontree/beliefpropagation.py in initialize_triangulation_heap(key_sizes, edges)
245 """
246
--> 247 heap, entry_finder = update_heap(key_sizes.keys(), edges, key_sizes)
248
249 return heap, entry_finder
/nix/store/h87wncs2h5w7fmfh0yf55m36bbgk6kvd-python3.6-junctiontree-0.1.2/lib/python3.6/site-packages/junctiontree/beliefpropagation.py in update_heap(remaining_keys, edges, key_sizes, heap, entry_finder)
279 for key in remaining_keys:
280 rem_neighbors = [(set(edge) - set(key)).pop()
--> 281 for edge in edges if key in edge and len(set(remaining_keys).intersection(edge)) == 2]
282
283 # determine how many of key's remaining neighbors need to be connected
/nix/store/h87wncs2h5w7fmfh0yf55m36bbgk6kvd-python3.6-junctiontree-0.1.2/lib/python3.6/site-packages/junctiontree/beliefpropagation.py in <listcomp>(.0)
279 for key in remaining_keys:
280 rem_neighbors = [(set(edge) - set(key)).pop()
--> 281 for edge in edges if key in edge and len(set(remaining_keys).intersection(edge)) == 2]
282
283 # determine how many of key's remaining neighbors need to be connected
TypeError: 'int' object is not iterable
It shouldn't matter what the keys are as long as they are something that
can be used as keys in a dictionary. Why doesn't it work? I don't see any
reason why a variable key should be iterable. Any ideas @dar326
<https://github.com/dar326>?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AR0ogLr_fjHc9QPwFPtJ87CGyKvCGt3Cks5ubPeugaJpZM4WqWHi>
.
When performing a set operation, I needed to convert the key into a single element iterable. Failing to do this was not an issue with string keys but it causes the above error when using integer keys.
#6 fixes this bug. Closing.