jluttine / junction-tree

The junction tree algorithm for (discrete) factor graphs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dont working

jona2510 opened this issue · comments

Hello, please help!,
I've followed your instructions, but when I give the next data, the script dont work:
key_size={'0/3/7_ob': 2, '1/6': 2, '1/6_ob': 2, '1/5/11_ob': 2, '0/3/8': 2, '0/3/8_ob': 2, '1': 2, '1/5/11': 2, '1/5/10': 2, '0/4': 2, '0/4_ob': 2, '0/2_ob': 2, '0/3/7': 2, '0': 2, '1/5/9_ob': 2, '0_ob': 2, '1/5_ob': 2, '0/3_ob': 2, '0/2': 2, '1/5/9': 2, '1/5': 2, '1/5/10_ob': 2, '0/3': 2, '1_ob': 2, 'main_root': 2} factors=['main_root', ['main_root', '0'], ['0', '0/2'], ['0', '0/3'], ['0/3', '0/3/7'], ['0/3', '0/3/8'], ['0', '0/4'], ['main_root', '1'], ['1', '1/5'], ['1/5', '1/5/9'], ['1/5', '1/5/10'], ['1/5', '1/5/11'], ['1', '1/6'], ['0', '0_ob'], ['0/2', '0/2_ob'], ['0/3', '0/3_ob'], ['0/3/7', '0/3/7_ob'], ['0/3/8', '0/3/8_ob'], ['0/4', '0/4_ob'], ['1', '1_ob'], ['1/5', '1/5_ob'], ['1/5/10', '1/5/10_ob'], ['1/5/11', '1/5/11_ob'], ['1/5/9', '1/5/9_ob'], ['1/6', '1/6_ob']] values=[array([0.01, 0.99]), array([[1. , 0. ], [0.40293284, 0.59706716]]), array([[1. , 0. ], [0.7955909, 0.2044091]]), array([[1. , 0. ], [0.50927864, 0.49072136]]), array([[1. , 0. ], [0.30386583, 0.69613417]]), array([[1. , 0. ], [0.69613417, 0.30386583]]), array([[1. , 0. ], [0.69499093, 0.30500907]]), array([[1. , 0. ], [0.59706716, 0.40293284]]), array([[1. , 0. ], [0.50299773, 0.49700227]]), array([[1. , 0. ], [0.68939709, 0.31060291]]), array([[1. , 0. ], [0.70602911, 0.29397089]]), array([[1. , 0. ], [0.604158, 0.395842]]), array([[1. , 0. ], [0.49700227, 0.50299773]]), array([[1.00000000e+00, 0.00000000e+00], [5.64652739e-04, 9.99435347e-01]]), array([[0.98490566, 0.01509434], [0.00283286, 0.99716714]]), array([[0.89204545, 0.10795455], [0.00224467, 0.99775533]]), array([[0.91557064, 0.08442936], [0.00154799, 0.99845201]]), array([[0.90384615, 0.09615385], [0.00404858, 0.99595142]]), array([[0.99555016, 0.00444984], [0.00188324, 0.99811676]]), array([[1.00000000e+00, 0.00000000e+00], [8.11030008e-04, 9.99188970e-01]]), array([[0.98553719, 0.01446281], [0.00171527, 0.99828473]]), array([[0.93906305, 0.06093695], [0.00609756, 0.99390244]]), array([[0.96830601, 0.03169399], [0.00387597, 0.99612403]]), array([[0.9640592 , 0.0359408 ], [0.00606061, 0.99393939]]), array([[0.95831561, 0.04168439], [0.00153374, 0.99846626]])]
the script shows the next error:
Traceback (most recent call last): File "b5nhclassification.py", line 1017, in <module> prop_values = tree.propagate(values) File "/usr/local/lib/python3.5/dist-packages/junctiontree/junctiontree.py", line 331, in propagate return self.clique_tree.marginalize(ys) File "/usr/local/lib/python3.5/dist-packages/junctiontree/junctiontree.py", line 270, in marginalize self.factor_to_maxclique File "/usr/local/lib/python3.5/dist-packages/junctiontree/junctiontree.py", line 268, in <listcomp> for (factor_keys, maxclique) in zip( TypeError: list indices must be integers or slices, not NoneType
I dont understant it, please help me
for copy and paste my code I use:
import numpy as np
array = np.array

Thanks for the report. This is probably the same issue I also encountered. I opened a bug report for that: #2

We'll try to fix this soon.

This error is due to the format of the factors list provided to the create_junction_tree method. The factors list should contain lists of strings. The first element of factors in the code above is the string 'main_root' but it should be provided as ['main_root']. This eventually causes the error seen above. I have added an assertion to the code to ensure that input factors are provided as a list of lists as expected. This change can be found in #4

Closing this ticket.