MCPcopy Create free account
hub / github.com/PythonOT/POT / build_noisy_circular_graph

Function build_noisy_circular_graph

examples/gromov/plot_partial_fgw.py:57–76  ·  view source on GitHub ↗

Create a noisy circular graph

(n_clean=15, n_noise=5, random_seed=0)

Source from the content-addressed store, hash-verified

55
56
57def build_noisy_circular_graph(n_clean=15, n_noise=5, random_seed=0):
58 """Create a noisy circular graph"""
59 # create clean circle
60 np.random.seed(random_seed)
61 g = nx.Graph()
62 g.add_nodes_from(np.arange(n_clean + n_noise))
63 for i in range(n_clean):
64 g.add_node(i, weight=math.sin(2 * i * math.pi / n_clean))
65 if i == (n_clean - 1):
66 g.add_edge(i, 0)
67 else:
68 g.add_edge(i, i + 1)
69 # add nodes out of the circle as structure noise
70 if n_noise > 0:
71 noisy_nodes = np.random.choice(np.arange(n_clean), n_noise)
72 for i, j in enumerate(noisy_nodes):
73 g.add_node(i + n_clean, weight=math.sin(2 * j * math.pi / n_clean))
74 g.add_edge(i + n_clean, j)
75 g.add_edge(i + n_clean, (j + 1) % n_clean)
76 return g
77
78
79def graph_colors(nx_graph, vmin=0, vmax=7):

Callers 1

Calls 2

seedMethod · 0.45
arangeMethod · 0.45

Tested by

no test coverage detected