forked from felixyu/SRF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.m
More file actions
42 lines (37 loc) · 946 Bytes
/
test.m
File metadata and controls
42 lines (37 loc) · 946 Bytes
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
% Computer the nonlinear map based on SRF.
clear all;
%% kernel parameter
a = 4;
b = 7;
num_gaussians = 10;
%% data
load('usps.mat');
num_train = size(data_train, 1);
num_test = size(data_test,1);
X = [data_train; data_test];
%% normalization
for i = 1:size(X,1)
X(i,:) = X(i,:)./norm(X(i,:),2);
end
%% kernel apprximation and evaluation
N_sample = 10000;
mapdim_all = 2.^[9, 10, 11, 12, 13, 14];
if (size(X,1) > N_sample)
rand_r = randperm(size(X,1));
X = X(rand_r(1:N_sample), :);
end
kernelfunc = @(normz) (1 - (normz/a).^2 ).^b;
MSE = zeros(1, length(mapdim_all));
for ii = 1:length(mapdim_all)
mapdim = mapdim_all(ii);
fea = gen_RFF(X, a, b, num_gaussians, mapdim);
kernel_gt = kernelfunc(sqrt(2 - X*X'*2));
kernel_diff = (kernel_gt - fea * fea').^2;
MSE(ii) = mean(kernel_diff(:));
end
close all;
figure;
hold on;
plot(log(mapdim_all)/log(2), MSE);
xlabel('log(mapped dimensionality)');
ylabel('MSE')