-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassifyLengthPiece.m
291 lines (228 loc) · 9.82 KB
/
classifyLengthPiece.m
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
function [ classification ] = classifyLengthPiece( queryall, queryidentifier, querycombo, template, templatecombo, qtprune, strokerelation ,votes,matchpercent)
%CLASSIFYLENGTHPIECE Summary of this function goes here
% Detailed explanation goes here
queryidentifier = queryidentifier(queryidentifier~=0);
classification = ones(1, length(queryidentifier))*2;
index=1;
%if matching a query to an emptyspace, classify all grouped points as
%extra
if isempty(template)
for i=1:length(queryidentifier)
actualclass = strokerelation(queryidentifier(i));
%strokes that were used in the query matching
if(actualclass==1 || actualclass==0)
classification(i) = 1;
end
end
%if query consists of a single point, check for missing strokes
elseif isempty(querycombo)
if(~isempty(queryidentifier))
found=false;
queryindex=1;
while ~found
if(index > length(queryidentifier))
found=true;
queryindex=1;
classification(1)=-1;
else
actualclass = strokerelation(queryidentifier(index));
%strokes that were used in the query matching
if(actualclass==1 || actualclass==0)
found=true;
classification(index) = 0;
queryindex=index;
end
index=index+1;
end
end
for i=1:length(queryidentifier)
sectionsize=0;
if(i ~= queryindex)
if(i<queryindex)
sectionsize=sum(queryall(i:queryindex-1));
elseif(i>queryindex)
sectionsize=sum(queryall(queryindex:i-1));
end
for j=1:length(template)
if(votes < 0.00000001)
if(abs(queryindex-i) <= length(template))
classification(i)=-1;
end
elseif(sectionsize/template(j) <1.2*(1/matchpercent) && sectionsize/template(j) > .8*matchpercent)
classification(i)=-1;
end
end
end
end
end
else
prunedsize = 0;
%classify start query prune as extra strokes
for i=1:qtprune(1)-1
found=false;
while ~found
actualclass = strokerelation(queryidentifier(index));
%strokes that were used in the query matching
if(actualclass==1 || actualclass==0)
found=true;
classification(index) = 1;
end
prunedsize = prunedsize+queryall(index);
index=index+1;
end
end
%classify the first in the query as correct
found=false;
while ~found
actualclass = strokerelation(queryidentifier(index));
%strokes that were used in the query matching
if(actualclass==1 || actualclass==0)
found=true;
classification(index) = 0;
prunedsize = prunedsize-queryall(index);
end
prunedsize = prunedsize+queryall(index);
index=index+1;
end
startindex=index-1;
%classifymissingstrokes in beginning pruned portion
currdistance=0;
i=1;
templatepiece=1;
prunedtemplatesize = sum(template(1:qtprune(3)-1));
while i<startindex && templatepiece < qtprune(3)
actualclass = strokerelation(queryidentifier(i));
%strokes that were not used in the query matching
if ~(actualclass==1 || actualclass==0)
distanceToPredictedMissing = ((prunedsize-currdistance) - sum(template(templatepiece:qtprune(3)-1)))/prunedtemplatesize;
if(distanceToPredictedMissing > .5)
currdistance = currdistance+queryall(i);
i=i+1;
elseif(distanceToPredictedMissing > -.5)
currdistance = currdistance+queryall(i);
classification(i) = -1;
i=i+1;
else
templatepiece=templatepiece+1;
end
else
currdistance = currdistance+queryall(i);
i=i+1;
end
end
sectionsize=0;
sectionstart=startindex;
queryindex=1;
templatecomboindex = 1;
%classify strokes that were matched
for i=qtprune(1):qtprune(2)
found=false;
while ~found
sectionsize=sectionsize+queryall(index-1);
actualclass = strokerelation(queryidentifier(index));
%strokes that were used in the query matching
if(actualclass==1 || actualclass==0)
found=true;
endsection = false;
if(i==qtprune(2))
classification(index) = 0;
endsection=true;
else
if(querycombo(queryindex)==0)
classification(index) = 0;
endsection=true;
else
classification(index) = 1;
querycombo(queryindex) = querycombo(queryindex) - 1;
end
end
%identify the missing strokes in the current section
if(endsection && queryindex<=length(querycombo))
currdistance=0;
j=sectionstart;
templatepieces=0;
templateindex=qtprune(3) + sum((templatecombo(1:templatecomboindex-1) + 1));
templatedist = template(templateindex);
while j<index && ~templatecombo(templatecomboindex) == 0
actualclass = strokerelation(queryidentifier(j));
%strokes that were not used in the query matching
if ~(actualclass==1 || actualclass==0)
distanceToPredictedMissing = (currdistance - templatedist)/sectionsize;
if(distanceToPredictedMissing < -.2)
currdistance = currdistance+queryall(j);
j=j+1;
elseif(distanceToPredictedMissing <.2)
currdistance = currdistance+queryall(j);
classification(j) = -1;
j=j+1;
else
templatepieces=templatepieces+1;
templateindex=qtprune(3) + sum((templatecombo(1:templatecomboindex-1)+1))+templatepieces;
templatedist = templatedist+template(templateindex);
j=j+1;
end
else
currdistance = currdistance+queryall(j);
j=j+1;
templatepieces=0;
end
end
templatecomboindex=templatecomboindex+1;
sectionsize=0;
sectionstart=index;
queryindex=queryindex+1;
end
end
index=index+1;
end
end
endindex=index-1;
%classify strokes in the query after the prunes as extra
for i=index:length(queryidentifier)
actualclass = strokerelation(queryidentifier(i));
%strokes that were used in the query matching
if(actualclass==1 || actualclass==0)
classification(i) = 1;
end
end
%classifymissingstrokes in end pruned portion
currdistance=0;
i=endindex;
templatepiece=qtprune(4)+1;
prunedtemplatesize = sum(template(qtprune(4)+1:length(template)));
while i<=length(queryidentifier) && templatepiece <= length(template)
actualclass = strokerelation(queryidentifier(i));
%strokes that were not used in the query matching
if ~(actualclass==1 || actualclass==0)
distanceToPredictedMissing = (currdistance - sum(template(qtprune(4)+1:templatepiece)))/prunedtemplatesize;
if(distanceToPredictedMissing < -.5)
if(i<length(queryidentifier))
currdistance = currdistance+queryall(i);
end
i=i+1;
elseif(distanceToPredictedMissing <.5)
if(i<length(queryidentifier))
currdistance = currdistance+queryall(i);
end
classification(i) = -1;
i=i+1;
else
templatepiece=templatepiece+1;
end
else
if(i<length(queryidentifier))
currdistance = currdistance+queryall(i);
end
i=i+1;
end
end
end
% queryall
% queryidentifier
% querycombo
% template
% templatecombo
% qtprune
% strokerelation
% classification
end