comparison env/lib/python3.9/site-packages/networkx/algorithms/tree/tests/test_decomposition.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 import networkx as nx
2 from networkx.algorithms.tree.decomposition import junction_tree
3
4
5 def test_junction_tree_directed_confounders():
6 B = nx.DiGraph()
7 B.add_edges_from([("A", "C"), ("B", "C"), ("C", "D"), ("C", "E")])
8
9 G = junction_tree(B)
10 J = nx.Graph()
11 J.add_edges_from(
12 [
13 (("C", "E"), ("C",)),
14 (("C",), ("A", "B", "C")),
15 (("A", "B", "C"), ("C",)),
16 (("C",), ("C", "D")),
17 ]
18 )
19
20 assert nx.is_isomorphic(G, J)
21
22
23 def test_junction_tree_directed_unconnected_nodes():
24 B = nx.DiGraph()
25 B.add_nodes_from([("A", "B", "C", "D")])
26 G = junction_tree(B)
27
28 J = nx.Graph()
29 J.add_nodes_from([("A", "B", "C", "D")])
30
31 assert nx.is_isomorphic(G, J)
32
33
34 def test_junction_tree_directed_cascade():
35 B = nx.DiGraph()
36 B.add_edges_from([("A", "B"), ("B", "C"), ("C", "D")])
37 G = junction_tree(B)
38
39 J = nx.Graph()
40 J.add_edges_from(
41 [
42 (("A", "B"), ("B",)),
43 (("B",), ("B", "C")),
44 (("B", "C"), ("C",)),
45 (("C",), ("C", "D")),
46 ]
47 )
48 assert nx.is_isomorphic(G, J)
49
50
51 def test_junction_tree_directed_unconnected_edges():
52 B = nx.DiGraph()
53 B.add_edges_from([("A", "B"), ("C", "D"), ("E", "F")])
54 G = junction_tree(B)
55
56 J = nx.Graph()
57 J.add_nodes_from([("A", "B"), ("C", "D"), ("E", "F")])
58
59 assert nx.is_isomorphic(G, J)
60
61
62 def test_junction_tree_undirected():
63 B = nx.Graph()
64 B.add_edges_from([("A", "C"), ("A", "D"), ("B", "C"), ("C", "E")])
65 G = junction_tree(B)
66
67 J = nx.Graph()
68 J.add_edges_from(
69 [
70 (("A", "D"), ("A",)),
71 (("A",), ("A", "C")),
72 (("A", "C"), ("C",)),
73 (("C",), ("B", "C")),
74 (("B", "C"), ("C",)),
75 (("C",), ("C", "E")),
76 ]
77 )
78
79 assert nx.is_isomorphic(G, J)