-
Notifications
You must be signed in to change notification settings - Fork 1
/
2d_initpt_example_prcess.py
78 lines (66 loc) · 2.44 KB
/
2d_initpt_example_prcess.py
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
import mlfd
import numpy as np
import h5py
import ja
import lte
import sys
# insert at 1, 0 is the script path (or '' in REPL)
sys.path.insert(1, './dmp_pastor_2009/')
import perform_dmp as dmp
import similaritymeasures
import os
def get_lasa_traj1(shape_name):
#ask user for the file which the playback is for
#filename = raw_input('Enter the filename of the .h5 demo: ')
#open the file
filename = '../data/lasa_dataset.h5'
hf = h5py.File(filename, 'r')
#navigate to necessary data and store in numpy arrays
shape = hf.get(shape_name)
demo = shape.get('demo1')
pos_info = demo.get('pos')
pos_data = np.array(pos_info)
y_data = np.delete(pos_data, 0, 1)
x_data = np.delete(pos_data, 1, 1)
#close out file
hf.close()
return [x_data, y_data]
def main():
## set up demonstration
lasa_name = 'Saeghe'
plt_fpath = '../example_outputs/2d_initpt_example/'
try:
os.makedirs(plt_fpath)
except OSError:
print ("Creation of the directory %s failed" % plt_fpath)
else:
print ("Successfully created the directory %s" % plt_fpath)
[x, y] = get_lasa_traj1(lasa_name)
traj = np.hstack((x, y))
## set up SAMLfD Object
my_mlfd = mlfd.SAMLfD()
my_mlfd.add_traj(traj)
my_mlfd.add_representation(ja.perform_ja_general, 'JA')
my_mlfd.add_representation(lte.LTE_ND_any_constraints, 'LTE')
my_mlfd.add_representation(dmp.perform_dmp_general, 'DMP')
my_mlfd.add_metric(similaritymeasures.frechet_dist, is_dissim=True)
my_mlfd.plot_org_traj(mode='show', filepath=plt_fpath)
## create meshgrid
my_mlfd.create_grid(plot=True) #use default values for grid creation (defaults include initial point deformation)
## deform at each point on grid
my_mlfd.deform_traj(plot=True)
## calculate similarities of deformations
my_mlfd.calc_similarities()
my_mlfd.plot_heatmap(mode='show', filepath=plt_fpath)
## save/load results
my_mlfd.save_to_h5(plt_fpath + 'mlfd_' + lasa_name + '.h5')
#my_mlfd.load_from_h5(plt_fpath + 'mlfd_' + lasa_name + '.h5')
## set up classifier
my_mlfd.get_strongest_sims(0.1)
my_mlfd.set_up_classifier()
## get similarity region & reproductions
my_mlfd.plot_classifier_results(mode='show', filepath=plt_fpath)
my_mlfd.plot_contour2D(mode='show', filepath=plt_fpath)
my_mlfd.reproduction_point_selection2D()
if __name__ == '__main__':
main()