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

Error about separate graphs when learning BN #136

Closed
sersoage opened this issue Sep 22, 2021 · 2 comments
Closed

Error about separate graphs when learning BN #136

sersoage opened this issue Sep 22, 2021 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@sersoage
Copy link

sersoage commented Sep 22, 2021

Description

I am getting the following error "The given structure has 5 separated graph components. Please make sure it has only one."
Structure was learnt with notears but when i run bn = BayesianNetwork(sm) i get the above error. Any advice? How can I select or display the particular subgraphs

Context

Trying to compute CPT and display markov blanket

@oentaryorj oentaryorj added the question Further information is requested label Sep 22, 2021
@oentaryorj oentaryorj self-assigned this Sep 22, 2021
@oentaryorj
Copy link
Contributor

oentaryorj commented Sep 22, 2021

Thanks for the question.

Ideally, the structure model to be fed into BayesianNetwork should be a single connected component with no isolated nodes.

You can use plot_structure to inspect the graph produced by NOTEARS, as per this tutorial, and then manually remove nodes or edges based on, e.g., input from domain experts. We also have a helper function sm.get_largest_subgraph() to extract the largest connected component in the graph, as well as sm.get_target_subgraph() to extract the subgraph for a given node.

Alternatively, to iterate over all subgraphs, you can use the function weakly_connected_components in networkx. For example:

import networkx as nx

for sub_graph in nx.weakly_connected_components(sm):
     print(list(sub_graph.edges()))

Do let us know if the above helps.

@oentaryorj
Copy link
Contributor

Closing this for now. Feel free to open a new issue if you have another enquiry. Thank you.

@qbphilip qbphilip mentioned this issue Nov 10, 2021
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants