MCPcopy Create free account
hub / github.com/Vegetebird/GraphMLP / get_adjacency

Method get_adjacency

model/block/graph_frames.py:80–128  ·  view source on GitHub ↗
(self, strategy)

Source from the content-addressed store, hash-verified

78 raise ValueError("Do Not Exist This Layout.")
79
80 def get_adjacency(self, strategy):
81
82 valid_hop = range(0, self.max_hop + 1, self.dilation)
83 adjacency = np.zeros((self.num_node, self.num_node))
84 for hop in valid_hop:
85 adjacency[self.hop_dis == hop] = 1
86 normalize_adjacency = normalize_digraph(adjacency)
87
88 if strategy == 'spatial':
89 A = []
90 for hop in valid_hop:
91 a_root = np.zeros((self.num_node, self.num_node))
92 a_close = np.zeros((self.num_node, self.num_node))
93 a_further = np.zeros((self.num_node, self.num_node))
94 a_sym = np.zeros((self.num_node, self.num_node))
95 a_forward = np.zeros((self.num_node, self.num_node))
96 a_back = np.zeros((self.num_node, self.num_node))
97
98 for i in range(self.num_node):
99 for j in range(self.num_node):
100 if self.hop_dis[j, i] == hop:
101 if (j,i) in self.sym_link_all or (i,j) in self.sym_link_all:
102 a_sym[j, i] = normalize_adjacency[j, i]
103 elif (j,i) in self.time_link_forward:
104 a_forward[j, i] = normalize_adjacency[j, i]
105 elif (j,i) in self.time_link_back:
106 a_back[j, i] = normalize_adjacency[j, i]
107 elif self.dist_center[j] == self.dist_center[i]:
108 a_root[j, i] = normalize_adjacency[j, i]
109 elif self.dist_center[j] > self.dist_center[i]:
110 a_close[j, i] = normalize_adjacency[j, i]
111 else:
112 a_further[j, i] = normalize_adjacency[j, i]
113
114 if hop == 0:
115 A.append(a_root)
116 else:
117 A.append(a_close)
118 A.append(a_further)
119 A.append(a_sym)
120 if self.seqlen > 1:
121 A.append(a_forward)
122 A.append(a_back)
123
124 A = np.stack(A)
125 self.A = A
126
127 else:
128 raise ValueError("Do Not Exist This Strategy")
129
130
131def get_hop_distance(num_node, edge, max_hop=1):

Callers 1

__init__Method · 0.95

Calls 1

normalize_digraphFunction · 0.85

Tested by

no test coverage detected