MCPcopy Create free account
hub / github.com/IntelligentSystemsLab/ST-EVCDP / forward

Method forward

models.py:119–158  ·  view source on GitHub ↗
(self, occ, prc)

Source from the content-addressed store, hash-verified

117 self.adj2 = adj2
118
119 def forward(self, occ, prc): # occ.shape = [batch,node, seq]
120 b, n, s = occ.shape
121 data = torch.stack([occ, prc], dim=3).reshape(b*n, s, -1).unsqueeze(1)
122 data = self.conv2d(data)
123 data = data.squeeze().reshape(b, n, -1)
124
125 # first layer
126 atts_mat = self.gat_lyr(data) # attention matrix, dense(nodes, nodes)
127 occ_conv1 = torch.matmul(atts_mat, data) # (b, n, s)
128 occ_conv1 = self.dropout(self.LeakyReLU(self.gcn(occ_conv1)))
129
130 # second layer
131 atts_mat2 = self.gat_lyr(occ_conv1) # attention matrix, dense(nodes, nodes)
132 occ_conv2 = torch.matmul(atts_mat2, occ_conv1) # (b, n, s)
133 occ_conv2 = self.dropout(self.LeakyReLU(self.gcn(occ_conv2)))
134
135 occ_conv1 = (1 - self.alpha) * occ_conv1 + self.alpha * data
136 occ_conv2 = (1 - self.alpha) * occ_conv2 + self.alpha * occ_conv1
137 occ_conv1 = occ_conv1.view(b * n, self.seq)
138 occ_conv2 = occ_conv2.view(b * n, self.seq)
139
140 x = torch.stack([occ_conv1, occ_conv2], dim=2) # best
141 lstm_out, (_, _) = self.lstm(x) # b*n, s, 2
142
143 # TPA
144 ht = lstm_out[:, -1, :] # ht
145 hw = lstm_out[:, :-1, :] # from h(t-1) to h1
146 hw = torch.transpose(hw, 1, 2)
147 Hc = self.fc1(hw)
148 Hn = self.fc2(Hc)
149 ht = torch.unsqueeze(ht, dim=2)
150 a = torch.bmm(Hn, ht)
151 a = torch.sigmoid(a)
152 a = torch.transpose(a, 1, 2)
153 vt = torch.matmul(a, Hc)
154 ht = torch.transpose(ht, 1, 2)
155 hx = torch.cat((vt, ht), dim=2)
156 y = self.fc3(hx)
157 y = y.view(b, n)
158 return y

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected