| 104 | |
| 105 | |
| 106 | class CreateFastDataset(Dataset): |
| 107 | def __init__(self, occ, prc, lb, pt, law, device, adj, num_layers=2, prob=0.6): # adj |
| 108 | occ, label = create_rnn_data(occ, lb, pt) |
| 109 | prc, _ = create_rnn_data(prc, lb, pt) |
| 110 | self.occ = torch.Tensor(occ) |
| 111 | self.prc = torch.Tensor(prc) |
| 112 | self.label = torch.Tensor(label) |
| 113 | self.device = device |
| 114 | self.adj = adj |
| 115 | self.eye = torch.eye(adj.shape[0]) |
| 116 | self.deg = torch.sum(adj, dim=0) |
| 117 | self.num_layers = num_layers |
| 118 | self.law = -law |
| 119 | |
| 120 | # price |
| 121 | chg = torch.randn(size=[self.occ.shape[2]]) / 2 |
| 122 | chg[torch.where(chg < prob)] = 0 |
| 123 | self.prc_chg = chg # [node, ] |
| 124 | |
| 125 | # label |
| 126 | chg = torch.unsqueeze(chg, dim=1) # [node, 1] |
| 127 | deg = torch.unsqueeze(self.deg, dim=1) # [node, 1] |
| 128 | label_chg = [-chg] |
| 129 | hop_chg = chg |
| 130 | for n in range(self.num_layers): # graph propagation |
| 131 | hop_chg = torch.matmul(self.adj-self.eye, hop_chg) * (1 / deg) |
| 132 | label_chg.append(hop_chg) |
| 133 | label_chg = torch.stack(label_chg, dim=1) # [node, num_layers] |
| 134 | label_chg = torch.sum(label_chg, dim=1) # [node, ] |
| 135 | self.label_chg = torch.squeeze(label_chg, dim=1) |
| 136 | |
| 137 | def __len__(self): |
| 138 | return len(self.occ) |
| 139 | |
| 140 | def __getitem__(self, idx): # occ: batch, seq, node |
| 141 | # Pseudo Sampling |
| 142 | prc_ch = torch.Tensor(self.prc[idx, :, :] * (1+self.prc_chg)) # [node, seq] |
| 143 | label_ch = torch.tan(torch.Tensor(self.label[idx, :] * (1+self.label_chg/self.law))) # [node, ] |
| 144 | |
| 145 | # to device |
| 146 | output_occ = torch.transpose(self.occ[idx, :, :], 0, 1).to(self.device) |
| 147 | output_prc = torch.transpose(self.prc[idx, :, :], 0, 1).to(self.device) |
| 148 | output_label = self.label[idx, :].to(self.device) |
| 149 | output_prc_ch = torch.transpose(prc_ch, 0, 1).to(self.device) |
| 150 | output_label_ch = label_ch.to(self.device) |
| 151 | return output_occ, output_prc, output_label, output_prc_ch, output_label_ch |
| 152 | |
| 153 | |
| 154 | class PseudoDataset(Dataset): |
nothing calls this directly
no outgoing calls
no test coverage detected