-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathcompute_rwmd.m
41 lines (26 loc) · 893 Bytes
/
compute_rwmd.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
function [] = compute_rwmd(load_file,save_file)
addpath('emd')
load(load_file);
n = length(BOW_X);
RWMD_D = zeros(n,n);
parfor i = 1:n
Ei = zeros(1,n);
for j = (i+1):n
if isempty(BOW_X{i}) || isempty(BOW_X{j})
Ei(j) = Inf;
else
x1 = BOW_X{i}./sum(BOW_X{i});
x2 = BOW_X{j}./sum(BOW_X{j});
DD = distance(X{i},X{j}); % (ni,nj)
m1 = sqrt(max(min(DD,[],1),0)); % (1,nj)
m2 = sqrt(max(min(DD,[],2),0)); % (ni,1)
dist1 = m1*x2';
dist2 = m2'*x1';
Ei(j) = max(dist1,dist2);
end
end
RWMD_D(i,:) = Ei;
end
RWMD_D = RWMD_D + RWMD_D'; % because only upper triangular part is computed (similar to WMD)
save(save_file,'RMD_D');
end