-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreco_GPCA.m
63 lines (49 loc) · 1.72 KB
/
reco_GPCA.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
57
58
59
60
61
62
63
function reco_GPCA(database,iS,iP)
% Calculate the reconstruction error of GPCA.
% Generalized two dimensional principal component analysis by Lp-norm for image analysis
% Copyright (C) 2015 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/>.
fprintf('reco_GPCA_par(%s,%d,%d)\n\n',database,iS,iP);
tic;
load(sprintf('data/%s_noise.mat',database));
[height,width,nSub]=size(x_noise);
x_noise=reshape(x_noise,[height*width,nSub]);
x_mean=mean(x_noise,2);
x_centered=x_noise-repmat(x_mean,1,nSub);
sS=[1:0.1:3];
nS=length(sS);
sP=[0.9:0.1:3];
nP=length(sP);
nPV=30; % the first 30 projection vectors are considered
s=sS(iS);
p=sP(iP);
W=GPCA(x_centered,s,p,nPV);
err=zeros(nPV,1);
for iPV=1:nPV
w=W(:,1:iPV);
x_reco=zeros(size(x_noise));
for iSub=1:nSub
x_reco(:,iSub)=w*w'*x_centered(:,iSub)+x_mean;
end
temp=x_noise-x_reco;
rsd=0;
for iSub=nSub/5+1:nSub
rsd=rsd+norm(temp(:,ix_noise(iSub)));
end
err(iPV)=rsd/(nSub*4/5);
perct(toc,iPV,nPV);
end
time=toc/60;
save(sprintf('result/reco_GPCA_%s_iS%d_iP%d.mat',database,iS,iP),'err','time');