-
Notifications
You must be signed in to change notification settings - Fork 14
/
lossM.m
69 lines (57 loc) · 1.52 KB
/
lossM.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
function [delta, p, r] = lossM(y, ybar, callbacks, parameters)
% create an association array for y and ybar:
% the position of the element in y gives him a uinque identifier
elements = [y{:}];
% create the UF data structures
UF_y = zeros(1, length(elements));
UF_ybar = zeros(1, length(elements));
for i = 1 : size(y, 2)
for j = 1 : length(y{i})
% find the index of the element and update its input in UF_y
UF_y(elements == y{i}(j)) = i;
end
end
for i = 1 : size(ybar, 2)
for j = 1 : length(ybar{i})
% find the index of the element and update its input in UF_y
UF_ybar(elements == ybar{i}(j)) = i;
end
end
% get the connected components in UF_y and UF_ybar
connected_y = unique(UF_y);
connected_ybar = unique(UF_ybar);
% take 0 away
connected_y(connected_y == 0) = [];
connected_ybar(connected_ybar == 0) = [];
% now we can apply the MITRE measure, first from y to ybar...
num = 0;
den = 0;
for i = 1 : length(connected_y)
S = UF_y == connected_y(i);
num = num + sum(S) - length(unique(UF_ybar(S)));
den = den + sum(S) - 1;
end
R_y_ybar = num / den;
if isnan(R_y_ybar)
R_y_ybar = 1;
end
% ... and then from ybar to y!
num = 0;
den = 0;
for i = 1 : length(connected_ybar)
S = UF_ybar == connected_ybar(i);
num = num + sum(S) - length(unique(UF_y(S)));
den = den + sum(S) - 1;
end
R_ybar_y = num / den;
if isnan(R_ybar_y)
R_ybar_y = 1;
end
F = 2 * R_y_ybar * R_ybar_y / (R_y_ybar + R_ybar_y);
p = R_ybar_y;
r = R_y_ybar;
if isnan(F)
F = 0;
end
delta = 1 - F;
end