Repository navigation
Expand file tree
/
Copy pathelm_train.m
More file actions
56 lines (40 loc) · 1.47 KB
/
Copy pathelm_train.m
File metadata and controls
56 lines (40 loc) · 1.47 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
% =========================================================================
%%% Authors: Kai Zhang AND DR Jiuwen Cao
%%% Hangzhou Dianzi University, CHINA
%%% EMAIL: jwcao@hdu.edu.cn
%%% DATE: June 2016
%%% Please cite the paper: "J. Cao, K. Zhang, M. Luo, C. Yin and X. Lai, Extreme learning machine and adaptive sparse representation for image classification, Neural networks (2016), http://dx.doi.org/10.1016/j.neunet.2016.06.001"
%--------------------------------------------------------------------------
function [nn, acc_train,label_actual,label_desired] = elm_train(X, Y, nn)
% beta f(Wx+b) = y
tic;
ndata = size(X,2);
tempH = nn.W*X + repmat(nn.b,1,ndata);
switch lower(nn.activefunction)
case{'s','sig','sigmoid'}
H = 1 ./ (1 + exp(-tempH));
case{'t','tanh'}
H = tanh(tempH);
end
clear tempH;
switch(nn.method)
case 'ELM'
[beta,C_opt,LOO] = regressor(H', Y', 0);
case 'RELM'
[beta,C_opt,LOO] = regressor(H', Y', nn.C);
end
nn.time_train = toc;
nn.C_opt = C_opt;
nn.LOO = LOO;
nn.beta = beta';
Y_hat = nn.beta*H;
if ismember(nn.type,{'c','classification','Classification'})
[~,label_actual] = max(Y_hat,[],1);
[~,label_desired] = max(Y,[],1);
acc_train = sum(label_actual==label_desired)/ndata;
else
normfro = norm(Y-Y_hat,'fro');
acc_train = sqrt(normfro^2/ndata);
end
nn.trainlabel = Y_hat;
nn.acc_train = acc_train;