comparison env/lib/python3.9/site-packages/networkx/algorithms/moral.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 r"""Function for computing the moral graph of a directed graph."""
2
3 from networkx.utils import not_implemented_for
4 import itertools
5
6 __all__ = ["moral_graph"]
7
8
9 @not_implemented_for("undirected")
10 def moral_graph(G):
11 r"""Return the Moral Graph
12
13 Returns the moralized graph of a given directed graph.
14
15 Parameters
16 ----------
17 G : NetworkX graph
18 Directed graph
19
20 Returns
21 -------
22 H : NetworkX graph
23 The undirected moralized graph of G
24
25 Notes
26 ------
27 A moral graph is an undirected graph H = (V, E) generated from a
28 directed Graph, where if a node has more than one parent node, edges
29 between these parent nodes are inserted and all directed edges become
30 undirected.
31
32 https://en.wikipedia.org/wiki/Moral_graph
33
34 References
35 ----------
36 .. [1] Wray L. Buntine. 1995. Chain graphs for learning.
37 In Proceedings of the Eleventh conference on Uncertainty
38 in artificial intelligence (UAI'95)
39 """
40 if G is None:
41 raise ValueError("Expected NetworkX graph!")
42
43 H = G.to_undirected()
44 for preds in G.pred.values():
45 predecessors_combinations = itertools.combinations(preds, r=2)
46 H.add_edges_from(predecessors_combinations)
47 return H