-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel_learning_preprocessing.py
More file actions
137 lines (124 loc) · 3.94 KB
/
model_learning_preprocessing.py
File metadata and controls
137 lines (124 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import pickle
from sklearn.preprocessing import StandardScaler
# logfile_ip = "./Results/blocks_exp_raw_data_rs_1.p"
# logfile_ip = "./Results/blocks_exp_raw_data_rs_1_mm.p" # small data exp
# logfile_ip = "./Results/blocks_exp_raw_data_rs_1_mm_bigdata.p"
logfile_ip = "./Results/Final/blocks_exp_raw_data_rs_1_mm_d40.p"
# logfile_ip = "./Results/Final/blocks_exp_raw_data_rs_1_mm_d15.p"
# logfile_ip = "./Results/Final/blocks_exp_raw_data_rs_1_mm_d15_1.p"
# logfile_ip = "./Results/yumi_exp_preprocessed_data_1.dat"
# logfile_op = "./Results/blocks_exp_preprocessed_data_rs_1.p"
# logfile_op = "./Results/blocks_exp_preprocessed_data_rs_1_gpy.p"
# logfile_op = "./Results/blocks_exp_preprocessed_data_rs_1_mm.p" # small data exp
# logfile_op = "./Results/blocks_exp_preprocessed_data_rs_1_mm_bigdata.p"
# logfile_op = "./Results/blocks_exp_preprocessed_data_rs_1_mm_smalldata.p"
logfile_op = "./Results/Final/blocks_exp_preprocessed_data_rs_1_mm_d40_1.p"
# logfile_op = "./Results/Final/blocks_exp_preprocessed_data_rs_1_mm_d15_1.p"
# logfile_op = "./Results/blocks_exp_preprocessed_data_rs_1_gpflow.p"
exp_data = pickle.load(open(logfile_ip, "rb"))
exp_params = exp_data['exp_params']
Xs = exp_data['X'] # state
Us = exp_data['U'] # action
Xg = exp_data['Xg'] # sate ground truth
Ug = exp_data['Ug'] # action ground truth
dP = exp_params['dP']
dV = exp_params['dV']
dU = exp_params['dU']
dX = dP+dV
T = exp_params['T']
dt = exp_params['dt']
N = exp_params['num_samples']
n_trials, n_time_steps, dim_state = Xs.shape
_, _, dim_action = Us.shape
assert(dX==dim_state)
assert(n_time_steps==T)
assert(dU==dim_action)
# n_train = n_trials//3 * 2
n_train = 15
# n_train = 40
# n_test = n_trials - n_train
n_test = 10
plt.figure()
plt.title('Position')
plt.xlabel('t')
plt.ylabel('q(t)')
tm = np.linspace(0,T*dt,T)
# plot positions
plt.plot(tm, Xg[:,:dP], ls='-', marker='^')
for s in range(n_train):
plt.plot(tm,Xs[s,:,0])
plt.figure()
plt.xlabel('t')
plt.ylabel('q_dot(t)')
plt.title('Velocity')
plt.plot(tm, Xg[:,dP:dP+dV], ls='-', marker='^')
# plot velocities
for s in range(n_train):
plt.plot(tm,Xs[s,:,1])
plt.figure()
plt.xlabel('t')
plt.ylabel('u(t)')
plt.title('Action')
plt.plot(tm, Ug, ls='-', marker='^')
# plot actions
for s in range(n_train):
plt.plot(tm,Us[s,:,0])
plt.show(block=False)
plt.figure()
plt.title('Position')
plt.xlabel('t')
plt.ylabel('q(t)')
tm = np.linspace(0,T*dt,T)
# plot positions
plt.plot(tm, Xg[:,:dP], ls='-', marker='^')
for s in range(n_train, n_train+n_test):
plt.plot(tm,Xs[s,:,0])
plt.figure()
plt.xlabel('t')
plt.ylabel('q_dot(t)')
plt.title('Velocity')
plt.plot(tm, Xg[:,dP:dP+dV], ls='-', marker='^')
# plot velocities
for s in range(n_train, n_train+n_test):
plt.plot(tm,Xs[s,:,1])
plt.figure()
plt.xlabel('t')
plt.ylabel('u(t)')
plt.title('Action')
plt.plot(tm, Ug, ls='-', marker='^')
# plot actions
for s in range(n_train, n_train+n_test):
plt.plot(tm,Us[s,:,0])
plt.show(block=False)
exp_data['n_train'] = n_train
exp_data['n_test'] = n_test
XUs = np.concatenate((Xs, Us), axis=2)
XUs_train = XUs[:n_train, :, :]
XUs_t_train = XUs_train[:,:-1,:]
exp_data['XUs_t_train'] = XUs_t_train
Xs_t_train = XUs_train[:,:-1,:dX]
exp_data['Xs_t_train'] = Xs_t_train
Xs_t1_train = XUs_train[:,1:,:dX]
exp_data['Xs_t1_train'] = Xs_t1_train
XUs_test = XUs[n_train:n_train + n_test, :, :]
# only for small data
fil = [False]*n_test
fil[0] = fil[1] = fil[2] = fil[9] = fil[8] = True # for d40
# fil[0] = fil[2] = fil[5] = fil[8] = fil[9] = True # for d15
XUs_test = XUs_test[fil]
XUs_t_test = XUs_test[:,:-1,:]
exp_data['XUs_t_test'] = XUs_t_test
Xs_t1_test = XUs_test[:,1:,:dX]
exp_data['Xs_t1_test'] = Xs_t1_test
Xs_t_test = XUs_test[:,:-1,:dX]
exp_data['Xs_t_test'] = Xs_t_test
X0s = XUs_train[:, 0, :dX]
X0_mu = np.mean(X0s, axis=0)
exp_data['X0_mu'] = X0_mu
X0_var = np.var(X0s, axis=0)
exp_data['X0_var'] = X0_var
pickle.dump(exp_data, open(logfile_op, "wb"))
None