-
Notifications
You must be signed in to change notification settings - Fork 6
/
build_bag_indicators.m
62 lines (55 loc) · 1.63 KB
/
build_bag_indicators.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
function [ A_ind, B_ind ] = build_bag_indicators( params, bag, Y, T )
[N, P] = size(Y);
eA = zeros(N, 1);
eB = zeros(P, 1);
I = length(bag);
A_ind = cell(I, 1);
B_ind = cell(I, 1);
for i = 1:I
A_ind{i} = eA;
B_ind{i} = eB;
if isempty(bag(i).person) || isempty(bag(i).action)
if strcmp(params.coordinate, 'faces')
if bag(i).person == 1
A_ind{i}(bag(i).tracks) = 1;
else
% A_ind{i}(bag(i).tracks) = 1 ./ size(T,2);
A_ind{i}(bag(i).tracks) = 1;
end
B_ind{i}(bag(i).person) = 1;
else
if bag(i).action == 1
A_ind{i}(bag(i).tracks) = 1;
else
% A_ind{i}(bag(i).tracks) = 1 ./ size(T,2);
A_ind{i}(bag(i).tracks) = 1;
end
B_ind{i}(bag(i).action) = 1;
end
else
temp = eA;
temp(bag(i).tracks) = 1;
if strcmp(params.coordinate, 'faces')
if bag(i).person > 0
A_ind{i} = temp .* T(:, bag(i).action);
B_ind{i}(bag(i).person) = 1;
else
fprintf('Skipping negative constraint\n');
end
else
if bag(i).person < 0
A_ind{i} = temp .* (1 - T(:, -bag(i).person));
B_ind{i}(1) = 1;
else
A_ind{i} = temp .* T(:, bag(i).person);
B_ind{i}(bag(i).action) = 1;
end
end
end
end
sA = cellfun(@sum, A_ind);
sB = cellfun(@sum, B_ind);
nonempty = sA>0 & sB>0;
A_ind = A_ind(nonempty);
B_ind = B_ind(nonempty);
end