-
Notifications
You must be signed in to change notification settings - Fork 693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DBNInference ValueError: Self loops are not allowed #1364
Comments
I think I got the problem. The issue is related to the function If we run Going in deep to
It gets the first letter of the first node of a edge and attach the input One possible solution is to set the inputs of |
@576774572 Keep in mind that perhaps your model is not completely correct, despite the bug. I would say that it would be more correct like this:
Because first, all 4 nodes in all time slices are represented by a CPD; second, all 4 edges are represented; and third, the CDP of |
This doesn't seem to be fixed yet. Another example: import numpy as np
from scipy.special import softmax
from pgmpy.models import DynamicBayesianNetwork
from pgmpy.inference import DBNInference
from pgmpy.factors.discrete import TabularCPD
edges=[
( ('A', 0) , ('A', 1) ),
( ('A', 0) , ('B', 1) ),
( ('B', 0) , ('A', 1) ),
( ('B', 0) , ('B', 1) ),
( ('L', 0) , ('A', 0) ),
( ('L', 0) , ('B', 0) ),
( ('L', 0) , ('L', 1) ),
( ('L', 1) , ('A', 1) ),
( ('L', 1) , ('B', 1) ),
]
bnet=DynamicBayesianNetwork(edges)#, latents=set('L'))
bnet_cpds = []
bnet_cpds.append(
TabularCPD(('A',0), 2, softmax(np.ones((2,2)), axis=0), evidence=[('L', 0)], evidence_card=[2]))
bnet_cpds.append(
TabularCPD(('B',0), 2, softmax(np.ones((2,2)), axis=0), evidence=[('L', 0)], evidence_card=[2]))
bnet_cpds.append(
TabularCPD(('L',0), 2, softmax(np.ones((2,1)), axis=0)))
bnet_cpds.append(
TabularCPD(('A', 1), 2, softmax(np.ones((2,8)), axis=0), evidence=[('A', 0), ('B', 0), ('L', 1)], evidence_card=[2,2,2]))
bnet_cpds.append(
TabularCPD(('B', 1), 2, softmax(np.ones((2,8)), axis=0), evidence=[('A', 0), ('B', 0), ('L', 1)], evidence_card=[2,2,2]))
bnet_cpds.append(
TabularCPD(('L',1), 2, softmax(np.ones((2,2)), axis=0), evidence=[('L', 0)], evidence_card=[2]))
bnet.add_cpds(*bnet_cpds)
ie=DBNInference(bnet)
# Error: Self loops are not allowed |
Ok, my tests were not so good to check the networks. I think the issue is linked to this part, specially with pgmpy/pgmpy/inference/dbn_inference.py Lines 67 to 73 in ec7e5b4
@ankurankan You can assign me to this issue to remember me to solve it in the following weeks, if you want. |
Hi!
when I try to construct model with DBN like this:
from pgmpy.models import DynamicBayesianNetwork as DBN
from pgmpy.factors.discrete import TabularCPD
from pgmpy.inference import DBNInference
dbn = DBN()
dbn.add_edges_from([(('a', 0),('b', 0)),(('a', 0),('a', 1)), (('a', 0),('b', 1))])
a_0=TabularCPD(('a', 0), 2, [[0.5],[0.5]])
b_0=TabularCPD(('b', 0), 2, [[0.3,0.7],[0.7,0.3]],[('a',0)],[2])
a_1=TabularCPD(('a', 1), 2, [[0.3,0.7],[0.7,0.3]],[('a',0)],[2])
dbn.add_cpds(a_0, b_0, a_1)
dbn_inf = DBNInference(dbn)
But when I execute the code I get this error:
File "C:\users\a5767\appdata\local\programs\python\python36\lib\site-packages\pgmpy\models\untitled9.py", line 25, in <module> dbn_inf = DBNInference(dbn)
File "c:\users\a5767\appdata\local\programs\python\python36\lib\site-packages\pgmpy\inference\dbn_inference.py", line 70, in __init__ start_markov_model.add_edges_from(combinations_slice_0[0])
File "c:\users\a5767\appdata\local\programs\python\python36\lib\site-packages\pgmpy\base\UndirectedGraph.py", line 252, in add_edges_from self.add_edge(edge[0], edge[1])
File "c:\users\a5767\appdata\local\programs\python\python36\lib\site-packages\pgmpy\models\MarkovModel.py", line 105, in add_edge raise ValueError("Self loops are not allowed")
ValueError: Self loops are not allowed
Thank you very much for someone who can help me with this error.
The text was updated successfully, but these errors were encountered: