-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathClassify_PCAL1.m
31 lines (29 loc) · 1.15 KB
/
Classify_PCAL1.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
function acc=Classify_PCAL1(x_train,x_test,label_train,label_test)
% PCA-L1
% 2DPCA with L1-norm for simultaneously robust and sparse modelling
% Copyright (C) 2013 Jing Wang
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
W=PCAL1(x_train);
nComp=size(W,2);
acc=zeros(nComp,1);
x_train_reserve=W'*x_train;
x_test_reserve=W'*x_test;
for iComp=1:nComp
x_train=x_train_reserve(1:iComp,:);
x_test=x_test_reserve(1:iComp,:);
dxx=pdist2(x_train',x_test');
[~,ix]=min(dxx);
acc(iComp)=mean(label_test==label_train(ix));
end