-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathutils.py
47 lines (40 loc) · 1.13 KB
/
utils.py
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
39
40
41
42
43
44
45
46
import numpy as np
import networkx as nx
def gaussian_normalization(train_x):
mu = np.mean(train_x, axis=0)
dev = np.std(train_x, axis=0)
norm_x = (train_x - mu) / (dev + 1e-12)
# print norm_x
return norm_x
def min_max_normalization(train_x):
_max = np.max(train_x, axis=0)
_min = np.min(train_x, axis=0)
norm_x = (train_x - _min) / (_max-_min)
# print norm_x
return norm_x
def zero_max_normalization(train_x):
_max = np.max(train_x, axis=0)
norm_x = train_x / _max
# print norm_x
return norm_x
def get_edges(G,self_edge=False):
edges = set()
u_i = []
u_j = []
label = []
for edge in G.edges():
if (edge[0],edge[1]) in edges:
continue
u_i.append(edge[0])
u_j.append(edge[1])
dat = 1
label.append(dat)
edges.add((edge[0],edge[1]))
if self_edge:
for node_index in range(nx.number_of_nodes(G)):
if (node_index,node_index) in edges:
continue
u_i.append(node_index)
u_j.append(node_index)
label.append(1)
return u_i, u_j, label