-
Notifications
You must be signed in to change notification settings - Fork 1
/
order_tracks.m
333 lines (290 loc) · 10.2 KB
/
order_tracks.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
function [Omega2, order] = order_tracks(Omega, type)
%ORDER_TRACKS Order tracks for efficient hypotheses management
% Detailed explanation goes here
%
% Coded by:
% Flavio Eler de Melo ([email protected])
% University of Liverpool, September, 2013
%
mk = size(Omega,1);
order = (1:mk)';
if mk < 2
Omega2 = Omega;
return;
end
Omega2 = Omega;
tm = cell(mk,1);
tset = [];
for j = 1:mk
cond = (Omega(j,2:end) == 1);
ind = find(cond);
tm{j,1} = ind;
tset = union(tset,tm{j,1});
end
Nt = length(tset);
switch type
case 'ehm1'
%% Original ordering algorithm - ordering measurements
tlist = cell(mk,1);
mlist = cell(mk,1);
mcomb = cell(4,2);
for j = 1:mk
mlist{j,1} = j;
end
comb = nchoosek(1:mk,2);
mc = zeros(size(comb,1),1);
mi = zeros(4,1);
for j = 1:mk-1
% For each list of tracks, get the union of correspondent gated targets
for i = 1:mk
tlist{i,1} = unique(horzcat(tm{mlist{i,1},1}));
end
% Compare the intersection in pairs of measurements' lists
for k = 1:size(comb,1)
im1 = intersect(tlist{comb(k,1),1},tlist{comb(k,2),1});
% im1 = union(tlist{comb(k,1),1},tlist{comb(k,2),1});
if ~isempty(im1)
mc(k,1) = length(im1);
else
mc(k,1) = 0;
end
end
% Consider the lists with maximum intersection of associated common gated
% measurements (maximum intersection)
[mm1,im1] = max(mc);
if mm1 == 0
% if mm1 == Nt
ind = zeros(1,2);
k1 = 0;
k = 1;
while k1 < 2
if ~isempty(mlist{k,1});
k1 = k1+1;
ind(k1) = k;
end
k = k+1;
end
i1 = ind(1,1) == comb(:,1);
i2 = ind(1,2) == comb(:,2);
im1 = find(i1 & i2);
end
% Assemble potential combinations
mcomb{1,1} = mlist{comb(im1,1),1}; mcomb{1,2} = mlist{comb(im1,2),1};
mcomb{2,1} = fliplr(mlist{comb(im1,1),1}); mcomb{2,2} = mlist{comb(im1,2),1};
mcomb{3,1} = mlist{comb(im1,2),1}; mcomb{3,2} = mlist{comb(im1,1),1};
mcomb{4,1} = fliplr(mlist{comb(im1,2),1}); mcomb{4,2} = mlist{comb(im1,1),1};
% Check for combinations where the new adjoining targets have minimum
% intersection of gated measurements
for k = 1:4
im2 = intersect(tm{mcomb{k,1}(1,end),1},tm{mcomb{k,2}(1,1),1});
mi(k,1) = length(im2);
end
[~,im2] = min(mi);
% Substitute both previous list by the combined one
mlist{comb(im1,1),1} = unique(horzcat(mcomb{im2,1},mcomb{im2,2}),'stable');
mlist{comb(im1,2),1} = [];
end
ml = [];
k = 1;
while isempty(ml)
ml = mlist{k,1};
k = k+1;
end
order(1:mk,1) = ml;
case 'new' % Ordering algorithm proposed by Flavio Eler de Melo - September 2013
% Disclaimer:
% This is an enhancement to software that was generated under licence from QinetiQ Limited
% (ref QQC4ISR/UOL/SLA/12-2013). The enhancement relates to a patented algorithm,
% Patent Reference: 0315349.1. As specified under the agreement, QinetiQ has an irrevocable
% non-exclusive worldwide royalty free licence to use this enhancement.
%% Ordering algorithm 2 - ordering measurements
mlist = zeros(2*mk-1,1);
% Define middle measurement
% Find the target that can be assigned to the greatest number of
% measurements
tau = sum(Omega(:,2:end),1);
tmm = find(tau == max(tau));
% Criterion 1
% if the target that can be assigned to the greatest number of
% measurements is not unique, select the measurement with the
% maximum number of such targets
sm = zeros(mk,1);
for j = 1:mk
sm(j,1) = size(intersect(tm{j,1},tmm),2);
end
% Criterion 2
% Check if it is a unique maximum
[m1,~] = max(sm);
im1 = m1 == sm;
while sum(im1) > 1 % not unique
tau(tmm) = 0;
tmm = find(tau == max(tau));
if sum(tau) > 0
sm = zeros(mk,1);
for j = 1:mk
sm(j,1) = size(intersect(tm{j,1},tmm),2);
end
[m,~] = max(sm);
im = m == sm;
im2 = im & im1;
if sum(im2) > 0
im1 = im2;
end
else
sm = zeros(mk,1);
for j = 1:mk
sm(j,1) = size(tm{j,1},2);
end
[m,~] = max(sm);
im = m == sm;
im2 = im & im1;
if sum(im2) > 0
im = find(im2);
im2(im(2:end)) = 0;
im1 = im2;
else
im = find(im1);
im1(im(2:end)) = 0;
end
end
end
im = find(im1);
% Start with the list with maximum number of assignments
sm = zeros(mk,1);
sm2 = zeros(mk,1);
tset = [];
for j = 1:mk
sm(j,1) = size(tm{j,1},2);
sm2(j,1) = size(tm{j,1},2);
tset = union(tset,tm{j,1});
end
% [m1,~] = max(sm);
% Find if it is the only maximum
% im1 = find(sm == m1);
% mi = zeros(length(im1),1);
% if length(im1) > 1
% for i = 1:length(im1)
% im2 = 0;
% for j = 1:mk
% if j ~= im1(i)
% im = intersect(tm{im1(i),1},tm{j,1});
% im2 = im2 + size(im,2);
% end
% end
% mi(i,1) = im2;
% end
% end
% [~,im2] = max(mi);
% im = im1(im2);
mlist(mk) = im;
% Find two tracks
% tstack = zeros(2,1);
% istack = 0;
mc = zeros(mk,1);
exc = im;
sm2(im) = 0;
% i0 = (mk+mod(mk,2))/2 +1;
i0 = mk;
% Find the one with greatest intersection of assignment
for j = 1:mk
im1 = intersect(tm{im,1},tm{j,1});
if ~ismember(j,exc)
if ~isempty(im1)
mc(j,1) = length(im1);
else
mc(j,1) = 0;
end
end
end
[m1,im1] = max(mc);
% [m1,im1] = min(mc);
if m1 ~= 0
mlist(i0-1,1) = im1;
else
[~,im1] = max(sm2);
mlist(i0+1,1) = im1;
end
mc(:,1) = zeros(size(mc));
j = 2;
ind = find(mlist ~= 0);
while j < mk
iu = ind(1);
id = ind(end);
% Exceptions list
exc = mlist(ind,1);
iud = [iu; id];
if mk-size(ind) >= 2
for i = 1:2
for k = 1:mk
im1 = intersect(tm{mlist(iud(i)),1},tm{k,1});
if ~ismember(k,exc)
if ~isempty(im1)
mc(k,1) = length(im1);
else
mc(k,1) = 0;
end
end
end
[m1,im1] = max(mc);
% [m1,im1] = min(mc);
% Find if it is the only maximum
im2 = find(mc == m1);
% mi = zeros(length(im1),1);
if length(im2) > 1
sm2 = sm;
sm2(exc) = 0;
if i == 1 % Upper
[~,im3] = max(sm2(im2));
else % Lower
% [~,im3] = min(sm(im2));
[~,im3] = max(sm2(im2));
end
im1 = im2(im3);
m1 = mc(im1);
end
% if m1 ~= 0
if i == 1
mlist(iud(i)-1,1) = im1;
else
mlist(iud(i)+1,1) = im1;
end
exc = union(exc, im1);
% end
mc(:,1) = zeros(size(mc));
end
else
ilast = setdiff(1:mk,mlist(ind));
for i = 1:2
im1 = intersect(tm{mlist(iud(i)),1},tm{ilast,1});
if ~isempty(im1)
mc(iud(i),1) = length(im1);
else
mc(iud(i),1) = 0;
end
end
[m1,im1] = max(mc);
% [m1,im1] = min(mc);
if im1 == iud(1) && m1 > 0
mlist(iud(1)-1,1) = ilast;
elseif im1 == iud(2) && m1 > 0
mlist(iud(2)+1,1) = ilast;
else
if sm(ilast) < sm(iud(1))
mlist(iud(1)-1,1) = ilast;
else
mlist(iud(2)+1,1) = ilast;
end
end
mc(:,1) = zeros(size(mc));
end
ind = find(mlist ~= 0);
j = length(ind);
end
order(1:mk,1) = mlist((mlist ~= 0),1);
otherwise
order = (1:mk)';
% error('Unknown ordering type.');
end
% Ordering tracks
Omega2(:,2:end) = Omega(order, 2:end);
end