-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameterselection.m
56 lines (50 loc) · 1.75 KB
/
parameterselection.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
%% Emsemble features.
% LPQ 256 77.3465 30
% BSIF 256 77.7768 40
% DWT 13 79.1697 22
clear; close all;
load('/home/shu/Desktop/Tenko/Data/CrossmatchR2.mat')
load('/home/shu/Desktop/Tenko/Data/CrossmatchR2_BSIF_11_8.mat')
load('/home/shu/Desktop/Tenko/Data/CrossmatchR2_DWT_5.mat')
load('/home/shu/Desktop/Tenko/Data/CrossmatchR2_LBP_1_8_riu2.mat')
load('/home/shu/Desktop/Tenko/Data/CrossmatchR2_LPQ_5.mat')
feat = [data_dwt];
%%
train_stat = zeros(1, 100);
test_stat = zeros(1, 100);
iternum = 100;
for k = 1 : 100
for i = 1 : iternum
% Shuffle data and get index.
trainrate = 0.8;
trainnum = ceil(trainrate * numel(label));
idx = randperm(numel(label));
trainidx = idx(1:trainnum);
testidx = idx(trainnum+1:end);
% get label
trainlabel = label(trainidx, :);
testlabel = label(testidx, :);
% get data
trainfeat = feat(trainidx, :);
testfeat = feat(testidx, :);
% Training
[~, ~, TrainAcc, TestAcc, W, b, o] ...
= elm([trainlabel, trainfeat], [testlabel, testfeat], 1, k, 'sig');
train_stat(k) = train_stat(k) + TrainAcc;
test_stat(k) = test_stat(k) + TestAcc;
end
end
%%
train_stat = train_stat * 100 / iternum;
test_stat = test_stat * 100 / iternum;
plot(1:100, train_stat, 1:100, test_stat);
xlabel('Number of Neurons in Hidden Layer');
ylabel('Accuracy (%)');
legend('Train', 'Test');
hold on; plot([1,100], [80,80], 'r--');
[accmax, kmax] = max(test_stat);
hold on; plot([kmax,kmax], [50, accmax], 'r--');
text(50, 70, [num2str(accmax), '%']);
text(50, 68, ['kmax=', num2str(kmax)]);
disp(['The optimal number of hidden neurons is ', num2str(kmax)]);
disp(['The best testing performance is ', num2str(accmax), '%.']);