Skip to content
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

DBN: CPD associated with (B, 1) doesn't have proper parents associated with it. #1583

Open
tomorrown opened this issue Dec 8, 2022 · 1 comment

Comments

@tomorrown
Copy link

Subject of the issue

A Dynamic Bayesian network is built, but the network is always displayed: CPD associated with (B, 1) doesn't have proper parents associated with it.

Your environment

  • pgmpy version

Steps to reproduce

from pgmpy.factors.discrete import TabularCPD
from pgmpy.models import DynamicBayesianNetwork as DBN
from pgmpy.inference import DBNInference

dbnet = DBN()
dbnet.add_edges_from(
[(('A', 0), ('B', 0)), (('A', 0), ('C', 0)),
(('C', 0), ('D', 0)), (('B', 0), ('B', 1)),
(('B', 0), ('D', 1 ))
]
)
a_cpds = TabularCPD(('A', 0), 2, [[0.7], [0.3]])
b_start_cpds = TabularCPD(
('B', 0), 2, [[0.3, 0.6],
[0.7, 0.4]],
evidence=[('A', 0)],
evidence_card=[2]
)
b_trans_cpds = TabularCPD(
('B',1), 2, [[0.1, 0.3, 0.8, 0.6],
[0.9, 0.7, 0.2, 0.4]],
evidence=[('A', 0), ('B', 0)],
evidence_card=[2, 2]
)
c_cpds = TabularCPD(
('C', 0), 2, [[0.3, 0.1],
[0.7,0.9]],
evidence=[('A', 0)],
evidence_card=[2]
)
d_start_cpds = TabularCPD(
('D',0), 2, [[0.4, 0.2], [0.6, 0.8]],
evidence=[('C', 0)],
evidence_card=[2]
)
d_trans_cpds = TabularCPD(
('D',1), 2, [[0.3, 0.4, 0.8, 0.9],
[0.7, 0.6, 0.2, 0.1]],
evidence=[('B', 0),('C',0)],
evidence_card=[2, 2]
)
dbnet.add_cpds(a_cpds, b_start_cpds, b_trans_cpds, c_cpds, d_start_cpds, d_trans_cpds)
dbnet.initialize_initial_state()
dbn_inf = DBNInference(dbnet)
temp = dbn_inf.query([('D', 1)], {('D', 0):0, ('D', 2):1})['D', 1].values
print(temp)

Expected behaviour

When the evidence under the first time slice of D is true and the evidence under the third time slice is false, the probability of the second time slice is calculated by reasoning. The final calculation result is D2, True: 0.7365902, False:0.2634098

Actual behaviour

CPD associated with (B, 1) doesn't have proper parents associated with it. Is this a problem of network model building? Specific network diagram, see [https://www.bilibili.com/video/BV1W3411M7cp/?spm_id_from=333.337.search-card.all.click&vd_source=1a42ddbfb403e da9de41b20ccdca8523]

@ankurankan
Copy link
Member

@tomorrown I think there is a slight mistake in the CPDs that you have defined. For variables (D, 1) and (B, 1), the evidence variables should be [(B, 0), (C, 1)] and [(A, 1), (B, 0)]. If you fix this, the model definition seems to work for me. The inference still is throwing an error, and I am still looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants