-
Notifications
You must be signed in to change notification settings - Fork 4
/
build_action_bags.m
96 lines (71 loc) · 2.52 KB
/
build_action_bags.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function [Y, linear_constraint,blocks,slack_blocks] = build_action_bags(params, movie_block,movie_bag,bags, X, GT, tframes,T ,mapping)
% the variable with the opposite latent variable is called here T but its
% true value depend on the direction of optimization
N = size(X, 1);
P = max(GT);
blocks = movie_block;
n_movies = length(movie_block);
% checking which track is in which bag
A = tracks_in_bag(bags, tframes);
eS = zeros(N, 1);
eC = zeros(P, 1);
for i=1:n_movies
mask = sum(A(movie_bag{i},:),1) == 0;
unconstrained_tracks{i} = intersect(find(mask),movie_block{i});
%block2 = unconstrained_tracks;
%block1 = find(sum(A(:,movie_block{1}),1) > 0);
%n_unconstrained_tracks = length(unconstrained_tracks);
end
% number of bags
I = size(A,1);
k = 1;
decay = 0;
ls = linspace(0,1,decay+2);
% switching from frame position to track indexgt
linear_constraint = struct();
slack_blocks = movie_bag;
I = size(A,1);
for i = 1:I
sidx = find(A(i, :)>0);
cidx = bags(i).action;
if length(sidx) >= 0
if decay > 0
msidx = min(sidx);
Msidx = max(sidx);
lsidx = msidx - (1:decay);
rsidx = Msidx + (1:decay);
sidx = [lsidx sidx rsidx];
end
linear_constraint(k).sample = eS;
linear_constraint(k).sample(sidx) = 1;
linear_constraint(k).class = eC;
linear_constraint(k).class(cidx) = 1;
linear_constraint(k).type = 'geq';
linear_constraint(k).val = params.alpha;
linear_constraint(k).slack = 1;
if decay > 0
linear_constraint(k).weights = [ls(2:end-1)';ones(length(sidx)-2*decay,1);ls(end-1:-1:2)'];
else
if bags(i).people > 0
linear_constraint(k).weights = T(mapping(sidx),bags(i).people);
else
linear_constraint(k).weights = ones(length(sidx),1);
end
end
k = k+1;
end
end
%% WEAK-SUPERVISION CONSTRAINT FOR BACKGROUND %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:n_movies
linear_constraint(k).sample = eS;
linear_constraint(k).sample(unconstrained_tracks{i}) = 1;
linear_constraint(k).class = eC;
linear_constraint(k).class(1) = 1;
linear_constraint(k).type = 'geq';
linear_constraint(k).val = params.alpha_2*length(unconstrained_tracks{i});
linear_constraint(k).slack = 0;
linear_constraint(k).weights = ones(length(unconstrained_tracks{i}),1);
k = k+1;
end
Y = full(sparse(1:length(GT), GT, 1));
end