MCPcopy Create free account
hub / github.com/IntelligentSystemsLab/ST-EVCDP / PseudoDataset

Class PseudoDataset

functions.py:154–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152
153
154class 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)
191
192 def __getitem__(self, idx): # occ: batch, seq, node
193 # sampling
194 pseudo_prc = torch.Tensor(self.prc[idx, :, :] * (1+self.prc_chg)) # [node, seq]
195 pseudo_label = torch.tan(torch.Tensor(self.label[idx, :] * (1+self.label_chg))) # [node, ]
196
197 # to device
198 output_occ = torch.transpose(self.occ[idx, :, :], 0, 1).to(self.device)
199 output_prc = torch.transpose(self.prc[idx, :, :], 0, 1).to(self.device)
200 output_label = self.label[idx, :].to(self.device)
201 output_pseudo_prc = torch.transpose(pseudo_prc, 0, 1).to(self.device)
202 output_pseudo_label = pseudo_label.to(self.device)
203
204 return output_occ, output_prc, output_label, output_pseudo_prc, output_pseudo_label
205
206
207def meta_division(data, support_rate, query_rate):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected