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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
function test_failed=test_thresh
%-*- texinfo -*-
%@deftypefn {Function} test_thresh
%@verbatim
%TEST_THRESH Compare sparse and full thesholding
%@end verbatim
%@strong{Url}: @url{http://ltfat.github.io/doc/testing/test_thresh.html}
%@end deftypefn
% Copyright (C) 2005-2016 Peter L. Soendergaard <peter@sonderport.dk>.
% This file is part of LTFAT version 2.2.0
%
% 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/>.
test_failed=0;
disp(' =============== TEST_THRESH ================');
global LTFAT_TEST_TYPE;
if ~strcmpi(LTFAT_TEST_TYPE,'double')
disp(sprintf('Skipping. Cannot work with sparse matrices of type %s.',LTFAT_TEST_TYPE));
return;
end
lambda=0.1;
ttypes={'hard','soft','wiener'};
for ii=1:2
if ii==1
g=tester_rand(3,4);
field='REAL ';
g(2,2)=lambda;
else
g=tester_crand(3,4);
field='CMPLX ';
g(2,2)=lambda;
end;
for jj=1:3
ttype=ttypes{jj};
[xo_full, Nfull] = thresh(g,lambda,ttype,'full');
[xo_sparse, Nsp] = thresh(g,lambda,ttype,'sparse');
res = xo_full-xo_sparse;
res = norm(res(:));
res2 = Nfull-Nsp;
[test_failed,fail]=ltfatdiditfail(res,test_failed);
s=sprintf(['THRESH %s %s %0.5g %s'],field,ttype,res,fail);
disp(s);
[test_failed,fail]=ltfatdiditfail(res2,test_failed);
s=sprintf(['THRESH N %s %s %0.5g %s'],field,ttype,res2,fail);
disp(s);
% Extend lambda to:
% a) Vector
lambdavec = lambda*ones(numel(g),1);
[xo_full2, Nfull2] = thresh(g,lambdavec,ttype,'full');
[xo_sparse2, Nsp2] = thresh(g,lambdavec,ttype,'sparse');
res_full = xo_full2-xo_full;
res_sparse = xo_sparse2-xo_sparse;
res_full = norm(res_full(:));
res_sparse = norm(res_sparse(:));
res_nfull = Nfull2-Nfull;
res_nsparse = Nfull2-Nfull;
[test_failed,fail]=ltfatdiditfail(res,test_failed);
s=sprintf(['THRESH VEC FULL %s %s %0.5g %s'],field,ttype,res_full,fail);
disp(s);
[test_failed,fail]=ltfatdiditfail(res,test_failed);
s=sprintf(['THRESH VEC SPARSE %s %s %0.5g %s'],field,ttype,res_sparse,fail);
disp(s);
[test_failed,fail]=ltfatdiditfail(res2,test_failed);
s=sprintf(['THRESH VEC N FULL %s %s %0.5g %s'],field,ttype,res_nfull,fail);
disp(s);
[test_failed,fail]=ltfatdiditfail(res2,test_failed);
s=sprintf(['THRESH VEC N SPARSE %s %s %0.5g %s'],field,ttype,res_nsparse,fail);
disp(s);
% b) Same shape as g
lambdamat = lambda*ones(size(g));
[xo_full3, Nfull3] = thresh(g,lambdamat,ttype,'full');
[xo_sparse3, Nsp3] = thresh(g,lambdamat,ttype,'sparse');
res_full = xo_full3-xo_full;
res_sparse = xo_sparse3-xo_sparse;
res_full = norm(res_full(:));
res_sparse = norm(res_sparse(:));
res_nfull = Nfull3-Nfull;
res_nsparse = Nfull3-Nfull;
[test_failed,fail]=ltfatdiditfail(res,test_failed);
s=sprintf(['THRESH MAT FULL %s %s %0.5g %s'],field,ttype,res_full,fail);
disp(s);
[test_failed,fail]=ltfatdiditfail(res,test_failed);
s=sprintf(['THRESH MAT SPARSE %s %s %0.5g %s'],field,ttype,res_sparse,fail);
disp(s);
[test_failed,fail]=ltfatdiditfail(res2,test_failed);
s=sprintf(['THRESH MAT N FULL %s %s %0.5g %s'],field,ttype,res_nfull,fail);
disp(s);
[test_failed,fail]=ltfatdiditfail(res2,test_failed);
s=sprintf(['THRESH MAT N SPARSE %s %s %0.5g %s'],field,ttype,res_nsparse,fail);
disp(s);
end;
end;
|