forked from sjyk/python-segmentation-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
188 lines (155 loc) · 6.44 KB
/
main.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import numpy as np
np.seterr(divide='ignore') # these warnings are usually harmless for this code
from matplotlib import pyplot as plt
import copy, os
from generate.TrajectoryDataGenerator import *
from tsc.tsc import TransitionStateClustering
from alternates.clustering import TimeVaryingGaussianMixtureModel, HMMGaussianMixtureModel, CoresetSegmentation
from alternates.bayes import HiddenSemiMarkovModel, AutoregressiveMarkovModel
from alternates.em import EMForwardBackward
from evaluation.Evaluator import *
from evaluation.Metrics import *
#creates a system whose regimes are uniformly sampled from the stochastic params
"""
sys = createNewDemonstrationSystem(k=3,dims=2, observation=[0.1,0.1], resonance=[0.0,0.0], drift=[0.0,0.0])
t = sampleDemonstrationFromSystem(sys,np.ones((2,1)),lm=0.0, dp=0.0)
t2 = sampleDemonstrationFromSystem(sys,np.ones((2,1)),lm=0.0, dp=0.0)
t3 = sampleDemonstrationFromSystem(sys,np.ones((2,1)),lm=0.0, dp=0.0)
a.addDemonstration(t[0])
a.addDemonstration(t2[0])
a.addDemonstration(t3[0])
a.fit()
print a.segmentation
"""
sys_params = {'k':3,'dims':2, 'observation':[0.0,0.1], 'resonance':[0.0,0.0], 'drift':[0,0.0]}
a = TransitionStateClustering(window_size=3, normalize=False, pruning=0.3,delta=-1)
#b = TimeVaryingGaussianMixtureModel(hard_param=3)
#c = HMMGaussianMixtureModel(n_components=3)
#d = CoresetSegmentation(n_components=4)
b = EMForwardBackward(n_components=3)
#f = AutoregressiveMarkovModel()
"""
plotY1Y2(run_sweep_experiment(sys_params, 'observation', [0.1, 0.25, 0.5, 0.75, 1], [a, b], np.ones((2,1)), lambda x,y: evaluate(x,y,'jaccard', thresh=0.75), N=10, k=10),
"(A) HF Observation Noise",
"HF Noise",
"Segment Accuracy",
legend=["GMM-TSC", "EM-TSC"],
loc = 'lower left',
filename="output1.png",
ylim=0.0,
xlim=0.1)
"""
plotY1Y2(run_sweep_experiment(sys_params, 'resonance', [0.1, 0.5, 1.0, 1.5, 2], [a, b], np.ones((2,1)), lambda x,y: evaluate(x,y,'jaccard', thresh=0.75), N=10, k=10),
"(B) LF Observation Noise",
"LF Noise",
"Segment Accuracy",
legend=["GMM-TSC", "EM-TSC"],
loc = 'lower left',
filename="output2.png",
ylim=0.0,
xlim=0.1)
"""
plotY1Y2(run_sweep_experiment(sys_params, 'resonance', [0.1, 0.25, 0.5, 0.75, 1], [a,b,c,d,e,f], np.ones((2,1)), lambda x,y: evaluate(x,y,'seg_acc', thresh=0.75), N=2, k=10),
"(B) LF Process Noise",
"LF Noise",
"Segment Accuracy",
legend=["TSC", "GMM", "GMM+HMM", "Coreset", "HSMM", "ARHMM"],
loc = 'lower left',
filename="output2.png",
ylim=0.0,
xlim=0.1)
"""
"""
plotY1Y2(run_sweep_experiment(sys_params, 'observation', [0.1, 0.2, 0.3, 0.4, 0.5, 0.75, 1], [a,b,c,d,e,f], np.ones((2,1)), lambda x,y: evaluate(x,y,'frame_acc'), N=2, k=10),
"(B) HF Observation Noise",
"HF Noise",
"Frame Accuracy",
legend=["TSC", "GMM", "GMM+HMM", "Coreset", "HSMM", "ARHMM"],
loc = 'lower left',
filename="output1b.png",
ylim=0.0,
xlim=0.1)
"""
"""
plotY1Y2(run_sweep_experiment(sys_params, 'resonance', [0.1, 0.2, 0.3, 0.4, 0.5, 0.75, 1], [a,b,c,d,e,f], np.ones((2,1)), lambda x,y: evaluate(x,y,'frame_acc'), N=2, k=10),
"(D) LF Process Noise",
"LF Noise",
"Frame Accuracy",
legend=["TSC", "GMM", "GMM+HMM", "Coreset", "HSMM", "ARHMM"],
loc = 'lower left',
filename="output2b.png",
ylim=0.0,
xlim=0.1)
"""
#plotData(t[0])
#
#lm is the mean number of loops, dp is the probability of "missing"
#t = sampleDemonstrationFromSystem(sys,np.ones((2,1)), lm=0, dp=0)
#u = sampleDemonstrationFromSystem(sys,np.ones((2,1)), lm=0, dp=0)
#v = sampleDemonstrationFromSystem(sys,np.ones((2,1)), lm=0, dp=0)
#w = sampleDemonstrationFromSystem(sys,np.ones((2,1)), lm=0, dp=0)
#x = sampleDemonstrationFromSystem(sys,np.ones((2,1)), lm=0, dp=0)
#0.3 o, 0.3, 3 r
"""
a = TransitionStateClustering(window_size=3, normalize=False, pruning=0.3,delta=-1)
b = TimeVaryingGaussianMixtureModel(hard_param=3)
c = HMMGaussianMixtureModel(n_components=3)
d = CoresetSegmentation(n_components=4)
e = HiddenSemiMarkovModel()
f = AutoregressiveMarkovModel()
plotY1Y2(run_sweep_experiment(sys_params, 'resonance', [0.01, 0.25, 0.5, 1, 2], [a,b,c,d,e,f], np.ones((2,1)), jaccard, N=5, k=5),
"LF Noise vs. Jaccard",
"LF Noise",
"Jaccard",
legend=["TSC", "GMM", "GMM+HMM", "Coreset", "HSMM", "ARHMM"],
loc = 'title',
filename="output2.png",
ylim=0.0,
xlim=0.1)
"""
"""
a = TransitionStateClustering(window_size=2, normalize=False, pruning=0.2,delta=-1)
b = TransitionStateClustering(window_size=2, normalize=False, pruning=0.4,delta=-1)
c = TransitionStateClustering(window_size=2, normalize=False, pruning=0.6,delta=-1)
d = TransitionStateClustering(window_size=2, normalize=False, pruning=0.8,delta=-1)
e = TransitionStateClustering(window_size=2, normalize=False, pruning=1.0,delta=-1)
plotY1Y2(run_sweep_experiment(sys_params, 'observation', [0.1, 0.2, 0.5, 0.75, 1, 1.5], [a,b,c,d,e], np.ones((2,1)), jaccard, N=5, k=20),
"LF Noise vs. Jaccard",
"LF Noise",
"Jaccard",
legend=["TSC (p=0.2)", "TSC (p=0.4)", "TSC (p=0.6)", "TSC (p=0.8)", "TSC (p=1.0)"],
loc = 'title',
filename="output5.png",
ylim=0.0,
xlim=0.1)
"""
"""
a = TimeVaryingGaussianMixtureModel()
#t = sampleDemonstrationFromSystem(sys,np.ones((2,1)), lm=0, dp=0)
#plotData(t)
for i in range(0,20):
t = sampleDemonstrationFromSystem(sys,np.ones((2,1)), lm=0, dp=0)
a.addDemonstration(np.squeeze(t))
a.fit(hard_param = 3)
print a.segmentation
"""
"""
a = HMMGaussianMixtureModel()
#t = sampleDemonstrationFromSystem(sys,np.ones((2,1)), lm=0, dp=0)
#plotData(t)
for i in range(0,20):
t = sampleDemonstrationFromSystem(sys,np.ones((2,1)), lm=0, dp=0)
a.addDemonstration(np.squeeze(t))
a.fit(n_components = 4)
print a.segmentation
"""
"""
a = CoresetSegmentation()
for i in range(0,20):
t = sampleDemonstrationFromSystem(sys,np.ones((2,1)), lm=0, dp=0)
a.addDemonstration(np.squeeze(t))
a.fit(n_components = 2)
print a.segmentation
"""
#from alternates.coreset import *
#print coreset.get_coreset(np.squeeze(t),3,3)