tgb.nodeproppred
NodePropPredDataset
Bases: object
Source code in tgb/nodeproppred/dataset.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
|
edge_feat: Optional[np.ndarray]
property
Returns the edge features of the dataset with dim [E, feat_dim] Returns: edge_feat: np.ndarray, [E, feat_dim] or None if there is no edge feature
eval_metric: str
property
the official evaluation metric for the dataset, loaded from info.py Returns: eval_metric: str, the evaluation metric
full_data: Dict[str, Any]
property
the full data of the dataset as a dictionary with keys: 'sources', 'destinations', 'timestamps', 'edge_idxs', 'edge_feat', 'w', 'edge_label',
Returns:
Name | Type | Description |
---|---|---|
full_data |
Dict[str, Any]
|
Dict[str, Any] |
node_feat: Optional[np.ndarray]
property
Returns the node features of the dataset with dim [N, feat_dim] Returns: node_feat: np.ndarray, [N, feat_dim] or None if there is no node feature
num_classes: int
property
number of classes in the node label Returns: num_classes: int, number of classes
test_mask: np.ndarray
property
Returns the test mask of the dataset: Returns: test_mask: Dict[str, Any]
train_mask: np.ndarray
property
Returns the train mask of the dataset Returns: train_mask
val_mask: np.ndarray
property
Returns the validation mask of the dataset Returns: val_mask: Dict[str, Any]
__init__(name, root='datasets', meta_dict=None, preprocess=True)
Dataset class for the node property prediction task. Stores meta information about each dataset such as evaluation metrics etc. also automatically pre-processes the dataset. [!] node property prediction datasets requires the following: self.meta_dict["fname"]: path to the edge list file self.meta_dict["nodefile"]: path to the node label file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the dataset |
required |
root |
Optional[str]
|
root directory to store the dataset folder |
'datasets'
|
meta_dict |
Optional[dict]
|
dictionary containing meta information about the dataset, should contain key 'dir_name' which is the name of the dataset folder |
None
|
preprocess |
Optional[bool]
|
whether to pre-process the dataset |
True
|
Returns: None
Source code in tgb/nodeproppred/dataset.py
download()
downloads this dataset from url check if files are already downloaded Returns: None
Source code in tgb/nodeproppred/dataset.py
find_next_labels_batch(cur_t)
this returns the node labels closest to cur_t (for that given day) Parameters: cur_t: current timestamp of the batch of edges Returns: ts: timestamp of the node labels source_idx: node ids labels: the stacked label vectors
Source code in tgb/nodeproppred/dataset.py
generate_processed_files()
returns an edge list of pandas data frame Returns: df: pandas data frame storing the temporal edge list node_label_dict: dictionary with key as timestamp and item as dictionary of node labels
Source code in tgb/nodeproppred/dataset.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
generate_splits(full_data, val_ratio=0.15, test_ratio=0.15)
Generates train, validation, and test splits from the full dataset Parameters: full_data: dictionary containing the full dataset val_ratio: ratio of validation data test_ratio: ratio of test data Returns: train_mask: boolean mask for training data val_mask: boolean mask for validation data test_mask: boolean mask for test data
Source code in tgb/nodeproppred/dataset.py
pre_process()
Pre-process the dataset and generates the splits, must be run before dataset properties can be accessed Returns: None
Source code in tgb/nodeproppred/dataset.py
reset_label_time()
reset the pointer for node label once the entire dataset has been iterated once Returns: None
return_label_ts()
return the current label timestamp that the pointer is at Returns: ts: int, the timestamp of the node labels
Source code in tgb/nodeproppred/dataset.py
PyGNodePropPredDataset
Bases: InMemoryDataset
PyG wrapper for the NodePropPredDataset
can return pytorch tensors for src,dst,t,msg,label
can return Temporal Data object
also query the node labels corresponding to a timestamp from edge batch
Parameters:
name: name of the dataset, passed to NodePropPredDataset
root (string): Root directory where the dataset should be saved.
transform (callable, optional): A function/transform that takes in an
pre_transform (callable, optional): A function/transform that takes in
Source code in tgb/nodeproppred/dataset_pyg.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
dst: torch.Tensor
property
Returns the destination nodes of the dataset Returns: dst: the idx of the destination nodes
edge_feat: torch.Tensor
property
Returns the edge features of the dataset Returns: edge_feat: the edge features
edge_label: torch.Tensor
property
Returns the edge labels of the dataset Returns: edge_label: the labels of the edges (all one tensor)
eval_metric: str
property
the official evaluation metric for the dataset, loaded from info.py Returns: eval_metric: str, the evaluation metric
num_classes: int
property
how many classes are in the node label Returns: num_classes: int
src: torch.Tensor
property
Returns the source nodes of the dataset Returns: src: the idx of the source nodes
test_mask: torch.Tensor
property
Returns the test mask of the dataset: Returns: test_mask: the mask for edges in the test set
train_mask: torch.Tensor
property
Returns the train mask of the dataset Returns: train_mask: the mask for edges in the training set
ts: torch.Tensor
property
Returns the timestamps of the dataset Returns: ts: the timestamps of the edges
val_mask: torch.Tensor
property
Returns the validation mask of the dataset Returns: val_mask: the mask for edges in the validation set
get(idx)
construct temporal data object for a single edge Parameters: idx: index of the edge Returns: data: TemporalData object
Source code in tgb/nodeproppred/dataset_pyg.py
get_TemporalData()
return the TemporalData object for the entire dataset Returns: data: TemporalData object storing the edgelist
Source code in tgb/nodeproppred/dataset_pyg.py
get_label_time()
return the timestamps of the current node labels Returns: t: time of the current node labels
get_node_label(cur_t)
return the node labels for the current timestamp
Source code in tgb/nodeproppred/dataset_pyg.py
len()
process_data()
convert data to pytorch tensors
Source code in tgb/nodeproppred/dataset_pyg.py
Evaluator
Bases: object
Evaluator for Node Property Prediction
Source code in tgb/nodeproppred/evaluate.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
__init__(name)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the dataset |
required |
Source code in tgb/nodeproppred/evaluate.py
eval(input_dict, verbose=False)
evaluation for edge regression task
Source code in tgb/nodeproppred/evaluate.py
main()
simple test for evaluator