(self, occ, prc, lb, pt, law, device, adj, num_layers=2, prob=0.6)
| 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) |
nothing calls this directly
no test coverage detected