-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExp1_rf.m
More file actions
60 lines (50 loc) · 1.91 KB
/
Exp1_rf.m
File metadata and controls
60 lines (50 loc) · 1.91 KB
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
addpath('./utils/');
addpath('./libsvm/matlab/');
rand('state', 16);
% parameters
n_rf = [1,50:50:3000];
n_partition = 500;
D = 500;
n_repeat = 5;
data_name = 'HIGGS';
[lambda, sigma] = best_parameters(data_name);
load(['./data/', data_name]);
error_matrix = zeros(n_repeat, length(n_rf));
time_matrix = zeros(n_repeat, length(n_rf));
for i_rf = 1 : length(n_rf)
len_rf = n_rf(i_rf);
% feature mapping
t_rf_start = tic();
Z = random_fourier_features(X, len_rf, sigma);
Z = [Z, ones(length(y), 1)];
t_rf = toc(t_rf_start);
for i_repeat = 1 : n_repeat
t = tic();
idx_rand = randperm(length(y));
idx_train = idx_rand(1:ceil(5*length(y)/6));
idx_test = setdiff(idx_rand, idx_train);
Z_train = Z(idx_train, :);
Z_test = Z(idx_test, :);
y_train = y(idx_train, :);
y_test = y(idx_test, :);
% error_rate = linear_solver(Z_train, y_train, Z_test, y_test, lambda, 'binary')
step_part = ceil(length(y_train)/n_partition);
w = zeros(len_rf+1, 1);
for i_part = 1 : n_partition
idx_start = (i_part - 1)*step_part + 1;
idx_end = min(i_part*step_part, length(y_train));
i_Z_train = Z_train(idx_start:idx_end, :);
i_y_train = y_train(idx_start:idx_end);
w = w + linear_train(i_Z_train, i_y_train, lambda);
end
training_time = (t_rf + toc(t))/n_partition;
w = w ./ n_partition;
y_predict = Z_test * w;
error_rate = error_estimate(y_predict, y_test, 'binary');
error_matrix(i_repeat, i_rf) = error_rate;
time_matrix(i_repeat, i_rf) = training_time;
fprintf('Finish repeat %d - rf %d\n', i_repeat, len_rf);
end
end
save(['./results/Exp1/error_rfs_', data_name], 'n_repeat', 'lambda', ...
'sigma', 'n_repeat', 'n_rf', 'error_matrix', 'time_matrix');