import numpy as np
import matplotlib.pyplot as plt
Toy Example Note
import pandas as pd
import pickle
= 50
T = np.arange(T)/T * 10 t
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)
import torch
= 50*np.sin(2*t)#+30*np.sin(5*t)
x = np.random.normal(size=T)
eps_x = x.copy()
y for i in range(2,T):
= 0.35*x[i-1] - 0.15*x[i-2] + 50*np.cos(0.5*t[i])
y[i] = np.random.normal(size=T) eps_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
= {'node1':0, 'node2':1}
_node_ids
= np.stack([x,y],axis=1).tolist()
_FX1
= torch.tensor([[1,0]]).tolist()
_edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1 #data_dict = itstgcn.load_data('./data/fivenodes.pkl')
'./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,
+eps_x,y+eps_y],axis=1).shape np.stack([x
(800, 2)
= {'node1':0, 'node2':1} _node_ids
= np.stack([x+eps_x,y+eps_y],axis=1).tolist() _FX
= torch.tensor([[0,0],[0,1],[1,0],[1,1]]).tolist() _edges
= {'edges':_edges, 'node_ids':_node_ids, 'FX':_FX} data_dict
'edges'] data_dict[
[[0, 0], [0, 1], [1, 0], [1, 1]]
'edges']).shape np.array(data_dict[
(4, 2)
'./data/toy_example.pkl') save_data(data_dict,
= load_data('./data/toy_example.pkl') data_dict
data_dict.keys()
dict_keys(['edges', 'node_ids', 'FX'])
'edges'] data_dict[
[[0, 0], [0, 1], [1, 0], [1, 1]]
'node_ids'] data_dict[
{'node1': 0, 'node2': 1}
'FX']).shape np.array(data_dict[
(800, 2)
= pd.DataFrame({'x':x,'y':y,'xer':x+eps_x,'yer':y+eps_y}) data
'./data/toy_example_true.csv') save_data(data,
= load_data('./data/toy_example_true.csv') data
= {'node1':0, 'node2':1} _node_ids
= np.stack([x,y],axis=1).tolist() _FX1
= torch.tensor([[1,0]]).tolist() _edges1
= {'edges':_edges1, 'node_ids':_node_ids, 'FX':_FX1}
data_dict1 #data_dict = itstgcn.load_data('./data/fivenodes.pkl')
'./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,