/
reject.m
216 lines (176 loc) · 5.82 KB
/
reject.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
%% Reject main code file
%
% Developed by
% - Ricardo Sousa
% Researcher at INEB
% rsousa @ rsousa.org
% - Jaime S. Cardoso
% Professor at FEUP and Researcher at INESC Porto
% jsc @ inesctec.pt
%
% Code License (GNU v3)
function reject(general_opt)
if nargin ~= 1
% argument sanity check
usage();
return;
end
% max num of threads
% MaxNumCompThreads(1);
warning off all;
% debug info will be written to this file
% global filename
datasetID = general_opt.datasetID;
method = general_opt.method;
% ----------------------------------------------------------------------------------
% CONFIGURATION SECTION
% C-values
if ~isfield( general_opt, 'C' )
Cvalue = -5:2:3; %-5:2:10; %-5:2:15;
Cvalue = 2.^Cvalue;
else
Cvalue = general_opt.C;
end
% Gamma values
if ~isfield ( general_opt, 'gamma' )
gamma = -3:2:-1;
gamma = 2.^gamma;
else
gamma = general_opt.gamma;
end
% osvm specific configuration values
if ~isfield ( general_opt, 'h' )
h = 1:4; %3:7 - syntheticI
else
h = general_opt.h;
end
if ~isfield ( general_opt, 's' )
s = [2,4];
else
s = general_opt.s;
end
% weights
wr = 0.04:.2:.48;
if strcmp(general_opt.method,'sca_flip') == 1 | ...
strcmp(general_opt.method,'sca_del') == 1 | ...
strcmp(general_opt.method,'ssca_del') == 1 | ...
strcmp(general_opt.method,'standard') == 1
wr = 0.04; % this value does not matter
end
if strcmp(general_opt.method,'sca_flip') == 1 | ...
strcmp(general_opt.method,'sca_del') == 1 | ...
strcmp(general_opt.method,'ssca_del') == 1 | ...
strcmp(general_opt.method,'standard') == 1
general_opt.prune = true;
end
% precision
epsilon = 1e-5;
% kernel degree
degree = general_opt.degree;
% folds
foldsx = .05:.05:.9;
folds = [foldsx' 1-foldsx'];
nfolds = 3;
%pause
paramRange = struct('C',Cvalue,'gamma',gamma)
parameters = struct();
%parameters.k = k;
parameters.Cvalue = Cvalue;
parameters.gamma = gamma;
parameters.h = h;
parameters.s = s;
% number of rounds
nrounds = general_opt.nrounds;
% kernel type
kerneltype = general_opt.kernel;
switch (method)
case {'standard','sca_flip','sca_del','ssca_del','threshold','weights'}
kernel = kerneltype;
otherwise
fprintf(1,'(reject.m) error: method ''%s'' unknown\n',method);
usage();
return
end
if ( strcmp(method,'threshold') == 1 )
probability = 1;
else
probability = 0;
end
% -------------------------------------------------------
% lets combine all them
combinations = combine_parameters( general_opt, parameters);
method_parameter = 1;
% ----------------------------------------------------------------------------------
% specific options for the my_svm_dual_train
options = struct('trial',general_opt.trial,'epsilon',epsilon,'method',method,'method_parameter',method_parameter);
options.project_lib_path = general_opt.project_lib_path; %
options.workmem = 1024;
options.test = false;
% dataset
options.givenval = general_opt.givenval;
options.randomset = general_opt.randomset;
% pruning specific options
options.prune = general_opt.prune;
options.reduce_now = false;
options.submethod = 'libsvm';
% bag of features
options.usenclusters = 1000; %2^2;
% SVM Specific Options
options.coef = 1;
options.kernel = kernel;
options.degree = degree;
options.weights = 1;
options.wr = wr;
options.folds = folds;
options.nfolds = nfolds;
options.nrounds = nrounds;
options.probability = probability;
options.maxiter = 15000;
options.optimization = 'cplex';
options.C = [];
options.gamma = [];
options.ssca_D = general_opt.ssca_D;
if ( method_parameter == 0 && ...
( strcmp(options.method,'threshold') == 1 ) )
options.nbins = 1;
end
switch (options.submethod)
case 'libsvm'
addpath(fullfile(general_opt.project_lib_path, 'libsvm-3.17/matlab/'))
otherwise
which_method_are_you_going_to_run
end
options
fprintf(1,'Using dataset ''%s'' on method ''%s'' \n', datasetID, method );
% ----------------------------------------------------------------------------------
best_options = reject_run( options, combinations, datasetID);
return
%%
%
function usage
fprintf(1,'You must identify the method and datasetID\n\n');
fprintf(1,'Usage: ./reject method datasetID\n');
fprintf(1,'method: \n');
fprintf(1,['\t- threshold\n'...
'\t- weights\n']);
fprintf(1,'datasetID: \n');
fprintf(1,['\t- syntheticI\n'...
'\t- others'...
'\n\n']);
return
%%
%
function combinations = combine_parameters( options, parameters)
switch( options.method )
case {'threshold', 'weights', 'sca_flip', 'sca_del', 'ssca_del', 'standard'}
switch( options.kernel )
case 'linear'
combinations = parameters.Cvalue;
otherwise
combinations = combvec( parameters.Cvalue, parameters.gamma );
end
otherwise
str = sprintf('Method ''%s'' unknown.\n',options.method);
error(str);
end
return