-
Notifications
You must be signed in to change notification settings - Fork 1
/
RPRecog.m
executable file
·75 lines (69 loc) · 2.04 KB
/
RPRecog.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
function [ RPR ] = RPRecog( D, G, Events, thres_time )
% root-pattern recognition rate (R-P Recog): calculates the ratio between
% the number of correctly identified events
% (i.e., events with correct type of root-pattern) and the number of
% correctly detected events.
% D: detection matrix
% G: groundtruth matrix
% Events: a cell storing event name in order
% thres_time: match detection and groundtruth within this time span
RPR = [];
if nargin < 3
disp('Error: Not enough arguments!')
return
end
if nargin == 3
thres_time = 7; % second
end
if size(D,1) ~= size(G,1)
disp('Error: D and G must be the same number of row')
return
end
if mod(size(D,1),length(Events))
disp('Error: Event number does not match')
return
end
cnt_i = 0;
cnt_d = 0;
for i=1:length(Events):size(D,1)
d = D(i:i+length(Events)-1,:);
g = G(i:i+length(Events)-1,:);
time_d = [];
time_g = [];
% calculate the number of correctly identified events
for j=1:size(g,1)
if sum(g(j,:)>=0) == 0
continue
end
dt = d(j,d(j,:)>=0); % delete useless information -1
gt = g(j,g(j,:)>=0);
time_d = [time_d , dt]; % store times used for next step
time_g = [time_g , gt];
for k=1:length(gt)
if isempty(dt)
break
end
if sum(abs(dt - gt(k)) <= thres_time)
cnt_i = cnt_i + 1;
[~, loc] = min(abs(dt - gt(k)));
dt(loc) = [];
end
end
end
% calculate the number of correctly detected events
if isempty(time_g)
continue
end
for j=1:length(time_g)
if sum(abs(time_d-time_g(j)) <= thres_time)
cnt_d = cnt_d + 1;
[~, loc] = min(abs(time_d-time_g(j)));
time_d(loc) = [];
end
end
end
RPR.metric = 'Root-Pattern Recog Rate';
RPR.identi = cnt_i;
RPR.detect = cnt_d;
RPR.result = strcat(num2str(round(cnt_i/cnt_d*10000)/100),'%');
end