-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_graphs.py
More file actions
38 lines (33 loc) · 1.28 KB
/
example_graphs.py
File metadata and controls
38 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from signal_processing import SignalProcessingGraph
import networkx as nx
import numpy as np
class RingGraph(SignalProcessingGraph):
def __init__(self, N):
super().__init__()
for n in range(N):
self.add_node(n, value=0, x=100 * n, y=0)
self.nodes[0]['value'] = 1
for n in range(N - 1):
self.add_edge(n, n + 1, weight=1)
self.add_edge(N - 1, 0, weight=1)
class WattsStrogatzGraph(SignalProcessingGraph):
def __init__(self, N, K, beta):
super().__init__()
nw = nx.watts_strogatz_graph(N, K, beta)
for n in nw.nodes:
nw.nodes[n]['x'] = 900 * np.sin(2 * np.pi * n / N)
nw.nodes[n]['y'] = 900 * np.cos(2 * np.pi * n / N)
for n in nw.nodes:
nw.nodes[n]['value'] = 40 * (np.sin(1.5 * np.pi * n / N)) ** 2 - 4
# nw.nodes[n]['size'] = 0
for n in nw.nodes:
self.add_node(n)
for attr in nw.nodes[n]:
self.nodes[n][attr] = nw.nodes[n][attr]
self.nodes[n]['title'] = str(self.nodes[n]['value'])
for e in nw.edges:
self.add_edge(e[1], e[0])
self.add_edge(*e)
for e in self.edges:
self.edges[e]['hidden'] = False
self.edges[e]['weight'] = 1