-
Notifications
You must be signed in to change notification settings - Fork 692
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 causing errors when fitting the parameter to DBN #1737
Comments
@Rajaram1604 The error is because of changes in the lastest version of networkx. This has already been fixed in pgmpy but hasn't been released yet. Could you give it another try using the dev branch of pgmpy? You can install it using:
|
Thanks @ankurankan for the quick response, let me try with dev branch installation and update you. |
Yes @ankurankan , its working after installing pgmpy from the dev branch. Thanks for the update. Also, just wanted to know currently , Is pgmpy supporting the online learning for continuous streaming data for the DBN as i don't find fit_update method in the DynamicBayesianNetwork class as well as is there any algorithm for learning the structure from the data's for DBN by using HillClimbSearch or some other algorithm? |
@Rajaram1604 Sorry for the late reply. Unfortunately, there's no support for either of those for DBNs yet. |
Will it be incorporated these features with pgmpy in the near future or do you have any timeline? |
@Rajaram1604 Sorry for the late reply. Unfortunately, we don't have a timeline currently for adding these. |
Subject of the issue
DBNInference causing errors when fitting the parameter to DBN
Your environment
Steps to reproduce
Example code:
`from pgmpy.models import DynamicBayesianNetwork as DBN
from pgmpy.inference import DBNInference
import numpy as np
import pandas as pd
Create a DBN
dbn = DBN()
Add Edges
dbn.add_edges_from([
(("A", 0), ("B", 0)),
(("A", 0), ("C", 0)),
(("B", 0), ("D", 0)),
(("C", 0), ("D", 0)),
(("A", 0), ("A", 1)),
(("B", 0), ("B", 1)),
(("C", 0), ("C", 1)),
(("D", 0), ("D", 1)),
])
Generating Random data
data = np.random.randint(low=0, high=2, size=(1000, 20))
print(data)
col_names = []
for t in range(5):
...
col_names.extend([("A", t), ("B", t), ("C", t), ("D", t)])
df = pd.DataFrame(data, columns=col_names)
print(df)
print("Edges: ", dbn.edges)
fit the data into model, Currently only Maximum Likelihood Estimator is supported.
dbn.fit(df, estimator="MLE")
dbn.initialize_initial_state()
assert dbn.check_model()
for cpd in dbn.get_cpds():
print(cpd)
making inference
inference = DBNInference(dbn)
results = inference.query(variables=[("A", 0)], evidence= {("B", 0): 1})
print(results[("A", 0)])
`
Expected behaviour
It should give the inference results
Actual behaviour
Traceback (most recent call last):
File "C:\Users\Rajarampandian.A\PycharmProjects\pythonProject1\dbn_parameter_learning.py", line 43, in
inference = DBNInference(dbn)
^^^^^^^^^^^^^^^^^
File "C:\Users\Rajarampandian.A\PycharmProjects\pythonProject1.venv\Lib\site-packages\pgmpy\inference\dbn_inference.py", line 75, in init
self.one_and_half_junction_tree = one_and_half_markov_model.to_junction_tree()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Rajarampandian.A\PycharmProjects\pythonProject1.venv\Lib\site-packages\pgmpy\models\MarkovNetwork.py", line 515, in to_junction_tree
triangulated_graph = self.triangulate()
^^^^^^^^^^^^^^^^^^
File "C:\Users\Rajarampandian.A\PycharmProjects\pythonProject1.venv\Lib\site-packages\pgmpy\models\MarkovNetwork.py", line 433, in triangulate
clique_dict, clique_dict_removed = _get_cliques_dict(node)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Rajarampandian.A\PycharmProjects\pythonProject1.venv\Lib\site-packages\pgmpy\models\MarkovNetwork.py", line 409, in _get_cliques_dict
clique_dict = nx.cliques_containing_node(
^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'networkx' has no attribute 'cliques_containing_node'
The text was updated successfully, but these errors were encountered: