annotate solvers/SMALL_MP.m @ 121:5ded5e2e7d07 ivand_dev

bug 159 Removed API for Skretting/Engang rlsdla
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Wed, 25 May 2011 13:33:47 +0100
parents 524cc3fff5ac
children 8e660fd14774
rev   line source
idamnjanovic@3 1 function [A]=SMALL_MP(Dict,X, m, maxNumCoef, errorGoal, varargin)
idamnjanovic@1 2 %%
idamnjanovic@22 3 %
idamnjanovic@22 4 % Centre for Digital Music, Queen Mary, University of London.
idamnjanovic@22 5 % This file copyright 2009 Ivan Damnjanovic.
idamnjanovic@22 6 %
idamnjanovic@22 7 % This program is free software; you can redistribute it and/or
idamnjanovic@22 8 % modify it under the terms of the GNU General Public License as
idamnjanovic@22 9 % published by the Free Software Foundation; either version 2 of the
idamnjanovic@22 10 % License, or (at your option) any later version. See the file
idamnjanovic@22 11 % COPYING included with this distribution for more information.
idamnjanovic@22 12 %
idamnjanovic@1 13 % Sparse coding of a group of signals based on a given
idamnjanovic@1 14 % dictionary and specified number of atoms to use.
idamnjanovic@1 15 % input arguments: Dict - the dictionary
idamnjanovic@1 16 % X - the signals to represent
idamnjanovic@1 17 % m - number of atoms in Dictionary
idamnjanovic@1 18 % errorGoal - the maximal allowed representation error for
idamnjanovic@1 19 % each signal.
idamnjanovic@1 20 %
idamnjanovic@1 21 % optional: if Dict is function handle then Transpose Dictionary
idamnjanovic@1 22 % handle needs to be specified.
idamnjanovic@1 23 %
idamnjanovic@22 24
idamnjanovic@1 25 %%
idamnjanovic@1 26 % This Dictionary check is based on Thomas Blumensath work in sparsify 0_4 greedy solvers
idamnjanovic@1 27 explicitD=0;
idamnjanovic@1 28 if isa(Dict,'float')
idamnjanovic@1 29 D =@(z) Dict*z;
idamnjanovic@1 30 Dt =@(z) Dict'*z;
idamnjanovic@1 31 explicitD=1;
idamnjanovic@1 32 elseif isobject(Dict)
idamnjanovic@1 33 D =@(z) Dict*z;
idamnjanovic@1 34 Dt =@(z) Dict'*z;
idamnjanovic@1 35 elseif isa(Dict,'function_handle')
idamnjanovic@1 36 try
idamnjanovic@1 37 DictT=varargin{1};
idamnjanovic@1 38 if isa(DictT,'function_handle');
idamnjanovic@1 39 D=Dict;
idamnjanovic@1 40 Dt=DictT;
idamnjanovic@1 41 else
idamnjanovic@1 42 error('If Dictionary is a function handle,Transpose Dictionary also needs to be a function handle. ');
idamnjanovic@1 43 end
idamnjanovic@1 44 catch
idamnjanovic@1 45 error('If Dictionary is a function handle, Transpose Dictionary needs to be specified. Exiting.');
idamnjanovic@1 46 end
idamnjanovic@1 47 else
idamnjanovic@1 48 error('Dictionary is of unsupported type. Use explicit matrix, function_handle or object. Exiting.');
idamnjanovic@1 49 end
idamnjanovic@1 50 %%
idamnjanovic@1 51 [n,P]=size(X);
idamnjanovic@1 52
idamnjanovic@2 53 %E2 = errorGoal^2;
idamnjanovic@1 54
idamnjanovic@1 55
idamnjanovic@1 56 A = sparse(m,size(X,2));
idamnjanovic@1 57 for k=1:1:P,
idamnjanovic@1 58
idamnjanovic@1 59 x = X(:,k);
idamnjanovic@1 60 residual=x;
idamnjanovic@1 61 indx = [];
idamnjanovic@1 62 j=0;
idamnjanovic@1 63
idamnjanovic@1 64 currResNorm = norm(residual);
idamnjanovic@3 65 errGoal=errorGoal*currResNorm;
idamnjanovic@1 66
idamnjanovic@1 67 a = zeros(m,1);
idamnjanovic@1 68
idamnjanovic@1 69
idamnjanovic@3 70 while currResNorm>errGoal && j < maxNumCoef,
idamnjanovic@1 71
idamnjanovic@1 72 j = j+1;
idamnjanovic@1 73 dir=Dt(residual);
idamnjanovic@1 74
idamnjanovic@1 75 [tmp__, pos]=max(abs(dir));
idamnjanovic@1 76 indx(j)=pos;
idamnjanovic@1 77 a(pos)=dir(pos);
idamnjanovic@1 78 e = zeros(m,1);
idamnjanovic@1 79 e(pos) = 1;
idamnjanovic@1 80 residual=residual-D(e)*a(pos);
idamnjanovic@1 81
idamnjanovic@1 82 currResNorm = norm(residual);
idamnjanovic@1 83 end;
idamnjanovic@1 84 if (~isempty(indx))
idamnjanovic@1 85 A(indx,k)=a(indx);
idamnjanovic@1 86 end
idamnjanovic@1 87 end;
idamnjanovic@1 88 return;
idamnjanovic@1 89
idamnjanovic@1 90