-
Notifications
You must be signed in to change notification settings - Fork 10
/
RE_PCAL1.m
50 lines (44 loc) · 1.56 KB
/
RE_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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function err=RE_PCAL1(x_noise,ix_noise,kSet)
% calculating the reconstruction error by 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/>.
nSub=size(x_noise,3);
xv_noise=reshape(x_noise,numel(x_noise)/nSub,nSub); % reshape data as a vector
xv_mean=mean(xv_noise,2);
xv_centered=xv_noise-repmat(xv_mean,[1,nSub]);
W=PCAL1(xv_centered);
% reconstruct the iSub-th image by the first iK-th components
nK=length(kSet);
xv_reco=zeros(size(xv_noise));
err=zeros(nK,1);
tic;
for iK=1:nK
w=W(:,1:kSet(iK));
for iSub=1:nSub
xv_reco(:,iSub)=w*w'*xv_centered(:,iSub)+xv_mean;
end
temp=xv_noise-xv_reco(:,:);
sum=0;
for iSub=nSub/5+1:nSub
sum=sum+norm(temp(:,ix_noise(iSub)));
end
err(iK)=sum/(nSub*4/5);
perct(toc,iK,nK);
end
figure;
plot(kSet,err,'-o');
title('RE\_PCAL1');
save('ERR_PCAL1.mat','err');