Moving nodes around using PyAgrum for a bayesian network

37 views Asked by At

I am working on a project where I am parsing information from a file. I am using the PyAgrum library in a Jupyter notebook. I am able to successfully get the bayesian network I need generated but I am not quite able to figure out the styling. The image I attached below is very long and not very vertical and not the best looking. Is there a way I can determine where the nodes are able to be visualized and is there a way I can get the edges to not cross over each other? I am using the showInference(bayesian_network) function to visualize everything and I want my nodes to keep the same format but to just be moved around in the visualization. I wasn't able to find much in the official documentation so any help would be appreciated. I am also open to any other suggestions of tools that may work better for this sort of visualization. Thank you in advance.Image of bayesian network where edges cross and nodes are all lined up

I have tried looking into the documentation and exploring online but I couldn't find any solutions.

1

There are 1 answers

5
Pierre-Henri Wuillemin On BEST ANSWER

pyAgrum uses graphviz for the graph layout. "Dot" usually gives an interesting layout for Bayesian networks. But others (https://graphviz.org/docs/layouts/) are also accessible:

import pyAgrum as gum
import pyAgrum.lib.notebook as gnb

bn=gum.fastBN("A1->B1;A1->B2;A1->B3;A2->B1;A2->B3;A3->B3;A3->B4;A4->B4;A5->B2;A5->B3")

gum.config["notebook","graph_layout"]="dot"
gnb.showInference(bn)

gum.config["notebook","graph_layout"]="neato"
gnb.showInference(bn)

gum.config["notebook","graph_layout"]="circo"
gnb.showInference(bn)

gum.config["notebook","graph_layout"]="fdp"
gnb.showInference(bn)

enter image description here