| 156 | |
| 157 | |
| 158 | class TPA(nn.Module): |
| 159 | def __init__(self, seq, n_fea): |
| 160 | super(TPA, self).__init__() |
| 161 | self.encoder = nn.Conv2d(self.nodes, self.nodes, (n_fea, n_fea), device=device) |
| 162 | # TPA |
| 163 | self.lstm = nn.LSTM(2, 2, num_layers=2, batch_first=True, device=device) |
| 164 | self.fc1 = nn.Linear(in_features=self.seq - 1, out_features=2, device=device) |
| 165 | self.fc2 = nn.Linear(in_features=2, out_features=2, device=device) |
| 166 | self.fc3 = nn.Linear(in_features=2 + 2, out_features=1, device=device) |
| 167 | self.decoder = nn.Linear(self.seq, 1, device=device) |
| 168 | |
| 169 | def forward(self, occ, prc): # occ.shape = [batch, node, seq] |
| 170 | x = torch.stack([occ, prc], dim=3) |
| 171 | x = self.encoder(x) |
| 172 | x = torch.squeeze(x) |
| 173 | |
| 174 | # TPA |
| 175 | lstm_out, (_, _) = self.lstm(x) # b*n, s, 2 |
| 176 | ht = lstm_out[:, -1, :] # ht |
| 177 | hw = lstm_out[:, :-1, :] # from h(t-1) to h1 |
| 178 | hw = torch.transpose(hw, 1, 2) |
| 179 | Hc = self.fc1(hw) |
| 180 | Hn = self.fc2(Hc) |
| 181 | ht = torch.unsqueeze(ht, dim=2) |
| 182 | a = torch.bmm(Hn, ht) |
| 183 | a = torch.sigmoid(a) |
| 184 | a = torch.transpose(a, 1, 2) |
| 185 | vt = torch.matmul(a, Hc) |
| 186 | ht = torch.transpose(ht, 1, 2) |
| 187 | hx = torch.cat((vt, ht), dim=2) |
| 188 | y = self.fc3(hx) |
| 189 | print(y.shape) |
| 190 | return y |
| 191 | |
| 192 | |
| 193 | # https://doi.org/10.1016/j.trc.2023.104205 |
nothing calls this directly
no outgoing calls
no test coverage detected