-
Notifications
You must be signed in to change notification settings - Fork 1
/
kendallDistNormalizedMergeSortFragmentedAlsoMiddle.m
69 lines (59 loc) · 2.88 KB
/
kendallDistNormalizedMergeSortFragmentedAlsoMiddle.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Calculate Kendall distance for fragments of windows
%
% Input:
% seq - the sequence of feature indexes, e.g., the indexes of the matches
% from the first image when the features in the second image are sorted
% by X axis and indexed as 1:N. ([firstSeq]->1:N)
% timesVec - a vector of resolutions, e.g., [(1:(round(resolution*N)):N)
% N] where resolution = 0.1 and N = 1000 for example.
%
% Output:
% kendallDistMat - an upper triangle matrix with kendall distance for the
% appropriate windows
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function kendallDistMat = kendallDistNormalizedMergeSortFragmentedAlsoMiddle(seq, timesVec, restrictWindowSize)
timesKendall = length(timesVec);
kendallDistVec = zeros(1,timesKendall-1);
sortedListCellArr = cell(1,timesKendall-1);
projDistMat = cell(1,timesKendall-1);
projKendallDistVec = zeros(1,timesKendall-1);
kendallDistMat = zeros(timesKendall-1,timesKendall-1);
% calculate kendall distance for every small fraction of window -
% for example (O is for the window an X for outside the window) -
% [OOOOOXXXXXXXXXXXXXXXXXXXXX] is one window and
% [XXXXXXXXXXXXXXXXOOOOOXXXXX] is another
for i = 1:(timesKendall-1)
[curSortedList, curDist] = kendallDistMergeSort(seq(timesVec(i):(timesVec(i+1)-1)));
kendallDistVec(i) = curDist;
sortedListCellArr{i} = curSortedList;
projKendallDistVec(i) = curDist;
projDistMat{i} = curSortedList;
end
% using the small fractions of windows, calculate all the possible
% windows
% for example, calculate [OOOOOOOOOOXXXXXXXXXXXXXXXX] from
% [OOOOOXXXXXXXXXXXXXXXXXXXXX] and [XXXXXOOOOOXXXXXXXXXXXXXXXX]
for i = 1:(timesKendall-1)
curLengthLeft = length(sortedListCellArr{i});
if (restrictWindowSize)
if (curLengthLeft > 1)
kendallDistMat(i,i) = kendallDistVec(i)/((curLengthLeft)*(curLengthLeft-1)/2);
end
else
kendallDistMat(i,i) = kendallDistVec(i)/((curLengthLeft)*(curLengthLeft-1)/2);
end
for j = (i+1):(timesKendall-1)
projDistMat{i} = [projDistMat{i} sortedListCellArr{j}];
curAllLengthLeft = length(projDistMat{i});
curLengthLeft = length(sortedListCellArr{j});
projKendallDistVec(i) = projKendallDistVec(i) + kendallDistVec(j);
[curListLeft,curDistLeft] = merge(projDistMat{i},1,curAllLengthLeft-curLengthLeft,curAllLengthLeft,projKendallDistVec(i));
projDistMat{i} = curListLeft;
projKendallDistVec(i) = curDistLeft;
kendallDistMat(i,j) = curDistLeft/((curAllLengthLeft)*(curAllLengthLeft-1)/2);
end
end
end