(self, occ, prc, lb, pt, device, adj, law, num_layers=2, prop=0.4)
| 153 | |
| 154 | class PseudoDataset(Dataset): |
| 155 | def __init__(self, occ, prc, lb, pt, device, adj, law, num_layers=2, prop=0.4): # adj |
| 156 | occ, label = create_rnn_data(occ, lb, pt) |
| 157 | prc, _ = create_rnn_data(prc, lb, pt) |
| 158 | self.occ = torch.Tensor(occ) |
| 159 | self.prc = torch.Tensor(prc) |
| 160 | self.label = torch.Tensor(label) |
| 161 | self.device = device |
| 162 | self.adj = adj |
| 163 | self.eye = torch.eye(adj.shape[0]) |
| 164 | self.deg = torch.sum(adj, dim=0) |
| 165 | self.num_layers = num_layers |
| 166 | self.prop = prop # Proportion of nodes with price changes |
| 167 | self.law = -law |
| 168 | |
| 169 | # price changes |
| 170 | node_score = torch.rand(size=[self.occ.shape[2]]) |
| 171 | shred = torch.quantile(node_score, self.prop) |
| 172 | prc_chg = torch.randn_like(node_score) / 2 # Percentage change in price |
| 173 | prc_chg[torch.where(node_score > self.prop)] = 0 |
| 174 | self.prc_chg = prc_chg |
| 175 | |
| 176 | # label changes |
| 177 | label_chg = self.law * prc_chg # Percentage change in occupancy |
| 178 | label_chg = torch.unsqueeze(label_chg, dim=1) # [node, 1] |
| 179 | hop_chg = -label_chg |
| 180 | label_chg = [label_chg] |
| 181 | deg = torch.unsqueeze(self.deg, dim=1) # [node, 1] |
| 182 | for n in range(self.num_layers): # graph propagation |
| 183 | hop_chg = torch.matmul(self.adj-self.eye, hop_chg) * (1 / deg) |
| 184 | label_chg.append(hop_chg) |
| 185 | label_chg = torch.stack(label_chg, dim=1) # [node, num_layers] |
| 186 | label_chg = torch.sum(label_chg, dim=1) # [node, ] |
| 187 | self.label_chg = torch.squeeze(label_chg, dim=1) |
| 188 | |
| 189 | def __len__(self): |
| 190 | return len(self.occ) |
nothing calls this directly
no test coverage detected