-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOTDelay.m
executable file
·63 lines (56 loc) · 1.6 KB
/
OTDelay.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
function [ OTD ] = OTDelay( D, G, Events, thres_time )
% occurrence time deviation: deviation between the detected occurring time
% and the ground truth (OT-Delay).
% D: detection matrix
% G: groundtruth matrix
% Events: a cell storing event name in order
% thres_time: match detection and groundtruth within this time span
OTD = [];
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
delay = zeros(length(Events),1);
cnt = delay;
for i=1:length(Events)
d = D(i:length(Events):end,:);
g = G(i:length(Events):end,:);
cnt(i) = 0;
for j=1:size(g,1)
if sum(g(j,:)>=0) == 0
continue
end
dt = d(j,d(j,:)>=0); % delet -1
gt = g(j,g(j,:)>=0); % delet -1
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)));
%if gt(k) > dt(loc)
delay(i) = delay(i) + abs(gt(k)-dt(loc));
%end
dt(loc) = [];
end
end
end
end
average = sum(delay) / sum(cnt);
OTD.metric = 'Occurring Time Delay';
OTD.events = Events;
OTD.result = delay'./cnt';
OTD.average = strcat(num2str(round(average*1000)/1000),'s');
end