dmlc--dgl
9b34b1c22a
* stgcn_wave model * fix readme * rm data file * split sensors2graph * rm dead code * fix README * rename class * rm seed & dead code * Update README.md * rm dead code & networkx * add num_layer papram, make model structure adjustable * fix * add model structure controller string, make code easier to understand and make model strcture more flexible * Update main.py * Update model.py * fix * Update README.md Co-authored-by: Ubuntu <ubuntu@ip-172-31-14-255.ap-northeast-1.compute.internal> Co-authored-by: Quan (Andy) Gan <coin2028@hotmail.com> Co-authored-by: Da Zheng <zhengda1936@gmail.com>
31 行
842 B
Python
31 行
842 B
Python
import torch
|
|
import numpy as np
|
|
import pandas as pd
|
|
|
|
|
|
|
|
def load_data(file_path, len_train, len_val):
|
|
df = pd.read_csv(file_path, header=None).values.astype(float)
|
|
train = df[: len_train]
|
|
val = df[len_train: len_train + len_val]
|
|
test = df[len_train + len_val:]
|
|
return train, val, test
|
|
|
|
|
|
def data_transform(data, n_his, n_pred, device):
|
|
# produce data slices for training and testing
|
|
n_route = data.shape[1]
|
|
l = len(data)
|
|
num = l-n_his-n_pred
|
|
x = np.zeros([num, 1, n_his, n_route])
|
|
y = np.zeros([num, n_route])
|
|
|
|
cnt = 0
|
|
for i in range(l-n_his-n_pred):
|
|
head = i
|
|
tail = i + n_his
|
|
x[cnt, :, :, :] = data[head: tail].reshape(1, n_his, n_route)
|
|
y[cnt] = data[tail + n_pred - 1]
|
|
cnt += 1
|
|
return torch.Tensor(x).to(device), torch.Tensor(y).to(device)
|