📄 testvsblockc.m
字号:
% TestVSblockC Test of VSblockC, vector selection done by program
% written in C an compiled to VSblockC.exe
% This m-file gives an example on how to use the fast vector selection
% program. We also use VSblock for comparison.
%----------------------------------------------------------------------
% Copyright (c) 2003. Karl Skretting. All rights reserved.
% Hogskolen in Stavanger (Stavanger University), Signal Processing Group
% Mail: karl.skretting@tn.his.no Homepage: http://www.ux.his.no/~karlsk/
%
% HISTORY: dd.mm.yyyy
% Ver. 1.0 15.05.2003 KS: function made
% Ver. 1.1 22.09.2003 KS: some changes
%----------------------------------------------------------------------
clear all
Mfile='TestVSblockC';
ErrMessage='ok';
TestVSab=0;
randn('state',2023);
N=32;
K=80;
F=randn(N,K);
F=NormalizeF(F);
FF=F'*F;
S=12;
L=3000;
X=randn(N,L);
if 1
X(:,2)=2*F(:,22)+0.3*F(:,12)+0.93*F(:,14);
end
x=X(:)'*X(:);
disp([Mfile,': (trace/Frobenius) norm of X (size ',int2str(N),'x',int2str(L),') : ',num2str(sqrt(x),'%5.2f')]);
%
% First test VSblockC
for i=[1,2,3,4,5];
tic;
W=VSblockC(X,F,S,i);
t2=toc;
R=X-F*W;
r=R(:)'*R(:);
w=W(:)'*W(:);
disp(['VSblockC using A',int2str(i),', S=',int2str(S),', time was ',num2str(t2,'%5.2f'),...
' seconds, norm(error)=',num2str(sqrt(r),'%5.1f'),', norm(weights)=',num2str(sqrt(w),'%5.1f')]);
%
if TestVSab % test VSab too
tic;
W=VSblockC(X,F,S,7);
t2=toc;
R=X-F*W;
r=R(:)'*R(:);
w=W(:)'*W(:);
disp(['VSblockC using A7, S=',int2str(S),', time was ',num2str(t2,'%5.2f'),...
' seconds, norm(error)=',num2str(sqrt(r),'%5.1f'),', norm(weights)=',num2str(sqrt(w),'%5.1f')]);
disp(' ');
end
end
for M=[5,20,50,200,500]; %,100,400,1000] % ca 200 s for M=1000 (L=2000, N=16, K=40, S=7)
tic;
W=VSblockC(X,F,S,6,M);
t2=toc;
R=X-F*W;
r=R(:)'*R(:);
w=W(:)'*W(:);
disp(['VSblockC using A6 M',int2str(M),', S=',int2str(S),', time was ',num2str(t2,'%5.2f'),...
' seconds, norm(error)=',num2str(sqrt(r),'%5.1f'),', norm(weights)=',num2str(sqrt(w),'%5.1f')]);
end
%
if TestVSab
tic;
W=VSblockC(X,F,S,7);
t2=toc;
R=X-F*W;
r=R(:)'*R(:);
w=W(:)'*W(:);
disp(['VSblockC using A7, S=',int2str(S),', time was ',num2str(t2,'%5.2f'),...
' seconds, norm(error)=',num2str(sqrt(r),'%5.1f'),', norm(weights)=',num2str(sqrt(w),'%5.1f')]);
disp(' ');
end
if 1 % test VSblock
Alg={'VSmp2','VSps2','VSomp','VSormp','VSormp2','VSfomp2'};
% (value for M for VSps2 is assigned inside VSblock)
for i=1:length(Alg);
tic;
W=VSblock(X,F,S*ones(1,L),Alg{i},1); % argument 5 is Blocksize (which is 1)
t2=toc;
R=X-F*W;
r=R(:)'*R(:);
w=W(:)'*W(:);
disp(['VSblock using ',Alg{i},', S=',int2str(S),', time was ',num2str(t2,'%5.2f'),...
' seconds, norm(error)=',num2str(sqrt(r),'%5.1f'),', norm(weights)=',num2str(sqrt(w),'%5.1f')]);
end
if TestVSab % test VSab too
tic;
W=VSblock(X,F,W,'VSab2',1); % argument 5 is Blocksize (which is 1)
t2=toc;
R=X-F*W;
r=R(:)'*R(:);
w=W(:)'*W(:);
disp(['VSblock using VSab2, S=',int2str(S),', time was ',num2str(t2,'%5.2f'),...
' seconds, norm(error)=',num2str(sqrt(r),'%5.1f'),', norm(weights)=',num2str(sqrt(w),'%5.1f')]);
disp(' ');
end
end
if L<=1000 % test of the recursive function VSps
P=ones(1,S);
P(1)=5;P(2)=4;
tic;
for l=1:L
W(:,l)=VSps(F,X(:,l),S,P);
end;
t2=toc;
R=X-F*W;
r=R(:)'*R(:);
disp(' ');
disp(['VSps (recursive in Matlab), prod(P)=',int2str(prod(P)),', time=',num2str(t2),...
', norm(error)=',num2str(sqrt(r))]);
end
if L<=2500 % test of the function VSps2
global F FF % this gives a warning
M=50;
tic;
for l=1:L
W(:,l)=VSps2(X(:,l),S,M);
end;
t2=toc;
R=X-F*W;
r=R(:)'*R(:);
disp(' ');
disp(['VSps2 M=',int2str(M),', time=',num2str(t2),', norm(error)=',num2str(sqrt(r))]);
end
return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -