20
20
sigma = cp_models .get ('filter' , 'sigma' )
21
21
ipromps_set = joblib .load (os .path .join (datasets_path , 'pkl/ipromps_set.pkl' ))
22
22
datasets_raw = joblib .load (os .path .join (datasets_path , 'pkl/datasets_raw.pkl' ))
23
- test_index = cp_models .getint ('visualization' , 'test_index' )
24
-
25
23
26
24
# read datasets cfg file
27
25
cp_datasets = ConfigParser .SafeConfigParser ()
28
26
cp_datasets .read (os .path .join (datasets_path , './info/cfg/datasets.cfg' ))
27
+
29
28
# read datasets params
30
29
data_index_sec = cp_datasets .items ('index_17' )
31
- # data_index_sec = cp_datasets.items('index_25')
32
30
data_index = [map (int , task [1 ].split (',' )) for task in data_index_sec ]
33
31
34
32
35
33
def main ():
36
- task_id = 0
37
- test_index = 37
38
- obs_ratio = 0.35
34
+ # super param
35
+ task_id = 1
36
+ test_index = 1
37
+ obs_ratio = 0.5
39
38
40
- # read test data
39
+ # load test data
41
40
obs_data_dict = datasets_raw [task_id ][test_index ]
42
-
43
41
left_hand = obs_data_dict ['left_hand' ]
44
42
left_joints = obs_data_dict ['left_joints' ]
45
43
obs_data = np .hstack ([left_hand , left_joints ])
46
44
timestamp = obs_data_dict ['stamp' ]
47
45
48
- # filter the data
46
+ # filter data and preprocessing data
49
47
obs_data = gaussian_filter1d (obs_data .T , sigma = sigma ).T
50
- # preprocessing for the data
51
- obs_data_post_arr = ipromps_set [0 ].min_max_scaler .transform (obs_data )
52
- # consider the unobserved info
53
- obs_data_post_arr [:, - 7 :] = 0.0
48
+ obs_data_preproc = ipromps_set [0 ].min_max_scaler .transform (obs_data )
49
+ # set unobserved info
50
+ obs_data_preproc [:, - 7 :] = 0.0
54
51
55
52
# choose the data
56
53
num_obs = int (len (timestamp )* obs_ratio )
57
- num_obs = num_obs - num_obs % 15
58
- obs_data_post_arr = obs_data_post_arr [0 :num_obs :15 , :]
54
+ num_obs - = num_obs % 15
55
+ obs_data_preproc = obs_data_preproc [0 :num_obs :15 , :]
59
56
timestamp = timestamp [0 :num_obs :15 ]
60
57
61
58
# phase estimation
62
59
print ('Phase estimating...' )
63
60
alpha_max_list = []
64
61
for ipromp in ipromps_set :
65
62
alpha_temp = ipromp .alpha_candidate (num_alpha_candidate )
66
- idx_max = ipromp .estimate_alpha (alpha_temp , obs_data_post_arr , timestamp )
63
+ idx_max = ipromp .estimate_alpha (alpha_temp , obs_data_preproc , timestamp )
67
64
alpha_max_list .append (alpha_temp [idx_max ]['candidate' ])
68
65
ipromp .set_alpha (alpha_temp [idx_max ]['candidate' ])
69
66
70
67
# task recognition
71
68
print ('Adding via points in each trained model...' )
72
69
for task_idx , ipromp in enumerate (ipromps_set ):
73
70
for idx in range (len (timestamp )):
74
- ipromp .add_viapoint (timestamp [idx ] / alpha_max_list [task_idx ], obs_data_post_arr [idx , :])
71
+ ipromp .add_viapoint (timestamp [idx ] / alpha_max_list [task_idx ], obs_data_preproc [idx , :])
75
72
ipromp .param_update (unit_update = True )
76
73
print ('Computing the likelihood for each model under observations...' )
77
74
@@ -83,25 +80,15 @@ def main():
83
80
# idx_max_prob = 0 # a trick for testing
84
81
print ('The max fit model index is task %s' % task_name [idx_max_prob ])
85
82
86
- # # robot motion generation
87
- # [traj_time, traj] = ipromps_set[idx_max_prob].gen_real_traj(alpha_max_list[idx_max_prob])
88
- # traj = ipromps_set[idx_max_prob].min_max_scaler.inverse_transform(traj)
89
- # robot_traj = traj[:, -3:]
90
-
91
83
# robot motion generation
92
84
traj_full = []
93
85
for ipromp_id , ipromp in enumerate (ipromps_set ):
94
86
[traj_time , traj ] = ipromp .gen_real_traj (alpha_max_list [ipromp_id ])
95
87
traj = ipromp .min_max_scaler .inverse_transform (traj )
96
88
robot_traj = traj [:, - 7 :]
97
- human_traj = traj [:, 0 :- 7 ]
89
+ human_traj = traj [:, 0 :3 ]
98
90
traj_full .append ([human_traj , robot_traj ])
99
91
100
- # # test: robot motion generation for task2
101
- # [traj_time2, traj2] = ipromps_set[2].gen_real_traj(alpha_max_list[2])
102
- # traj2 = ipromps_set[2].min_max_scaler.inverse_transform(traj2)
103
- # robot_traj2 = traj2[:, -3:]
104
-
105
92
# save the conditional result
106
93
print ('Saving the post IProMPs...' )
107
94
joblib .dump (ipromps_set , os .path .join (datasets_path , 'pkl/ipromps_set_post_offline.pkl' ))
@@ -112,4 +99,3 @@ def main():
112
99
113
100
if __name__ == '__main__' :
114
101
main ()
115
- # visualization.main()
0 commit comments