import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import animation
# torch
import torch
import torch.nn.functional as F
import torch_geometric_temporal
from torch_geometric_temporal.nn.recurrent import GConvGRU
# scipy
from scipy.interpolate import interp1d
# utils
import copy
import time
import pickle
import itertools
from tqdm import tqdm
# rpy2
import rpy2
import rpy2.robjects as ro
from rpy2.robjects.vectors import FloatVector
import rpy2.robjects as robjects
from rpy2.robjects.packages import importr
import rpy2.robjects.numpy2ri as rpyn
2nd ITSTGCN
ST-GCN
GNAR fiveNet,fivenodes lag 1
import
class RecurrentGCN(torch.nn.Module):
def __init__(self, node_features, filters):
super(RecurrentGCN, self).__init__()
self.recurrent = GConvGRU(node_features, filters, 2)
self.linear = torch.nn.Linear(filters, 1)
def forward(self, x, edge_index, edge_weight):
= self.recurrent(x, edge_index, edge_weight)
h = F.relu(h)
h = self.linear(h)
h return h
pre-defined
def load_data(fname):
with open(fname, 'rb') as outfile:
= pickle.load(outfile)
data_dict return data_dict
def save_data(data_dict,fname):
with open(fname,'wb') as outfile:
pickle.dump(data_dict,outfile)
def plot(f,*args,t=None,h=2.5,**kwargs):
= f.shape
T,N if t is None: t = range(T)
= plt.figure()
fig = fig.subplots(N,1)
ax for n in range(N):
*args,**kwargs)
ax[n].plot(t,f[:,n],'node='+str(n))
ax[n].set_title(*h)
fig.set_figheight(N
fig.tight_layout()
plt.close()return fig
def plot_add(fig,f,*args,t=None,**kwargs):
= f.shape[0]
T = f.shape[1]
N if t is None: t = range(T)
= fig.get_axes()
ax for n in range(N):
*args,**kwargs)
ax[n].plot(t,f[:,n],return fig
def make_Psi(T):
= np.zeros((T,T))
W for i in range(T):
for j in range(T):
if i==j :
= 0
W[i,j] elif np.abs(i-j) <= 1 :
= 1
W[i,j] = np.array(W.sum(axis=1))
d = np.diag(d)
D = np.array(np.diag(1/np.sqrt(d)) @ (D-W) @ np.diag(1/np.sqrt(d)))
L = np.linalg.eigh(L)
lamb, Psi return Psi
= importr('EbayesThresh').ebayesthresh ebayesthresh
def trim(f):
= np.array(f)
f if len(f.shape)==1: f = f.reshape(-1,1)
= f.shape
T,N = make_Psi(T)
Psi = Psi.T @ f # apply dft
fbar = np.stack([ebayesthresh(FloatVector(fbar[:,i])) for i in range(N)],axis=1)
fbar_threshed = Psi @ fbar_threshed # inverse dft
fhat return fhat
def update_from_freq_domain(signal, missing_index):
= np.array(signal)
signal = signal.shape
T,N = trim(signal)
signal_trimed for i in range(N):
= signal_trimed[missing_index[i],i]
signal[missing_index[i],i] return signal
class DatasetLoader(object):
def __init__(self,data_dict):
self._dataset = data_dict
def _get_edges(self):
self._edges = np.array(self._dataset["edges"]).T
def _get_edge_weights(self):
self._edge_weights = np.ones(self._edges.shape[1])
def _get_targets_and_features(self):
= np.array(self._dataset["FX"])
stacked_target self.features = [
+ self.lags, :].T
stacked_target[i : i for i in range(stacked_target.shape[0] - self.lags)
]self.targets = [
+ self.lags, :].T
stacked_target[i for i in range(stacked_target.shape[0] - self.lags)
]
def get_dataset(self, lags: int = 4) -> torch_geometric_temporal.signal.StaticGraphTemporalSignal:
"""Returning the Chickenpox Hungary data iterator.
Args types:
* **lags** *(int)* - The number of time lags.
Return types:
* **dataset** *(torch_geometric_temporal.signal.StaticGraphTemporalSignal)* - The Chickenpox Hungary dataset.
"""
self.lags = lags
self._get_edges()
self._get_edge_weights()
self._get_targets_and_features()
= torch_geometric_temporal.signal.StaticGraphTemporalSignal(
dataset self._edges, self._edge_weights, self.features, self.targets
)return dataset
def _convert_train_dataset(train_dataset):
= torch.tensor(train_dataset.features).shape[-1]
lags = torch.concat([train_dataset[0].x.T,torch.tensor(train_dataset.targets)],axis=0).numpy()
f return f,lags
def miss_rand(train_dataset,missing_ratio=0.5):
= _convert_train_dataset(train_dataset)
f,lags = f.shape
T,N = int(np.round(missing_ratio*T,0))
missing_count = [np.sort(np.random.choice(range(T),missing_count,replace=False)).tolist() for i in range(N)]
mindex for i,m in enumerate(mindex):
= np.nan
f[m,i] = {
data_dict 'edges':train_dataset.edge_index.T.tolist(),
'node_ids':{'node'+str(i):i for i in range(N)},
'FX':f.tolist()
}= DatasetLoader(data_dict).get_dataset(lags=lags)
train_dataset = mindex
train_dataset.mindex = [len(mx)/T for mx in mindex]
train_dataset.mrate_eachnode = float(np.sum([len(mx) for mx in train_dataset.mindex])/(N*T))
train_dataset.mrate_total= 'rand'
train_dataset.mtypereturn train_dataset
def padding(train_dataset_miss,*args,interpolation_method='linear',**kwargs):
= train_dataset_miss.mindex
mindex = _convert_train_dataset(train_dataset_miss)
f,lags = f.shape
T,N = pd.DataFrame(f).interpolate(method=interpolation_method,axis=0,*args,**kwargs).fillna(method='bfill').fillna(method='ffill').to_numpy().tolist()
FX = {
data_dict 'edges':train_dataset_miss.edge_index.T.tolist(),
'node_ids':{'node'+str(i):i for i in range(N)},
'FX':FX
}= DatasetLoader(data_dict).get_dataset(lags=lags)
train_dataset_padded = mindex
train_dataset_padded.mindex = train_dataset_miss.mrate_eachnode
train_dataset_padded.mrate_eachnode = train_dataset_miss.mrate_total
train_dataset_padded.mrate_total = train_dataset_miss.mtype
train_dataset_padded.mtype= interpolation_method
train_dataset_padded.interpolation_method return train_dataset_padded
class StgcnLearner:
def __init__(self,train_dataset,dataset_name = None):
self.train_dataset = train_dataset
self.lags = torch.tensor(train_dataset.features).shape[-1]
self.dataset_name = str(train_dataset) if dataset_name is None else dataset_name
self.mindex= getattr(self.train_dataset,'mindex',None)
self.mrate_eachnode = getattr(self.train_dataset,'mrate_eachnode',0)
self.mrate_total = getattr(self.train_dataset,'mrate_total',0)
self.mtype = getattr(self.train_dataset,'mtype',None)
self.interpolation_method = getattr(self.train_dataset,'interpolation_method',None)
self.method = 'STGCN'
def learn(self,filters=32,epoch=50):
self.model = RecurrentGCN(node_features=self.lags, filters=filters)
self.optimizer = torch.optim.Adam(self.model.parameters(), lr=0.01)
self.model.train()
for e in range(epoch):
for t, snapshot in enumerate(self.train_dataset):
= self.model(snapshot.x, snapshot.edge_index, snapshot.edge_attr)
yt_hat = torch.mean((yt_hat-snapshot.y)**2)
cost
cost.backward()self.optimizer.step()
self.optimizer.zero_grad()
print('{}/{}'.format(e+1,epoch),end='\r')
# recording HP
self.nof_filters = filters
self.epochs = epoch+1
def __call__(self,dataset):
= torch.tensor(dataset.features).float()
X = torch.tensor(dataset.targets).float()
y = torch.stack([self.model(snapshot.x, snapshot.edge_index, snapshot.edge_attr) for snapshot in dataset]).detach().squeeze().float()
yhat return {'X':X, 'y':y, 'yhat':yhat}
class Evaluator:
def __init__(self,learner,train_dataset,test_dataset):
self.learner = learner
self.learner.model.eval()
self.train_dataset = train_dataset
self.test_dataset = test_dataset
self.lags = lrnr.lags
= self.learner(self.train_dataset)
rslt_tr = self.learner(self.test_dataset)
rslt_test self.X_tr = rslt_tr['X']
self.y_tr = rslt_tr['y']
self.f_tr = torch.concat([self.train_dataset[0].x.T,self.y_tr],axis=0).float()
self.yhat_tr = rslt_tr['yhat']
self.fhat_tr = torch.concat([self.train_dataset[0].x.T,self.yhat_tr],axis=0).float()
self.X_test = rslt_test['X']
self.y_test = rslt_test['y']
self.f_test = self.y_test
self.yhat_test = rslt_test['yhat']
self.fhat_test = self.yhat_test
self.f = torch.concat([self.f_tr,self.f_test],axis=0)
self.fhat = torch.concat([self.fhat_tr,self.fhat_test],axis=0)
def calculate_mse(self):
= ((self.y_test - self.y_test.mean(axis=0).reshape(-1,self.y_test.shape[-1]))**2).mean(axis=0).tolist()
test_base_mse_eachnode = ((self.y_test - self.y_test.mean(axis=0).reshape(-1,self.y_test.shape[-1]))**2).mean().item()
test_base_mse_total = ((self.y_tr-self.yhat_tr)**2).mean(axis=0).tolist()
train_mse_eachnode = ((self.y_tr-self.yhat_tr)**2).mean().item()
train_mse_total = ((self.y_test-self.yhat_test)**2).mean(axis=0).tolist()
test_mse_eachnode = ((self.y_test-self.yhat_test)**2).mean().item()
test_mse_total self.mse = {'train': {'each_node': train_mse_eachnode, 'total': train_mse_total},
'test': {'each_node': test_mse_eachnode, 'total': test_mse_total},
'test(base)': {'each_node': test_base_mse_eachnode, 'total': test_base_mse_total},
}def _plot(self,*args,t=None,h=2.5,max_node=5,**kwargs):
= self.f.shape
T,N if t is None: t = range(T)
= plt.figure()
fig = max(min(N,max_node),2)
nof_axs if min(N,max_node)<2:
print('max_node should be >=2')
= fig.subplots(nof_axs ,1)
ax for n in range(nof_axs):
self.f[:,n],color='gray',*args,**kwargs)
ax[n].plot(t,'node='+str(n))
ax[n].set_title(*h)
fig.set_figheight(nof_axs
fig.tight_layout()
plt.close()return fig
def plot(self,*args,t=None,h=2.5,**kwargs):
self.calculate_mse()
= self._plot(*args,t=None,h=2.5,**kwargs)
fig = fig.get_axes()
ax for i,a in enumerate(ax):
= self.mse['train']['each_node'][i]
_mse1= self.mse['test']['each_node'][i]
_mse2= self.mse['test(base)']['each_node'][i]
_mse3= lrnr.mrate_eachnode if set(dir(lrnr.mrate_eachnode)) & {'__getitem__'} == set() else lrnr.mrate_eachnode[i]
_mrate = 'node{0}, mrate: {1:.2f}% \n mse(train) = {2:.2f}, mse(test) = {3:.2f}, mse(test_base) = {4:.2f}'.format(i,_mrate*100,_mse1,_mse2,_mse3)
_title
a.set_title(_title)= self.lags
_t1 = self.yhat_tr.shape[0]+self.lags
_t2 = len(self.f)
_t3 range(_t1,_t2),self.yhat_tr[:,i],label='fitted (train)',color='C0')
a.plot(range(_t2,_t3),self.yhat_test[:,i],label='fitted (test)',color='C1')
a.plot(
a.legend()= self.mse['train']['total']
_mse1= self.mse['test']['total']
_mse2= self.mse['test(base)']['total']
_mse3=\
_title 'dataset: {0} \n method: {1} \n mrate: {2:.2f}% \n interpolation:{3} \n epochs={4} \n number of filters={5} \n lags = {6} \n mse(train) = {7:.2f}, mse(test) = {8:.2f}, mse(test_base) = {9:.2f} \n'.\
format(lrnr.dataset_name,lrnr.method,lrnr.mrate_total*100,lrnr.interpolation_method,lrnr.epochs,lrnr.nof_filters,lrnr.lags,_mse1,_mse2,_mse3)
fig.suptitle(_title)
fig.tight_layout()return fig
class ITStgcnLearner(StgcnLearner):
def __init__(self,train_dataset,dataset_name = None):
super().__init__(train_dataset)
self.method = 'IT-STGCN'
def learn(self,filters=32,epoch=50):
self.model = RecurrentGCN(node_features=self.lags, filters=filters)
self.optimizer = torch.optim.Adam(self.model.parameters(), lr=0.01)
self.model.train()
= copy.copy(self.train_dataset)
train_dataset_temp for e in range(epoch):
= _convert_train_dataset(train_dataset_temp)
f,lags = update_from_freq_domain(f,self.mindex)
f = f.shape
T,N = {
data_dict_temp 'edges':self.train_dataset.edge_index.T.tolist(),
'node_ids':{'node'+str(i):i for i in range(N)},
'FX':f
}= DatasetLoader(data_dict_temp).get_dataset(lags=self.lags)
train_dataset_temp for t, snapshot in enumerate(train_dataset_temp):
= self.model(snapshot.x, snapshot.edge_index, snapshot.edge_attr)
yt_hat = torch.mean((yt_hat-snapshot.y)**2)
cost
cost.backward()self.optimizer.step()
self.optimizer.zero_grad()
print('{}/{}'.format(e+1,epoch),end='\r')
# record
self.nof_filters = filters
self.epochs = epoch+1
class SimulationPlanner:
def __init__(self,plans,loader,dataset_name=None,simulation_results=None):
self.plans = plans
= ['dataset', 'method', 'mrate', 'mtype', 'lags', 'nof_filters', 'inter_method', 'epoch', 'mse']
col self.product_iterator = itertools.product(
'method'],
plans['mrate'],
plans['mtype'],
plans['lags'],
plans['nof_filters'],
plans['inter_method'],
plans['epoch']
plans[
)self.loader = loader
self.dataset_name = dataset_name
self.simulation_results = pd.DataFrame(columns=col) if simulation_results is None else simulation_results
def _simulate_STGCN(self):
for prod_itor in self.product_iterator:
= prod_itor
method,mrate,mtype,lags,nof_filters,inter_method,epoch self.dataset = self.loader.get_dataset(lags=lags)
= torch_geometric_temporal.signal.temporal_signal_split(self.dataset, train_ratio=0.8)
train_dataset, test_dataset if mrate >0:
if mtype == 'rand':
= padding(miss_rand(train_dataset,missing_ratio=mrate),interpolation_method=inter_method)
train_dataset elif mtype == 'block':
pass
= StgcnLearner(train_dataset,dataset_name=self.dataset_name)
lrnr =nof_filters,epoch=epoch)
lrnr.learn(filters= Evaluator(lrnr,train_dataset,test_dataset)
evtor
evtor.calculate_mse()= evtor.mse['test']['total']
mse self._record(*prod_itor,mse)
def _record(self,method,mrate,mtype,lag,nof_filter,inter_method,epoch,mse):
= {'dataset': self.dataset_name,
dct 'method': method,
'mrate': mrate,
'mtype': mtype,
'lags': lag,
'nof_filters': nof_filter,
'inter_method': inter_method,
'epoch': epoch,
'mse': mse
}= pd.Series(dct).to_frame().transpose()
simulation_result_new self.simulation_results = pd.concat([self.simulation_results,simulation_result_new])
From R
%load_ext rpy2.ipython
%%R
library(GNAR)
library(igraph) library(zoo)
R[write to console]: Loading required package: igraph
R[write to console]:
Attaching package: ‘igraph’
R[write to console]: The following objects are masked from ‘package:stats’:
decompose, spectrum
R[write to console]: The following object is masked from ‘package:base’:
union
R[write to console]: Loading required package: wordcloud
R[write to console]: Loading required package: RColorBrewer
R[write to console]:
Attaching package: ‘zoo’
R[write to console]: The following objects are masked from ‘package:base’:
as.Date, as.Date.numeric
%%R
<- as.matrix(fiveNet) fiveNet_m
%R -o fiveNet_m
= importr('GNAR') # import GNAR
GNAR = importr('igraph') # import igraph igraph
예제1: vanilla STGCN
-
데이터
= load_data('./data/fivenodes.pkl') _data
= torch.tensor(_data['edges']).nonzero().tolist()
_edges = _data['f'].tolist()
_FX = {'node1':0, 'node2':1, 'node3':2, 'node4':3, 'node5':4} _node_ids
= {'edges':_edges, 'node_ids':_node_ids, 'FX':_FX} data_dict
= DatasetLoader(data_dict)
loader = loader.get_dataset(lags=2)
dataset = torch_geometric_temporal.signal.temporal_signal_split(dataset, train_ratio=0.8) train_dataset, test_dataset
-
학습
= StgcnLearner(train_dataset,dataset_name='five_nodes') lrnr
=4,epoch=50) lrnr.learn(filters
50/50
-
적합값
# lrnr(train_dataset)
# lrnr(test_dataset)
- 실행하면 X,y,yhat 출력
-
모형 평가 및 시각화
baseline
torch.tensor(test_dataset.targets).shape
torch.Size([40, 5])
- torch.tensor(test_dataset.targets).mean(axis=0).reshape(-1,5))**2).mean() ((torch.tensor(test_dataset.targets)
tensor(1.2525, dtype=torch.float64)
test MSE는 1.2525 보다는 무조건 낮아야함!! 아니라면 모형을 잘못 돌린거
= Evaluator(lrnr,train_dataset,test_dataset) evtor
= evtor.plot('--.',h=5,max_node=3,label='complete data',alpha=0.5)
fig 12)
fig.set_figwidth(
fig.tight_layout() fig
예제2: padding missing values
-
데이터
# _data = load_data('./data/fivenodes.pkl')
# _edges = torch.tensor(_data['edges']).nonzero().tolist()
# _FX = _data['f'].tolist()
# _node_ids = {'node1':0, 'node2':1, 'node3':2, 'node4':3, 'node5':4}
= {'edges':_edges, 'node_ids':_node_ids, 'FX':_FX} data_dict
= DatasetLoader(data_dict)
loader = loader.get_dataset(lags=2)
dataset = torch_geometric_temporal.signal.temporal_signal_split(dataset, train_ratio=0.8) train_dataset, test_dataset
-
임의로 결측치 발생
= miss_rand(train_dataset,missing_ratio=0.5) train_dataset_miss
= plot(torch.tensor(train_dataset_miss.targets),'o')
fig fig
-
적절한 method로 결측치를 채움 (default 는 linear)
= padding(train_dataset_miss) # padding(train_dataset_miss,method='linear'와 같음) train_dataset_padded
= plot(torch.tensor(train_dataset_miss.targets),'o')
fig '--x',color='C1',alpha=0.5) plot_add(fig,torch.tensor(train_dataset_padded.targets),
다른 method로 결측치를 채울수도 있음. 사용할 수 있는 방법들은 아래에 정리되어 있음
= padding(train_dataset_miss,interpolation_method='nearest') train_dataset_padded2
= plot(torch.tensor(train_dataset_miss.targets),'o')
fig '--x',color='C1',alpha=0.5) plot_add(fig,torch.tensor(train_dataset_padded2.targets),
= padding(train_dataset_miss,interpolation_method='quadratic') train_dataset_padded3
= plot(torch.tensor(train_dataset_miss.targets),'o')
fig '--x',color='C1',alpha=0.5) plot_add(fig,torch.tensor(train_dataset_padded3.targets),
= padding(train_dataset_miss,interpolation_method='cubic') train_dataset_padded4
= plot(torch.tensor(train_dataset_miss.targets),'o')
fig '--x',color='C1',alpha=0.5) plot_add(fig,torch.tensor(train_dataset_padded4.targets),
예제3: vanilla STGCN with random missing
-
data
# _data = load_data('./data/fivenodes.pkl')
# _edges = torch.tensor(_data['edges']).nonzero().tolist()
# _FX = _data['f'].tolist()
# _node_ids = {'node1':0, 'node2':1, 'node3':2, 'node4':3, 'node5':4}
= {'edges':_edges, 'node_ids':_node_ids, 'FX':_FX} data_dict
= DatasetLoader(data_dict)
loader = loader.get_dataset(lags=2)
dataset = torch_geometric_temporal.signal.temporal_signal_split(dataset, train_ratio=0.8) train_dataset, test_dataset
= miss_rand(train_dataset,missing_ratio=0.8)
train_dataset_miss = padding(train_dataset_miss) # padding(train_dataset_miss,method='linear'와 같음) train_dataset_padded
-
학습
= StgcnLearner(train_dataset_padded) lrnr
=4,epoch=50) lrnr.learn(filters
50/50
-
적합값
#lrnr(train_dataset_padded)
#lrnr(test_dataset)
- 실행하면 X,y,yhat 출력
-
모형 평가 및 시각화
= Evaluator(lrnr,train_dataset_padded,test_dataset) evtor
= evtor.plot('--.',h=5,max_node=5,label='complete data',alpha=0.5) # max_nodes 는 1보다 커야함
fig 12)
fig.set_figwidth(
fig.tight_layout() fig
예제4: threshold example
-
data
# _data = load_data('./data/fivenodes.pkl')
# _edges = torch.tensor(_data['edges']).nonzero().tolist()
# _FX = _data['f'].tolist()
# _node_ids = {'node1':0, 'node2':1, 'node3':2, 'node4':3, 'node5':4}
= {'edges':_edges, 'node_ids':_node_ids, 'FX':_FX} data_dict
= DatasetLoader(data_dict)
loader = loader.get_dataset(lags=2)
dataset = torch_geometric_temporal.signal.temporal_signal_split(dataset, train_ratio=0.8) train_dataset, test_dataset
-
결측치 발생 및 패딩
= miss_rand(train_dataset,missing_ratio=0.5)
train_dataset_miss = padding(train_dataset_miss) train_dataset_padded
= _convert_train_dataset(train_dataset_miss)
f_miss,_ = _convert_train_dataset(train_dataset_padded) f_padded,_
= plot(f_miss,'o')
fig '--x',alpha=0.5) plot_add(fig,f_padded,
-
update by frequency thresholding
= plot(f_miss,'o',alpha=0.5)
fig '--x',alpha=0.5)
plot_add(fig,f_padded,= update_from_freq_domain(f_padded,train_dataset_padded.mindex)
f_updated '-') plot_add(fig,f_updated,
예제5: iterative thresholded STGCN (IT-STGCN) with random missing
-
data
# _data = load_data('./data/fivenodes.pkl')
# _edges = torch.tensor(_data['edges']).nonzero().tolist()
# _FX = _data['f'].tolist()
# _node_ids = {'node1':0, 'node2':1, 'node3':2, 'node4':3, 'node5':4}
= {'edges':_edges, 'node_ids':_node_ids, 'FX':_FX} data_dict
= DatasetLoader(data_dict)
loader = loader.get_dataset(lags=2)
dataset = torch_geometric_temporal.signal.temporal_signal_split(dataset, train_ratio=0.8) train_dataset, test_dataset
= miss_rand(train_dataset,missing_ratio=0.8)
train_dataset_miss = padding(train_dataset_miss) # padding(train_dataset_miss,method='linear'와 같음) train_dataset_padded
-
학습
= ITStgcnLearner(train_dataset_padded) lrnr
=4,epoch=50) lrnr.learn(filters
50/50
-
적합값
#lrnr(train_dataset_padded)
#lrnr(test_dataset)
- 실행하면 X,y,yhat 출력
-
모형 평가 및 시각화
= Evaluator(lrnr,train_dataset_padded,test_dataset) evtor
= evtor.plot('--.',h=5,max_node=3,label='complete data',alpha=0.5) # max_nodes 는 1보다 커야함
fig 12)
fig.set_figwidth(
fig.tight_layout() fig
예제6: GNAR
예제7: SimulationPlanner
# _data = load_data('./data/fivenodes.pkl')
# _edges = torch.tensor(_data['edges']).nonzero().tolist()
# _FX = _data['f'].tolist()
# _node_ids = {'node1':0, 'node2':1, 'node3':2, 'node4':3, 'node5':4}
= {'edges':_edges, 'node_ids':_node_ids, 'FX':_FX} data_dict
= DatasetLoader(data_dict) loader
= {
plans 'max_iteration': [2],
'method':['STGCN','IT-STGCN'],
'mrate':[0.0, 0.2],
'mtype':['rand'],
'lags':[4,8],
'nof_filters':[16,24],
'inter_method':['nearest','linear'],
'epoch': [3]
}
= SimulationPlanner(plans,loader,dataset_name='five_nodes') planner
planner._simulate_STGCN()
3/3
planner.simulation_results.reset_index()
index | dataset | method | mrate | mtype | lags | nof_filters | inter_method | epoch | mse | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | five_nodes | STGCN | 0.0 | rand | 4 | 16 | nearest | 3 | 1.173286 |
1 | 0 | five_nodes | STGCN | 0.0 | rand | 4 | 16 | linear | 3 | 1.186759 |
2 | 0 | five_nodes | STGCN | 0.0 | rand | 4 | 24 | nearest | 3 | 1.15008 |
3 | 0 | five_nodes | STGCN | 0.0 | rand | 4 | 24 | linear | 3 | 1.165545 |
4 | 0 | five_nodes | STGCN | 0.0 | rand | 8 | 16 | nearest | 3 | 1.138814 |
5 | 0 | five_nodes | STGCN | 0.0 | rand | 8 | 16 | linear | 3 | 1.155973 |
6 | 0 | five_nodes | STGCN | 0.0 | rand | 8 | 24 | nearest | 3 | 1.136766 |
7 | 0 | five_nodes | STGCN | 0.0 | rand | 8 | 24 | linear | 3 | 1.12492 |
8 | 0 | five_nodes | STGCN | 0.2 | rand | 4 | 16 | nearest | 3 | 1.168188 |
9 | 0 | five_nodes | STGCN | 0.2 | rand | 4 | 16 | linear | 3 | 1.164365 |
10 | 0 | five_nodes | STGCN | 0.2 | rand | 4 | 24 | nearest | 3 | 1.174488 |
11 | 0 | five_nodes | STGCN | 0.2 | rand | 4 | 24 | linear | 3 | 1.195016 |
12 | 0 | five_nodes | STGCN | 0.2 | rand | 8 | 16 | nearest | 3 | 1.175225 |
13 | 0 | five_nodes | STGCN | 0.2 | rand | 8 | 16 | linear | 3 | 1.112919 |
14 | 0 | five_nodes | STGCN | 0.2 | rand | 8 | 24 | nearest | 3 | 1.12651 |
15 | 0 | five_nodes | STGCN | 0.2 | rand | 8 | 24 | linear | 3 | 1.117976 |
16 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 4 | 16 | nearest | 3 | 1.155314 |
17 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 4 | 16 | linear | 3 | 1.157643 |
18 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 4 | 24 | nearest | 3 | 1.17059 |
19 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 4 | 24 | linear | 3 | 1.175871 |
20 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 8 | 16 | nearest | 3 | 1.140591 |
21 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 8 | 16 | linear | 3 | 1.142235 |
22 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 8 | 24 | nearest | 3 | 1.114178 |
23 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 8 | 24 | linear | 3 | 1.130595 |
24 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 4 | 16 | nearest | 3 | 1.146638 |
25 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 4 | 16 | linear | 3 | 1.255474 |
26 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 4 | 24 | nearest | 3 | 1.193976 |
27 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 4 | 24 | linear | 3 | 1.155053 |
28 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 8 | 16 | nearest | 3 | 1.152831 |
29 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 8 | 16 | linear | 3 | 1.151021 |
30 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 8 | 24 | nearest | 3 | 1.138263 |
31 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 8 | 24 | linear | 3 | 1.129985 |
= planner.simulation_results.reset_index()
df df
index | dataset | method | mrate | mtype | lags | nof_filters | inter_method | epoch | mse | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | five_nodes | STGCN | 0.0 | rand | 4 | 16 | nearest | 3 | 1.173286 |
1 | 0 | five_nodes | STGCN | 0.0 | rand | 4 | 16 | linear | 3 | 1.186759 |
2 | 0 | five_nodes | STGCN | 0.0 | rand | 4 | 24 | nearest | 3 | 1.15008 |
3 | 0 | five_nodes | STGCN | 0.0 | rand | 4 | 24 | linear | 3 | 1.165545 |
4 | 0 | five_nodes | STGCN | 0.0 | rand | 8 | 16 | nearest | 3 | 1.138814 |
5 | 0 | five_nodes | STGCN | 0.0 | rand | 8 | 16 | linear | 3 | 1.155973 |
6 | 0 | five_nodes | STGCN | 0.0 | rand | 8 | 24 | nearest | 3 | 1.136766 |
7 | 0 | five_nodes | STGCN | 0.0 | rand | 8 | 24 | linear | 3 | 1.12492 |
8 | 0 | five_nodes | STGCN | 0.2 | rand | 4 | 16 | nearest | 3 | 1.168188 |
9 | 0 | five_nodes | STGCN | 0.2 | rand | 4 | 16 | linear | 3 | 1.164365 |
10 | 0 | five_nodes | STGCN | 0.2 | rand | 4 | 24 | nearest | 3 | 1.174488 |
11 | 0 | five_nodes | STGCN | 0.2 | rand | 4 | 24 | linear | 3 | 1.195016 |
12 | 0 | five_nodes | STGCN | 0.2 | rand | 8 | 16 | nearest | 3 | 1.175225 |
13 | 0 | five_nodes | STGCN | 0.2 | rand | 8 | 16 | linear | 3 | 1.112919 |
14 | 0 | five_nodes | STGCN | 0.2 | rand | 8 | 24 | nearest | 3 | 1.12651 |
15 | 0 | five_nodes | STGCN | 0.2 | rand | 8 | 24 | linear | 3 | 1.117976 |
16 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 4 | 16 | nearest | 3 | 1.155314 |
17 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 4 | 16 | linear | 3 | 1.157643 |
18 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 4 | 24 | nearest | 3 | 1.17059 |
19 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 4 | 24 | linear | 3 | 1.175871 |
20 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 8 | 16 | nearest | 3 | 1.140591 |
21 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 8 | 16 | linear | 3 | 1.142235 |
22 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 8 | 24 | nearest | 3 | 1.114178 |
23 | 0 | five_nodes | IT-STGCN | 0.0 | rand | 8 | 24 | linear | 3 | 1.130595 |
24 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 4 | 16 | nearest | 3 | 1.146638 |
25 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 4 | 16 | linear | 3 | 1.255474 |
26 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 4 | 24 | nearest | 3 | 1.193976 |
27 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 4 | 24 | linear | 3 | 1.155053 |
28 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 8 | 16 | nearest | 3 | 1.152831 |
29 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 8 | 16 | linear | 3 | 1.151021 |
30 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 8 | 24 | nearest | 3 | 1.138263 |
31 | 0 | five_nodes | IT-STGCN | 0.2 | rand | 8 | 24 | linear | 3 | 1.129985 |
= {
plan2 'max_iteration': [2],
'method':['STGCN','IT-STGCN'],
'mrate':[0.2],
'mtype':['rand'],
'lags':[4,8],
'nof_filters':[16,24,32],
'inter_method':['nearest'],
'epoch': [2]
}
= SimulationPlanner(plan2,loader,dataset_name='asdf',simulation_results=df) planner2
planner2._simulate_STGCN()
2/2
planner2.simulation_results
index | dataset | method | mrate | mtype | lags | nof_filters | inter_method | epoch | mse | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 0.0 | five_nodes | STGCN | 0.0 | rand | 4 | 16 | nearest | 3 | 1.173286 |
1 | 0.0 | five_nodes | STGCN | 0.0 | rand | 4 | 16 | linear | 3 | 1.186759 |
2 | 0.0 | five_nodes | STGCN | 0.0 | rand | 4 | 24 | nearest | 3 | 1.15008 |
3 | 0.0 | five_nodes | STGCN | 0.0 | rand | 4 | 24 | linear | 3 | 1.165545 |
4 | 0.0 | five_nodes | STGCN | 0.0 | rand | 8 | 16 | nearest | 3 | 1.138814 |
5 | 0.0 | five_nodes | STGCN | 0.0 | rand | 8 | 16 | linear | 3 | 1.155973 |
6 | 0.0 | five_nodes | STGCN | 0.0 | rand | 8 | 24 | nearest | 3 | 1.136766 |
7 | 0.0 | five_nodes | STGCN | 0.0 | rand | 8 | 24 | linear | 3 | 1.12492 |
8 | 0.0 | five_nodes | STGCN | 0.2 | rand | 4 | 16 | nearest | 3 | 1.168188 |
9 | 0.0 | five_nodes | STGCN | 0.2 | rand | 4 | 16 | linear | 3 | 1.164365 |
10 | 0.0 | five_nodes | STGCN | 0.2 | rand | 4 | 24 | nearest | 3 | 1.174488 |
11 | 0.0 | five_nodes | STGCN | 0.2 | rand | 4 | 24 | linear | 3 | 1.195016 |
12 | 0.0 | five_nodes | STGCN | 0.2 | rand | 8 | 16 | nearest | 3 | 1.175225 |
13 | 0.0 | five_nodes | STGCN | 0.2 | rand | 8 | 16 | linear | 3 | 1.112919 |
14 | 0.0 | five_nodes | STGCN | 0.2 | rand | 8 | 24 | nearest | 3 | 1.12651 |
15 | 0.0 | five_nodes | STGCN | 0.2 | rand | 8 | 24 | linear | 3 | 1.117976 |
16 | 0.0 | five_nodes | IT-STGCN | 0.0 | rand | 4 | 16 | nearest | 3 | 1.155314 |
17 | 0.0 | five_nodes | IT-STGCN | 0.0 | rand | 4 | 16 | linear | 3 | 1.157643 |
18 | 0.0 | five_nodes | IT-STGCN | 0.0 | rand | 4 | 24 | nearest | 3 | 1.17059 |
19 | 0.0 | five_nodes | IT-STGCN | 0.0 | rand | 4 | 24 | linear | 3 | 1.175871 |
20 | 0.0 | five_nodes | IT-STGCN | 0.0 | rand | 8 | 16 | nearest | 3 | 1.140591 |
21 | 0.0 | five_nodes | IT-STGCN | 0.0 | rand | 8 | 16 | linear | 3 | 1.142235 |
22 | 0.0 | five_nodes | IT-STGCN | 0.0 | rand | 8 | 24 | nearest | 3 | 1.114178 |
23 | 0.0 | five_nodes | IT-STGCN | 0.0 | rand | 8 | 24 | linear | 3 | 1.130595 |
24 | 0.0 | five_nodes | IT-STGCN | 0.2 | rand | 4 | 16 | nearest | 3 | 1.146638 |
25 | 0.0 | five_nodes | IT-STGCN | 0.2 | rand | 4 | 16 | linear | 3 | 1.255474 |
26 | 0.0 | five_nodes | IT-STGCN | 0.2 | rand | 4 | 24 | nearest | 3 | 1.193976 |
27 | 0.0 | five_nodes | IT-STGCN | 0.2 | rand | 4 | 24 | linear | 3 | 1.155053 |
28 | 0.0 | five_nodes | IT-STGCN | 0.2 | rand | 8 | 16 | nearest | 3 | 1.152831 |
29 | 0.0 | five_nodes | IT-STGCN | 0.2 | rand | 8 | 16 | linear | 3 | 1.151021 |
30 | 0.0 | five_nodes | IT-STGCN | 0.2 | rand | 8 | 24 | nearest | 3 | 1.138263 |
31 | 0.0 | five_nodes | IT-STGCN | 0.2 | rand | 8 | 24 | linear | 3 | 1.129985 |
0 | NaN | asdf | STGCN | 0.2 | rand | 4 | 16 | nearest | 2 | 1.179652 |
0 | NaN | asdf | STGCN | 0.2 | rand | 4 | 24 | nearest | 2 | 1.213393 |
0 | NaN | asdf | STGCN | 0.2 | rand | 4 | 32 | nearest | 2 | 1.216179 |
0 | NaN | asdf | STGCN | 0.2 | rand | 8 | 16 | nearest | 2 | 1.151675 |
0 | NaN | asdf | STGCN | 0.2 | rand | 8 | 24 | nearest | 2 | 1.161763 |
0 | NaN | asdf | STGCN | 0.2 | rand | 8 | 32 | nearest | 2 | 1.170377 |
0 | NaN | asdf | IT-STGCN | 0.2 | rand | 4 | 16 | nearest | 2 | 1.22454 |
0 | NaN | asdf | IT-STGCN | 0.2 | rand | 4 | 24 | nearest | 2 | 1.159922 |
0 | NaN | asdf | IT-STGCN | 0.2 | rand | 4 | 32 | nearest | 2 | 1.171564 |
0 | NaN | asdf | IT-STGCN | 0.2 | rand | 8 | 16 | nearest | 2 | 1.13258 |
0 | NaN | asdf | IT-STGCN | 0.2 | rand | 8 | 24 | nearest | 2 | 1.234006 |
0 | NaN | asdf | IT-STGCN | 0.2 | rand | 8 | 32 | nearest | 2 | 1.175298 |
여기부터 서연이코드
= torch.tensor(data['edges'])
edges_tensor = np.array(data['f'])
fiveVTS = edges_tensor.nonzero()
nonzero_indices = np.array(nonzero_indices).T
fiveNet_edge = 200
T = 5 # number of Nodes
N = fiveNet_edge
E = np.array([1,2,3,4,5])
V = np.arange(0,T)
t = 1
node_features = torch.tensor(E)
edge_index = torch.tensor(np.array([1,1,1,1,1,1,1,1,1,1]),dtype=torch.float32) edge_attr
edge_index
tensor([[0, 0, 1, 1, 2, 2, 3, 3, 3, 4],
[3, 4, 2, 3, 1, 3, 0, 1, 2, 0]])
-
train / test
= fiveVTS[:int(len(fiveVTS)*0.8)]
fiveVTS_train = fiveVTS[int(len(fiveVTS)*0.8):] fiveVTS_test
Random Missing Values
class Missing:
def __init__(self,df):
self.df = df
self.N = N
self.number = []
def miss(self,percent=0.5):
self.missing = self.df.copy()
self.percent = percent
for i in range(self.N):
#self.seed = np.random.choice(1000,1,replace=False)
#np.random.seed(self.seed)
self.number.append(np.random.choice(int(len(self.df))-1,int(len(self.df)*self.percent),replace=False))
self.missing[self.number[i],i] = float('nan')
def first_mean(self):
self.train_mean = self.missing.copy()
for i in range(self.N):
self.train_mean[self.number[i],i] = np.nanmean(self.missing[:,i])
def second_linear(self):
self.train_linear = pd.DataFrame(self.missing)
self.train_linear.interpolate(method='linear', inplace=True)
self.train_linear = self.train_linear.fillna(0)
self.train_linear = np.array(self.train_linear).reshape(int(len(self.df)),N)
= ['Dataset','iteration', 'method', 'missingrate', 'missingtype', 'lag', 'number_of_filters', 'interpolation','MSE_train', 'MSE_test']
col
= [i/10 for i in range(10)] rate
Class code by Method
STGCN
class STGCN_Missing:
def __init__(self,Dataset,df, iterable, Method, Missingrate, Missingtype, lag, Number_of_filters, Interpolation):
self.Dataset = Dataset
self.df = df
self.iterable = iterable
self.Method = Method
self.Missingrate = Missingrate
self.Missingtype = Missingtype
self.lag = lag
self.Number_of_filters = Number_of_filters
self.Interpolation = Interpolation
def iter(self):
self.XX = torch.tensor(fiveVTS_test.reshape(int(T*0.2),N,1)[:-1,:,:]).float()
self.yy = torch.tensor(fiveVTS_test.reshape(int(T*0.2),N,1)[1:,:,:]).float()
self.real_y = torch.tensor(fiveVTS_train).reshape(int(T*0.8),N,1).float()[1:,:,:]
for i in range(self.iterable):
= Missing(fiveVTS_train)
_zero = self.Missingrate)
_zero.miss(percent
_zero.second_linear()
= _zero.number
missing_index = _zero.train_linear
interpolated_signal
= torch.tensor(interpolated_signal).reshape(int(T*0.8),N,1).float()[:int(T*0.8-1),:,:]
X = torch.tensor(interpolated_signal).reshape(int(T*0.8),N,1).float()[1:,:,:]
y
= RecurrentGCN(node_features=self.lag, filters=self.Number_of_filters)
net = torch.optim.Adam(net.parameters(), lr=0.01)
optimizer
net.train()for epoch in range(50):
for time, (xt,yt) in enumerate(zip(X,y)):
= net(xt, edge_index, edge_attr)
yt_hat = torch.mean((yt_hat-yt)**2)
cost
cost.backward()
optimizer.step()
optimizer.zero_grad()
= torch.stack([net(xt, edge_index, edge_attr) for xt in X]).detach().numpy()
yhat = torch.stack([net(xt, edge_index, edge_attr) for xt in self.XX]).detach().numpy()
yyhat
= (((self.real_y-yhat).squeeze())**2).mean()
train_mse_total_stgcn = (((self.yy-yyhat).squeeze())**2).mean()
test_mse_total_stgcn
= pd.DataFrame(columns=col)
df_row 'Dataset'] = self.Dataset,
df_row['iteration'] = i+1, # 1,2,3,...,10
df_row['method'] = self.Method, # 'stgcn','estgcn','gnar'
df_row['missingrate'] = self.Missingrate, # 0.0, 0.2, 0.4, 0.6, 0.8
df_row['missingtype'] = self.Missingtype, # None, 'randomly' and 'block'
df_row['lag'] = self.lag, # 1,2,3,4 ...
df_row['number_of_filters'] = self.Number_of_filters, # 16,24,32, ...
df_row['interpolation'] = self.Interpolation, # None, 'mean', 'linear'
df_row['MSE_train'] = train_mse_total_stgcn.tolist()
df_row['MSE_test'] = test_mse_total_stgcn.tolist()
df_row[
self.df = pd.concat([self.df,df_row])
Enhencement of STGCN
class ESTGCN_Missing:
def __init__(self,Dataset,df, iterable, Method, Missingrate, Missingtype, lag, Number_of_filters, Interpolation):
self.Dataset = Dataset
self.df = df
self.iterable = iterable
self.Method = Method
self.Missingrate = Missingrate
self.Missingtype = Missingtype
self.lag = lag
self.Number_of_filters = Number_of_filters
self.Interpolation = Interpolation
def iter(self):
self.XX = torch.tensor(fiveVTS_test.reshape(int(T*0.2),N,1)[:-1,:,:]).float()
self.yy = torch.tensor(fiveVTS_test.reshape(int(T*0.2),N,1)[1:,:,:]).float()
self.real_y = torch.tensor(fiveVTS_train).reshape(int(T*0.8),N,1).float()[1:,:,:]
for i in range(self.iterable):
= Missing(fiveVTS_train)
_zero = self.Missingrate)
_zero.miss(percent
_zero.second_linear()
= _zero.number
missing_index = _zero.train_linear
interpolated_signal
= torch.tensor(interpolated_signal).reshape(int(T*0.8),N,1).float()[:int(T*0.8-1),:,:]
X = torch.tensor(interpolated_signal).reshape(int(T*0.8),N,1).float()[1:,:,:]
y
= RecurrentGCN(node_features=self.lag, filters=self.Number_of_filters)
net = torch.optim.Adam(net.parameters(), lr=0.01)
optimizer
net.train()= interpolated_signal.copy()
signal for epoch in range(50):
= update_from_freq_domain(signal,missing_index)
signal = torch.tensor(signal).reshape(int(T*0.8),N,1).float()[:int(T*0.8-1),:,:]
X = torch.tensor(signal).reshape(int(T*0.8),N,1).float()[1:,:,:]
y for time, (xt,yt) in enumerate(zip(X,y)):
= net(xt, edge_index, edge_attr)
yt_hat = torch.mean((yt_hat-yt)**2)
cost
cost.backward()
optimizer.step()
optimizer.zero_grad()= torch.concat([X.squeeze(),yt_hat.detach().squeeze().reshape(1,-1)])
signal
= torch.stack([net(xt, edge_index, edge_attr) for xt in X]).detach().numpy()
yhat = torch.stack([net(xt, edge_index, edge_attr) for xt in self.XX]).detach().numpy()
yyhat
= (((self.real_y-yhat).squeeze())**2).mean()
train_mse_total_estgcn = (((self.yy-yyhat).squeeze())**2).mean()
test_mse_total_estgcn
= pd.DataFrame(columns=col)
df_row 'Dataset'] = self.Dataset,
df_row['iteration'] = i+1, # 1,2,3,...,10
df_row['method'] = self.Method, # 'stgcn','estgcn','gnar'
df_row['missingrate'] = self.Missingrate, # 0.0, 0.2, 0.4, 0.6, 0.8
df_row['missingtype'] = self.Missingtype, # None, 'randomly' and 'block'
df_row['lag'] = self.lag, # 1,2,3,4 ...
df_row['number_of_filters'] = self.Number_of_filters, # 16,24,32, ...
df_row['interpolation'] = self.Interpolation, # None, 'mean', 'linear'
df_row['MSE_train'] = train_mse_total_estgcn.tolist()
df_row['MSE_test'] = test_mse_total_estgcn.tolist()
df_row[
self.df = pd.concat([self.df,df_row])
GNAR
= robjects.r.matrix(FloatVector([0,0,0,1,1,0,0,1,1,0,0,1,0,1,0,1,1,1,0,0,1,0,0,0,0]), nrow = 5, ncol = 5) m
class GNAR_Missing:
def __init__(self,Dataset,df, iterable, Method, Missingrate, Missingtype, lag, Number_of_filters, Interpolation):
self.Dataset = Dataset
self.df = df
self.iterable = iterable
self.Method = Method
self.Missingrate = Missingrate
self.Missingtype = Missingtype
self.lag = lag
self.Number_of_filters = Number_of_filters
self.Interpolation = Interpolation
def iter(self):
self.yy = torch.tensor(fiveVTS_test.reshape(int(T*0.2),N,1)[1:,:,:]).float()
for i in range(self.iterable):
= Missing(fiveVTS_train)
_zero = self.Missingrate)
_zero.miss(percent
_zero.second_linear()
= _zero.number
missing_index = _zero.train_linear
interpolated_signal
= torch.tensor(interpolated_signal).reshape(int(T*0.8),N,1).float()[:int(T*0.8-2),:,:]
X
= GNAR.GNARfit(vts=robjects.r.matrix(rpyn.numpy2rpy(np.array(X).squeeze()), nrow = 160, ncol = 5),net = GNAR.matrixtoGNAR(m), alphaOrder = 2, betaOrder = FloatVector([1, 1]))
answer = GNAR.predict_GNARfit(answer,n_ahead=40)
predict
= ((pd.DataFrame(GNAR.residuals_GNARfit(answer)).values.reshape(-1,5))**2).mean()
train_mse_total_gnar = ((self.yy.squeeze() - pd.DataFrame(predict).values.reshape(-1,5)[:-1,:])**2).mean()
test_mse_total_gnar
= pd.DataFrame(columns=col)
df_row 'Dataset'] = self.Dataset,
df_row['iteration'] = i+1, # 1,2,3,...,10
df_row['method'] = self.Method, # 'stgcn','estgcn','gnar'
df_row['missingrate'] = self.Missingrate, # 0.0, 0.2, 0.4, 0.6, 0.8
df_row['missingtype'] = self.Missingtype, # None, 'randomly' and 'block'
df_row['lag'] = self.lag, # 1,2,3,4 ...
df_row['number_of_filters'] = self.Number_of_filters, # 16,24,32, ...
df_row['interpolation'] = self.Interpolation, # None, 'mean', 'linear'
df_row['MSE_train'] = train_mse_total_gnar.tolist()
df_row['MSE_test'] = test_mse_total_gnar.tolist()
df_row[
self.df = pd.concat([self.df,df_row])
STGCN
= 'fivenodes'
Dataset = 'stgcn' # 'stgcn','estgcn','gnar'
Method = 'randomly' # None, 'randomly' and 'block'
Missingtype = 1 # 1,2,3,4 ...
lag = 4 # 16,24,32, ...
Number_of_filters = 'Linear' # None, 'mean', 'linear'
Interpolation = 100 iterable
= pd.DataFrame(columns=col) df_stgcn
for Missingrate in rate:
= pd.DataFrame(columns=col)
df = STGCN_Missing(Dataset,df, iterable,Method, Missingrate, Missingtype, lag, Number_of_filters, Interpolation)
stgcn iter()
stgcn.= stgcn.df.copy()
df_add = pd.concat([df_stgcn,df_add],axis=0) df_stgcn
'./data/GNAR_stgcn_randomly_by_rate.pkl') save_data(df_stgcn,
Enhencement of STGCN
= 'fivenodes'
Dataset = 'estgcn' # 'stgcn','estgcn','gnar'
Method = 'randomly' # None, 'randomly' and 'block'
Missingtype = 1 # 1,2,3,4 ...
lag = 4 # 16,24,32, ...
Number_of_filters = 'Linear' # None, 'mean', 'linear'
Interpolation = 100 iterable
= pd.DataFrame(columns=col) df_estgcn
for Missingrate in rate:
= pd.DataFrame(columns=col)
df = ESTGCN_Missing(Dataset,df, iterable,Method, Missingrate, Missingtype, lag, Number_of_filters, Interpolation)
estgcn iter()
estgcn.= estgcn.df.copy()
df_add = pd.concat([df_estgcn,df_add],axis=0) df_estgcn
'./data/GNAR_estgcn_randomly_by_rate.pkl') save_data(df_estgcn,
GNAR
= 'fivenodes'
Dataset = 'gnar' # 'stgcn','estgcn','gnar'
Method = 'randomly' # None, 'randomly' and 'block'
Missingtype = 1 # 1,2,3,4 ...
lag = None # 16,24,32, ...
Number_of_filters = 'Linear' # None, 'mean', 'linear'
Interpolation = 100 iterable
= pd.DataFrame(columns=col) df_gnar
for Missingrate in rate:
= pd.DataFrame(columns=col)
df = GNAR_Missing(Dataset,df, iterable,Method, Missingrate, Missingtype, lag, Number_of_filters, Interpolation)
gnar iter()
gnar.= gnar.df.copy()
df_add = pd.concat([df_gnar,df_add],axis=0) df_gnar
'./data/GANR_gnar_randomly_by_rate.pkl') save_data(df_gnar,