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

The DAG is not a DAG! #1589

Closed
samanemami opened this issue Jan 3, 2023 · 2 comments
Closed

The DAG is not a DAG! #1589

samanemami opened this issue Jan 3, 2023 · 2 comments

Comments

@samanemami
Copy link

Subject of the issue

I tried to estimate the DAG structure with a tree search but I have repeated nodes with various connections!

Your environment

  • pgmpy version: 0.1.19
  • Python version: 3.6.5, 3.9, 3.10.0
  • Operating System: Windows and Linux

Steps to reproduce

est = TreeSearch(values, root_node='B')
model = est.estimate(estimator_type='chow-liu')

Expected behaviour

The edges should be unique and directed not multiple

Actual behaviour

Having duplicated nodes with various edges

@ankurankan
Copy link
Member

@samanemami Thanks for creating the issue. Would it be possible for you to share some of your data or give more details on what it looks like? I am not able to reproduce your issue using a different dataset.

In [1]: from pgmpy.utils import get_example_model

In [2]: model = get_example_model('alarm')
d
In [3]: data = model.simulate()
Generating for node: BP: 100%|██████████████████████████████████████████| 37/37 [00:00<00:00, 600.00it/s]

In [4]: from pgmpy.estimators import TreeSearch

In [6]: est = TreeSearch(data, root_node='HISTORY')

In [7]: est.estimate(estimator_type='chow-liu')
Building tree: 100%|████████████████████████████████████████████████| 666/666.0 [00:00<00:00, 756.91it/s]
Out[7]: <pgmpy.base.DAG.DAG at 0x7f3456214850>

In [8]: dag = est.estimate(estimator_type='chow-liu')
Building tree: 100%|████████████████████████████████████████████████| 666/666.0 [00:00<00:00, 769.44it/s]

# Nodes are exactly the same as in data.
In [12]: set(list(dag.nodes())) == set(list(data.columns))
Out[12]: True

# There are no repeated edges.
In [15]: len(list(dag.edges())) == len(set(list(dag.edges())))
Out[15]: True

In [29]: dag.to_daft('circular', pgm_params={'grid_unit': 10})
Out[29]: <daft.PGM at 0x7f3446375a60>

# Network plot attached below
In [30]: _.render()

Figure_2

@samanemami
Copy link
Author

Hi @ankurankan

Thank you for your kind reply and the shared experiment.
I reproduced everything from scratch and I found that the DAG had overwritten on the previous and caused the issue.

Thank you again for your amazing repository and support.

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