Closed DMozhevitin closed 3 years ago
Great suggestion. Im going to look into this.
A first implementation of topological sorting is now available!
pip install -U bnlearn
import bnlearn as bn
# Set Edges in graph
edges = [('1', '2'),
('1', '3'),
('2', '4'),
('2', '3'),
('3', '4'),
('3', '5'),
]
# Make the actual Bayesian DAG
DAG = bn.make_DAG(edges, verbose=0)
# Plot
bn.plot(DAG)
# Topological ordering of the entire graph
bn.topological_sort(DAG)
#>['1', '2', '3', '4', '5']
# Topological ordering using starting point in graph
bn.topological_sort(DAG, '2')
#>['2', '3', '5', '4']
This feature might be useful in the forward sampling of Bayesian networks when we require all parents of the node to be already processed.