(self, a_sparse, seq=12, kcnn=2, k=6, m=2)
| 79 | |
| 80 | class PAG(nn.Module): |
| 81 | def __init__(self, a_sparse, seq=12, kcnn=2, k=6, m=2): |
| 82 | super(PAG, self).__init__() |
| 83 | self.feature = seq |
| 84 | self.seq = seq-kcnn+1 |
| 85 | self.alpha = 0.5 |
| 86 | self.m = m |
| 87 | self.a_sparse = a_sparse |
| 88 | self.nodes = a_sparse.shape[0] |
| 89 | |
| 90 | # GAT |
| 91 | self.conv2d = nn.Conv2d(1, 1, (kcnn, 2)) # input.shape = [batch, channel, width, height] |
| 92 | self.gat_lyr = MultiHeadsGATLayer(a_sparse, self.seq, self.seq, 4, 0, 0.2) |
| 93 | self.gcn = nn.Linear(in_features=self.seq, out_features=self.seq) |
| 94 | |
| 95 | # TPA |
| 96 | self.lstm = nn.LSTM(m, m, num_layers=2, batch_first=True) |
| 97 | self.fc1 = nn.Linear(in_features=self.seq - 1, out_features=k) |
| 98 | self.fc2 = nn.Linear(in_features=k, out_features=m) |
| 99 | self.fc3 = nn.Linear(in_features=k + m, out_features=1) |
| 100 | self.decoder = nn.Linear(self.seq, 1) |
| 101 | |
| 102 | # Activation |
| 103 | self.dropout = nn.Dropout(p=0.5) |
| 104 | self.LeakyReLU = nn.LeakyReLU() |
| 105 | |
| 106 | # |
| 107 | adj1 = copy.deepcopy(self.a_sparse.to_dense()) |
| 108 | adj2 = copy.deepcopy(self.a_sparse.to_dense()) |
| 109 | for i in range(self.nodes): |
| 110 | adj1[i, i] = 0.000000001 |
| 111 | adj2[i, i] = 0 |
| 112 | degree = 1.0 / (torch.sum(adj1, dim=0)) |
| 113 | degree_matrix = torch.zeros((self.nodes, self.feature), device=device) |
| 114 | for i in range(12): |
| 115 | degree_matrix[:, i] = degree |
| 116 | self.degree_matrix = degree_matrix |
| 117 | self.adj2 = adj2 |
| 118 | |
| 119 | def forward(self, occ, prc): # occ.shape = [batch,node, seq] |
| 120 | b, n, s = occ.shape |
nothing calls this directly
no test coverage detected