= 100
T = np.arange(T)/T * 5
t
= 0.1*np.sin(2*t)+0.1*np.sin(4*t)+0.1*np.sin(8*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
y[i] = np.random.normal(size=T)*0
eps_y = x
x = y
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1 = pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y}) df1
Toy Example Figure(Intro)
ITSTGCN
edit
교수님 설정(수정 안 한 것)
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=1) dataset_DCRNN
= [[np.array(list(range(20,35)))],random.sample(range(0, T), int(T*0.5))]
mindex = itstgcn.miss(dataset_DCRNN,mindex,mtype='block') dataset_miss_DCRNN
= itstgcn.padding(dataset_miss_DCRNN,interpolation_method='linear') dataset_padded_DCRNN
= itstgcn.StgcnLearner(dataset_padded_DCRNN) lrnr_DCRNN
=1,epoch=10,lr=0.01,RecurrentGCN='GConvLSTM') lrnr_DCRNN.learn(filters
= Eval_csy(lrnr_DCRNN,dataset_padded_DCRNN) evtor_DCRNN
= itstgcn.ITStgcnLearner(dataset_padded_DCRNN) lrnr_DCRNN2
=1,epoch=10,lr=0.01,RecurrentGCN='GConvLSTM') lrnr_DCRNN2.learn(filters
초기 설정(수정 안 한 것)
= 200
T = np.arange(T)/T * 10
t = 0.1*np.sin(2*t)+0.2*np.sin(4*t)+0.1*np.sin(8*t)+0.2*np.sin(16*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y = np.random.normal(size=T)*0
eps_y = x*0.35
x = y*0.3
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids = np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1],[1,0]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1 = pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y}) df1
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=1) dataset_GConvLSTM
= [random.sample(range(0, T), int(T*0.5)),[np.array(list(range(100,120)))]]
mindex = itstgcn.miss(dataset_GConvLSTM,mindex,mtype='block') dataset_miss_GConvLSTM
= itstgcn.padding(dataset_miss_GConvLSTM,interpolation_method='cubic') dataset_padded_cubic_GConvLSTM
= itstgcn.StgcnLearner(dataset_padded_cubic_GConvLSTM) lrnr_GConvLSTM
=8,epoch=50,RecurrentGCN='GConvLSTM') lrnr_GConvLSTM.learn(filters
import
import itstgcn
import torch
import numpy as np
import matplotlib.pyplot as plt
import random
class Eval_csy:
def __init__(self,learner,train_dataset):
self.learner = learner
# self.learner.model.eval()
try:self.learner.model.eval()
except:pass
self.train_dataset = train_dataset
self.lags = self.learner.lags
= self.learner(self.train_dataset)
rslt_tr 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()
import pickle
import pandas as pd
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)
from plotnine import *
Example
= 500
T = np.arange(T)/T * 5
t
= 1*np.sin(2*t)+np.random.rand(T)+np.sin(4*t)+1*np.sin(8*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
y[i] = np.random.normal(size=T)*0
eps_y = x
x = y
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1
'./data/toy_example1.pkl')
save_data(data_dict1,
= pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y})
data1
'./data/toy_example_true1.csv') save_data(data1,
= np.array(dataset_padded.targets)[:,0] _x
plt.plot(_x) plt.plot(itstgcn.trim(_x))
# T = 100
# t = np.arange(T)/T * 5
# x = 0.01*np.sin(2*t)+0.1*np.sin(4*t)+0.1*np.sin(8*t)
# eps_x = np.random.normal(size=T)*0
# y = x.copy()
# for i in range(2,T):
# y[i] = 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
# eps_y = np.random.normal(size=T)*0
# x = x
# y = y
# plt.plot(t,x,color='C0',lw=5)
# plt.plot(t,x+eps_x,alpha=0.5,color='C0')
# plt.plot(t,y,color='C1',lw=5)
# plt.plot(t,y+eps_y,alpha=0.5,color='C1')
# _node_ids = {'node1':0, 'node2':1}
# _FX1 = np.stack([x+eps_x,y+eps_y],axis=1).tolist()
# _edges1 = torch.tensor([[0,1]]).tolist()
# data_dict1 = {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
# save_data(data_dict1, './data/toy_example1.pkl')
# data1 = pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y})
# save_data(data1, './data/toy_example_true1.csv')
= itstgcn.load_data('./data/toy_example1.pkl')
data_dict1 = itstgcn.DatasetLoader(data_dict1) loader1
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=4) dataset
= [random.sample(range(0, T), int(T*0.9)),[np.array(list(range(20,35)))]]
mindex = itstgcn.miss(dataset,mindex,mtype='block') dataset_miss
# mindex = [[np.array(list(range(181,300)))],[np.array(list(range(20,35)))]]
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='block')
= itstgcn.padding(dataset_miss,interpolation_method='linear') dataset_padded
= itstgcn.StgcnLearner(dataset_padded) lrnr
=16,epoch=5) lrnr.learn(filters
5/5
= Eval_csy(lrnr,dataset_padded) evtor
= itstgcn.ITStgcnLearner(dataset_padded) lrnr_2
=16,epoch=5) lrnr_2.learn(filters
5/5
= Eval_csy(lrnr_2,dataset_padded) evtor_2
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('x'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,0]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[0],'--o',color='C3',alpha=0.8,label='Interpolarion')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[0],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20) ax4.tick_params(axis
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 2)',fontsize=40)
fig.suptitle('y'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1[-1,2)[:,1],'--o',color='C3',label='Observed Data')
ax2.plot(torch.tensor(dataset_miss.targets).reshape(=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[1],'--o',color='C3',alpha=0.8,label='Interpolarion')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[1],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,1],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot((mindex[1][0][0]+mindex[1][0][len(mindex[1][0])-1])/2, 0.1,'s', markersize=110, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20) ax4.tick_params(axis
= itstgcn.load_data('./data/toy_example1.pkl')
data_dict1 = itstgcn.DatasetLoader(data_dict1) loader1
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=4) dataset
= [[np.array(list(range(40,55)))],[np.array(list(range(20,35)))]]
mindex = itstgcn.miss(dataset,mindex,mtype='block') dataset_miss
= itstgcn.padding(dataset_miss,interpolation_method='linear') dataset_padded
= itstgcn.StgcnLearner(dataset_padded) lrnr
=1,epoch=10) lrnr.learn(filters
10/10
= Eval_csy(lrnr,dataset_padded) evtor
= itstgcn.ITStgcnLearner(dataset_padded) lrnr_2
=1,epoch=10) lrnr_2.learn(filters
10/10
= Eval_csy(lrnr_2,dataset_padded) evtor_2
np.array(dataset_miss.features).shape
(96, 2, 4)
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('x'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,0]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[0],'--o',color='C3',alpha=0.8,label='Interpolarion')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[0],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20) ax4.tick_params(axis
시도 1
= 500
T = np.arange(T)/T * 5
t
= np.sin(2*t)+0.5*np.random.rand(T)+np.sin(4*t)+1.5*np.sin(8*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
y[i] = np.random.normal(size=T)*0
eps_y = x
x = y
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1
# save_data(data_dict1, './data/toy_example1.pkl')
= pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y})
data1
# save_data(data1, './data/toy_example_true1.csv')
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=4) dataset
= [random.sample(range(0, T), int(T*0.8)),[np.array(list(range(20,35)))]]
mindex = itstgcn.miss(dataset,mindex,mtype='block') dataset_miss
# mindex = [[np.array(list(range(181,300)))],[np.array(list(range(20,35)))]]
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='block')
= itstgcn.padding(dataset_miss,interpolation_method='linear') dataset_padded
= itstgcn.StgcnLearner(dataset_padded) lrnr
=4,epoch=5) lrnr.learn(filters
5/5
= Eval_csy(lrnr,dataset_padded) evtor
= itstgcn.ITStgcnLearner(dataset_padded) lrnr_2
=4,epoch=5) lrnr_2.learn(filters
5/5
= Eval_csy(lrnr_2,dataset_padded) evtor_2
# with plt.style.context('seaborn-white'):
# fig, ax1 = plt.subplots(figsize=(40,15))
# # fig.suptitle('Figure 1(node 1)',fontsize=40)
# ax1.plot(data1['x'][:],'-',color='C3',label='Complete Data')
# ax1.legend(fontsize=40,loc='lower left',facecolor='white', frameon=True)
# ax1.tick_params(axis='y', labelsize=40)
# ax1.tick_params(axis='x', labelsize=40)
# plt.savefig('node1_fst.png')
# with plt.style.context('seaborn-white'):
# fig, ax2 = plt.subplots(figsize=(40,15))
# # fig.suptitle('Figure 1(node 1)',fontsize=40)
# ax2.plot(data1['x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
# ax2.plot(torch.cat([torch.tensor(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,0]],dim=0),'--o',color='C3',label='Observed Data',markersize=15)
# ax2.legend(fontsize=40,loc='lower left',facecolor='white', frameon=True)
# ax2.tick_params(axis='y', labelsize=40)
# ax2.tick_params(axis='x', labelsize=40)
# plt.savefig('node1_snd.png')
# with plt.style.context('seaborn-white'):
# fig, ax3 = plt.subplots(figsize=(40,15))
# # fig.suptitle('Figure 1(node 1)',fontsize=40)
# ax3.plot(data1['x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
# ax3.plot(evtor_2.f_tr[:,0],'--o',color='C3',alpha=0.8,label='Interpolarion')
# ax3.legend(fontsize=40,loc='lower left',facecolor='white', frameon=True)
# ax3.tick_params(axis='y', labelsize=40)
# ax3.tick_params(axis='x', labelsize=40)
# plt.savefig('node1_3rd.png')
# with plt.style.context('seaborn-white'):
# fig, ax4 = plt.subplots(figsize=(40,15))
# # fig.suptitle('Figure 1(node 1)',fontsize=40)
# ax4.plot(data1['x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
# ax4.plot(evtor.fhat_tr[:,0],color='brown',lw=3,label='STGCN')
# ax4.plot(evtor_2.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
# ax4.plot(138, -1.2, 'o', markersize=230, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(220, -1.5, 'o', markersize=200, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(290, -1.2, 'o', markersize=310, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(455, -0.9, 'o', markersize=280, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.legend(fontsize=40,loc='lower left',facecolor='white', frameon=True)
# ax4.tick_params(axis='y', labelsize=40)
# ax4.tick_params(axis='x', labelsize=40)
# plt.savefig('node1_4th_1.png')
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('x'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,0]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[0],'--o',color='C3',alpha=0.8,label='Interpolarion')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[0],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try2_node1.png')
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 2)',fontsize=40)
fig.suptitle('y'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,1]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[1],'--o',color='C3',alpha=0.8,label='Interpolarion')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[1],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,1],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try2_node2.png')
시도 2
= 500
T = np.arange(T)/T * 5
t
= 1*np.sin(2*t)+0.4*np.random.rand(T)+np.sin(4*t)+1.3*np.sin(8*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
y[i] = np.random.normal(size=T)*0
eps_y = x
x = y
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1
# save_data(data_dict1, './data/toy_example1.pkl')
= pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y})
data1
# save_data(data1, './data/toy_example_true1.csv')
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=4) dataset
= [random.sample(range(0, T), int(T*0.8)),[np.array(list(range(20,35)))]]
mindex = itstgcn.miss(dataset,mindex,mtype='block') dataset_miss
# mindex = [[np.array(list(range(181,300)))],[np.array(list(range(20,35)))]]
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='block')
= itstgcn.padding(dataset_miss,interpolation_method='linear') dataset_padded
= itstgcn.StgcnLearner(dataset_padded) lrnr
=8,epoch=5) lrnr.learn(filters
5/5
= Eval_csy(lrnr,dataset_padded) evtor
= itstgcn.ITStgcnLearner(dataset_padded) lrnr_2
=8,epoch=5) lrnr_2.learn(filters
5/5
= Eval_csy(lrnr_2,dataset_padded) evtor_2
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('x'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,0]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[0],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[0],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try1_node1.png')
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('y'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,1]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[1],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[1],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,1],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try1_node2.png')
시도 3
= 500
T = np.arange(T)/T * 5
t
= 1*np.sin(2*t)+0.3*np.random.rand(T)+np.sin(4*t)+1.5*np.sin(8*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
y[i] = np.random.normal(size=T)*0
eps_y = x
x = y
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1
'./data/toy_example1.pkl')
save_data(data_dict1,
= pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y})
data1
'./data/toy_example_true1.csv') save_data(data1,
= itstgcn.load_data('./data/fivenodes.pkl')
_data_dict = itstgcn.DatasetLoader(_data_dict) _loader
= _loader.get_dataset(lags=2) _dataset
= [random.sample(range(0, 200), int(200*0.8)),[np.array(list(range(40,100)))]]
mindex = itstgcn.miss(_dataset,mindex,mtype='block') _dataset_miss
# mindex = itstgcn.rand_mindex(dataset,mrate=0.8)
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='rand')
# mindex = [[np.array(list(range(181,300)))],[np.array(list(range(20,35)))]]
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='block')
= itstgcn.padding(_dataset_miss,interpolation_method='linear') _dataset_padded
= itstgcn.StgcnLearner(_dataset_padded) _lrnr
=12,epoch=10) _lrnr.learn(filters
10/10
= Eval_csy(_lrnr,_dataset_padded) _evtor
= itstgcn.ITStgcnLearner(_dataset_padded) _lrnr_2
=12,epoch=10) _lrnr_2.learn(filters
10/10
= Eval_csy(_lrnr_2,_dataset_padded) _evtor_2
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('x'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
0,0],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(torch.tensor(_dataset.features)[:,2,0,0],torch.tensor(_dataset_miss.targets).reshape(-1,5)[:,0]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(_dataset.features)[:=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
0,0],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(torch.tensor(_dataset.features)[:,0],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(_evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
0,0],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(torch.tensor(_dataset.features)[:,0],color='brown',lw=3,label='STGCN')
ax4.plot(_evtor.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
ax4.plot(_evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try2_node1.png')
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 2)',fontsize=40)
fig.suptitle(1,0],'-',color='C3',label='Complete Data')
ax1.plot(torch.tensor(_dataset.features)[:,=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
1,0],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(torch.tensor(_dataset.features)[:,2,1,0],torch.tensor(_dataset_miss.targets).reshape(-1,5)[:,1]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(_dataset.features)[:=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
1,0],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(torch.tensor(_dataset.features)[:,1],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(_evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
1,0],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(torch.tensor(_dataset.features)[:,1],color='brown',lw=3,label='STGCN')
ax4.plot(_evtor.fhat_tr[:,1],color='blue',lw=3,label='ITSTGCN')
ax4.plot(_evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try2_node2.png')
시도 4 noise 0
= 500
T = np.arange(T)/T * 5
t
= 1*np.sin(2*t)+np.sin(4*t)+1.2*np.sin(8*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
y[i] = np.random.normal(size=T)*0
eps_y = x
x = y
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1
# save_data(data_dict1, './data/toy_example1.pkl')
= pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y})
data1
# save_data(data1, './data/toy_example_true1.csv')
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=4) dataset
= [random.sample(range(0, T), int(T*0.5)),[np.array(list(range(50,95)))]]
mindex = itstgcn.miss(dataset,mindex,mtype='block') dataset_miss
# mindex = [[np.array(list(range(181,300)))],[np.array(list(range(20,35)))]]
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='block')
= itstgcn.padding(dataset_miss,interpolation_method='linear') dataset_padded
= itstgcn.StgcnLearner(dataset_padded) lrnr
=16,epoch=5) lrnr.learn(filters
5/5
= Eval_csy(lrnr,dataset_padded) evtor
= itstgcn.ITStgcnLearner(dataset_padded) lrnr_2
=16,epoch=5) lrnr_2.learn(filters
5/5
= Eval_csy(lrnr_2,dataset_padded) evtor_2
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('x'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,0]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[0],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[0],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(135, -1.5, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(220, -1.5, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(290, -1.8, 'o', markersize=120, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(450, -1.5, 'o', markersize=120, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try2_node1_2.png')
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 2)',fontsize=40)
fig.suptitle('y'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,1]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[1],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[1],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,1],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(75, 0.75, 'o', markersize=150, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try2_node2_2.png')
시도 5 noise 10%
= 500
T = np.arange(T)/T * 5
t
= 1.5*np.sin(2*t)+0.1*np.random.rand(T)+np.sin(4*t)+1.5*np.sin(8*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
y[i] = np.random.normal(size=T)*0
eps_y = x
x = y
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1
# save_data(data_dict1, './data/toy_example1.pkl')
= pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y})
data1
# save_data(data1, './data/toy_example_true1.csv')
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=4) dataset
= [random.sample(range(0, T), int(T*0.8)),[np.array(list(range(20,35)))]]
mindex = itstgcn.miss(dataset,mindex,mtype='block') dataset_miss
# mindex = [[np.array(list(range(181,300)))],[np.array(list(range(20,35)))]]
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='block')
= itstgcn.padding(dataset_miss,interpolation_method='linear') dataset_padded
= itstgcn.StgcnLearner(dataset_padded) lrnr
=8,epoch=5) lrnr.learn(filters
5/5
= Eval_csy(lrnr,dataset_padded) evtor
= itstgcn.ITStgcnLearner(dataset_padded) lrnr_2
=8,epoch=5) lrnr_2.learn(filters
5/5
= Eval_csy(lrnr_2,dataset_padded) evtor_2
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('x'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,0]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[0],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[0],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try3_node1_noise10.png')
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('y'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,1]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[1],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[1],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,1],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try3_node2_noise10.png')
시도 6 noise 20%
= 500
T = np.arange(T)/T * 5
t
= 1.5*np.sin(2*t)+0.2*np.random.rand(T)+np.sin(4*t)+1.5*np.sin(8*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
y[i] = np.random.normal(size=T)*0
eps_y = x
x = y
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1
# save_data(data_dict1, './data/toy_example1.pkl')
= pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y})
data1
# save_data(data1, './data/toy_example_true1.csv')
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=4) dataset
= [random.sample(range(0, T), int(T*0.75)),[np.array(list(range(20,35)))]]
mindex = itstgcn.miss(dataset,mindex,mtype='block') dataset_miss
# mindex = [[np.array(list(range(181,300)))],[np.array(list(range(20,35)))]]
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='block')
= itstgcn.padding(dataset_miss,interpolation_method='linear') dataset_padded
= itstgcn.StgcnLearner(dataset_padded) lrnr
=8,epoch=5) lrnr.learn(filters
5/5
= Eval_csy(lrnr,dataset_padded) evtor
= itstgcn.ITStgcnLearner(dataset_padded) lrnr_2
=8,epoch=5) lrnr_2.learn(filters
5/5
= Eval_csy(lrnr_2,dataset_padded) evtor_2
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('x'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,0]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[0],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[0],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try4_node1_noise20.png')
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('y'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,1]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[1],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[1],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,1],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try2_node2_noise20.png')
시도 7 noise 30%
= 500
T = np.arange(T)/T * 5
t
= 1.5*np.sin(2*t)+0.3*np.random.rand(T)+np.sin(4*t)+1.5*np.sin(8*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
y[i] = np.random.normal(size=T)*0
eps_y = x
x = y
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1
# save_data(data_dict1, './data/toy_example1.pkl')
= pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y})
data1
# save_data(data1, './data/toy_example_true1.csv')
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=4) dataset
= [random.sample(range(0, T), int(T*0.75)),[np.array(list(range(20,35)))]]
mindex = itstgcn.miss(dataset,mindex,mtype='block') dataset_miss
# mindex = [[np.array(list(range(181,300)))],[np.array(list(range(20,35)))]]
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='block')
= itstgcn.padding(dataset_miss,interpolation_method='linear') dataset_padded
= itstgcn.StgcnLearner(dataset_padded) lrnr
=8,epoch=5) lrnr.learn(filters
5/5
= Eval_csy(lrnr,dataset_padded) evtor
= itstgcn.ITStgcnLearner(dataset_padded) lrnr_2
=8,epoch=5) lrnr_2.learn(filters
5/5
= Eval_csy(lrnr_2,dataset_padded) evtor_2
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('x'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,0]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[0],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[0],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try5_node1_noise30.png')
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('y'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,1]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[1],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[1],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,1],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try5_node2_noise20.png')
시도 8 noise 30% only random
= 500
T = np.arange(T)/T * 5
t
= 1*np.sin(2*t)+0.3*np.random.rand(T)+np.sin(4*t)+1.5*np.sin(8*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
y[i] = np.random.normal(size=T)*0
eps_y = x
x = y
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1
'./data/toy_example1.pkl')
save_data(data_dict1,
= pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y})
data1
'./data/toy_example_true1.csv') save_data(data1,
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=4) dataset
# mindex = [random.sample(range(0, T), int(T*0.7)),[np.array(list(range(20,35)))]]
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='block')
= itstgcn.rand_mindex(dataset,mrate=0.75)
mindex = itstgcn.miss(dataset,mindex,mtype='rand') dataset_miss
# mindex = [[np.array(list(range(181,300)))],[np.array(list(range(20,35)))]]
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='block')
= itstgcn.padding(dataset_miss,interpolation_method='linear') dataset_padded
= itstgcn.StgcnLearner(dataset_padded) lrnr
=8,epoch=5) lrnr.learn(filters
5/5
= Eval_csy(lrnr,dataset_padded) evtor
= itstgcn.ITStgcnLearner(dataset_padded) lrnr_2
=8,epoch=5) lrnr_2.learn(filters
5/5
= Eval_csy(lrnr_2,dataset_padded) evtor_2
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('x'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,0]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[0],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[0],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try2_node1.png')
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 2)',fontsize=40)
fig.suptitle('y'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,1]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[1],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[1],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,1],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try2_node2.png')
시도 9 noise 40%
= 500
T = np.arange(T)/T * 5
t
= 1.5*np.sin(2*t)+0.4*np.random.rand(T)+np.sin(4*t)+1.5*np.sin(8*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
y[i] = np.random.normal(size=T)*0
eps_y = x
x = y
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1
# save_data(data_dict1, './data/toy_example1.pkl')
= pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y})
data1
# save_data(data1, './data/toy_example_true1.csv')
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=4) dataset
= [[np.array(list(range(40,85)))],random.sample(range(0, T), int(T*0.7))]
mindex = itstgcn.miss(dataset,mindex,mtype='block') dataset_miss
# mindex = [[np.array(list(range(181,300)))],[np.array(list(range(20,35)))]]
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='block')
= itstgcn.padding(dataset_miss,interpolation_method='linear') dataset_padded
= itstgcn.StgcnLearner(dataset_padded) lrnr
=32,epoch=5) lrnr.learn(filters
5/5
= Eval_csy(lrnr,dataset_padded) evtor
= itstgcn.ITStgcnLearner(dataset_padded) lrnr_2
=32,epoch=5) lrnr_2.learn(filters
5/5
= Eval_csy(lrnr_2,dataset_padded) evtor_2
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('x'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,0]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[0],'--o',color='C3',alpha=0.8,label='Interpolation')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[0],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try6_node1_noise40.png')
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('y'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,1]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[1],'--o',color='C3',alpha=0.8,label='Interpolarion')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[1],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,1],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try6_node2_noise40.png')
시도 10 noise 50%
= 500
T = np.arange(T)/T * 5
t
= 1.5*np.sin(2*t)+0.1*np.random.rand(T)+np.sin(4*t)+1.5*np.sin(8*t)
x = np.random.normal(size=T)*0
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 0.5*np.cos(0.4*t[i])
y[i] = np.random.normal(size=T)*0
eps_y = x
x = y
y ='C0',lw=5)
plt.plot(t,x,color+eps_x,alpha=0.5,color='C0')
plt.plot(t,x='C1',lw=5)
plt.plot(t,y,color+eps_y,alpha=0.5,color='C1')
plt.plot(t,y= {'node1':0, 'node2':1}
_node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist()
_FX1
= torch.tensor([[0,1]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1
# save_data(data_dict1, './data/toy_example1.pkl')
= pd.DataFrame({'x':x,'y':y,'xer':x,'yer':y})
data1
# save_data(data1, './data/toy_example_true1.csv')
= itstgcn.DatasetLoader(data_dict1) loader1
= loader1.get_dataset(lags=4) dataset
= [random.sample(range(0, T), int(T*0.7)),[np.array(list(range(40,85)))]]
mindex = itstgcn.miss(dataset,mindex,mtype='block') dataset_miss
# mindex = [[np.array(list(range(181,300)))],[np.array(list(range(20,35)))]]
# dataset_miss = itstgcn.miss(dataset,mindex,mtype='block')
= itstgcn.padding(dataset_miss,interpolation_method='linear') dataset_padded
= itstgcn.StgcnLearner(dataset_padded) lrnr
=12,epoch=5) lrnr.learn(filters
5/5
= Eval_csy(lrnr,dataset_padded) evtor
= itstgcn.ITStgcnLearner(dataset_padded) lrnr_2
=12,epoch=5) lrnr_2.learn(filters
5/5
= Eval_csy(lrnr_2,dataset_padded) evtor_2
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('x'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,0]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[0],'--o',color='C3',alpha=0.8,label='Interpolarion')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'x'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[0],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,0],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try6_node1_noise40.png')
with plt.style.context('seaborn-white'):
# plt.rcParams['font.family'] = 'xkcd'
# plt.xkcd(scale=0,length=200)
= plt.subplots(2, 2,figsize=(40,15))
fig, ((ax1, ax2), (ax3, ax4)) 'Figure 1(node 1)',fontsize=40)
fig.suptitle('y'][:],'-',color='C3',label='Complete Data')
ax1.plot(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax1.legend(fontsize='y', labelsize=20)
ax1.tick_params(axis='x', labelsize=20)
ax1.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax2.plot(data1['x'][:4]),torch.tensor(dataset_miss.targets).reshape(-1,2)[:,1]],dim=0),'--o',color='C3',label='Observed Data')
ax2.plot(torch.cat([torch.tensor(data1[=20,loc='lower left',facecolor='white', frameon=True)
ax2.legend(fontsize='y', labelsize=20)
ax2.tick_params(axis='x', labelsize=20)
ax2.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax3.plot(data1[1],'--o',color='C3',alpha=0.8,label='Interpolarion')
ax3.plot(evtor_2.f_tr[:,=20,loc='lower left',facecolor='white', frameon=True)
ax3.legend(fontsize='y', labelsize=20)
ax3.tick_params(axis='x', labelsize=20)
ax3.tick_params(axis
'y'][:],'--',color='C5',alpha=0.5,label='Complete Data')
ax4.plot(data1[1],color='brown',lw=3,label='STGCN')
ax4.plot(evtor.fhat_tr[:,1],color='blue',lw=3,label='ITSTGCN')
ax4.plot(evtor_2.fhat_tr[:,# ax4.plot(55, 0, 'o', markersize=100, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(150, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
# ax4.plot(185, 0, 'o', markersize=80, markerfacecolor='none', markeredgecolor='red',markeredgewidth=3)
=20,loc='lower left',facecolor='white', frameon=True)
ax4.legend(fontsize='y', labelsize=20)
ax4.tick_params(axis='x', labelsize=20)
ax4.tick_params(axis# plt.savefig('try6_node2_noise40.png')