PyBNesian icon indicating copy to clipboard operation
PyBNesian copied to clipboard

Visualizing Bayesian Networks

Open LuisOB33 opened this issue 2 years ago • 0 comments

For those interested in visualizing Graph or GaussianNetwork objects, I have developed this code:

!pip install networkx
import networkx as nx

def visualizeGraph(bnGraph):
  G = nx.DiGraph()
  G.add_edges_from(bnGraph.arcs(), weight=1)
  return nx.draw(G, with_labels=True, node_size=1500, node_color='b', alpha=0.6)

gbn = bn.GaussianNetwork(['a', 'b', 'c', 'd'], [('a', 'c'), ('b', 'c'), ('c', 'd')])
graph = gbn.graph()


visualizeGraph(gbn)
visualizeGraph(graph)

The visualizeGraph function could be modified following the networkx documentation as to achieve different results

LuisOB33 avatar Feb 10 '23 11:02 LuisOB33