causalincentives / pycid

Library for graphical models of decision making, based on pgmpy and networkx
Apache License 2.0
96 stars 13 forks source link

alternative layouts for drawn (MA)CIDs #60

Closed sbenthall closed 2 years ago

sbenthall commented 2 years ago

The draw() method currently fixes the layout method for the drawn diagram as Kamada-Kawai. This is laying out the nodes in a roughly circular pattern, with no orientation based on node depth.

As a feature request, this layout method could be exposed as a keyword argument for the draw() method, allowing the user to try alternative layout algorithms. Or even provide their own positions for nodes.

https://github.com/causalincentives/pycid/blob/e79b237a098ea1d2a128f2296be589858df2e4f3/pycid/core/causal_bayesian_network.py#L269-L281

In particular, the graphviz/dot algorithm might be better for these kinds of diagrams, because it would position the nodes vertically in depth order.

That said, I believe using the graphviz layout in NetworkX requires the installation of an additional and somewhat cumbersome dependency (the graphviz package, which is an C library not installable with pip, if memory serves). So while it is a useful option, there may be good reasons not to use it as the default layout.

RyanCarey commented 2 years ago

Exposing as a keyword argument is a clear win. I would encourage anyone to implement this, or a (non-default) graphviz option!