-
Notifications
You must be signed in to change notification settings - Fork 1
/
runExperimentActiveTaskTargeted.m
82 lines (76 loc) · 2.65 KB
/
runExperimentActiveTaskTargeted.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
%%
% Do a targeted active task selection experiment on the landmine data
%
% Copyright (C) Paul Ruvolo and Eric Eaton 2013
%
% This file is part of ELLA.
%
% ELLA is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% ELLA is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with ELLA. If not, see <http://www.gnu.org/licenses/>.
function y = runExperimentActiveTaskTargeted()
useLogistic = true;
load('Datasets/landminedata','feature','label');
T = length(feature);
for t = 1 : T
feature{t}(:,end+1) = 1;
end
d = size(feature{1},2);
X = cell(T,1);
Xtest = cell(T,1);
Y = cell(T,1);
Ytest = cell(T,1);
for t = 1 : T
r = randperm(size(feature{t},1));
traininds = r(1:floor(length(r)/2));
testinds = r(floor(length(r)/2)+1:end);
X{t} = feature{t}(traininds,:);
Xtest{t} = feature{t}(testinds,:);
Y{t} = label{t}(traininds);
Ytest{t} = label{t}(testinds);
end
% set one task aside for targeting
targetTask = randint(1,1,[1 length(Y)]);
XTargetTrain = X{targetTask};
XTargetTest = Xtest{targetTask};
YTargetTrain = Y{targetTask};
YTargetTest = Ytest{targetTask};
nonTargets = [1:length(Y)]~=targetTask;
X = {X{nonTargets}};
Xtest = {Xtest{nonTargets}};
Y = {Y{nonTargets}};
Ytest = {Ytest{nonTargets}};
T = T - 1;
learningCurves = zeros(T,1);
model = initModelELLA(struct('k',2,...
'd',d,...
'mu',exp(-12),...
'lambda',exp(-10),...
'ridgeTerm',exp(-5),...
'initializeWithFirstKTasks',true,...
'useLogistic',useLogistic,...
'lastFeatureIsABiasTerm',true));
learned = logical(zeros(length(Y),1));
unlearned = find(~learned);
for t = 1 : T
% change the last input to 1 for random, 2 for InfoMax, 3 for Diversity, 4 for Diversity++
idx = selectTaskELLA(model,{X{unlearned}},{Y{unlearned}},2,XTargetTrain,YTargetTrain);
model = addTaskELLA(model,X{unlearned(idx)},Y{unlearned(idx)},unlearned(idx));
learned(unlearned(idx)) = true;
unlearned = find(~learned);
% encode the target task
model = addTaskELLA(model,XTargetTrain,YTargetTrain,T+1,true);
preds = predictELLA(model,XTargetTest,T+1);
learningCurves(t,1) = roc(preds,YTargetTest);
end
y = mean(learningCurves,2);
end