annotate solvers/SMALL_MP.m @ 2:257c289bf11d

(none)
author idamnjanovic
date Fri, 05 Mar 2010 12:23:57 +0000
parents 7750624e0c73
children 01cad25206d6
rev   line source
idamnjanovic@2 1 function [A]=SMALL_MP(Dict,X, m, maxNumCoef, errorGoal1, varargin)
idamnjanovic@1 2 %%
idamnjanovic@1 3 %=============================================
idamnjanovic@1 4 % Sparse coding of a group of signals based on a given
idamnjanovic@1 5 % dictionary and specified number of atoms to use.
idamnjanovic@1 6 % input arguments: Dict - the dictionary
idamnjanovic@1 7 % X - the signals to represent
idamnjanovic@1 8 % m - number of atoms in Dictionary
idamnjanovic@1 9 % errorGoal - the maximal allowed representation error for
idamnjanovic@1 10 % each signal.
idamnjanovic@1 11 %
idamnjanovic@1 12 % optional: if Dict is function handle then Transpose Dictionary
idamnjanovic@1 13 % handle needs to be specified.
idamnjanovic@1 14 %
idamnjanovic@1 15 % based on KSVD toolbox solver found on Miki Elad webpage (finding inverse
idamnjanovic@1 16 % with pinv() is changed with matching pursuit)
idamnjanovic@1 17 % Ivan Damnjanovic 2009
idamnjanovic@1 18 %=============================================
idamnjanovic@1 19 %%
idamnjanovic@1 20 %%
idamnjanovic@1 21 % This Dictionary check is based on Thomas Blumensath work in sparsify 0_4 greedy solvers
idamnjanovic@1 22 explicitD=0;
idamnjanovic@1 23 if isa(Dict,'float')
idamnjanovic@1 24 D =@(z) Dict*z;
idamnjanovic@1 25 Dt =@(z) Dict'*z;
idamnjanovic@1 26 explicitD=1;
idamnjanovic@1 27 elseif isobject(Dict)
idamnjanovic@1 28 D =@(z) Dict*z;
idamnjanovic@1 29 Dt =@(z) Dict'*z;
idamnjanovic@1 30 elseif isa(Dict,'function_handle')
idamnjanovic@1 31 try
idamnjanovic@1 32 DictT=varargin{1};
idamnjanovic@1 33 if isa(DictT,'function_handle');
idamnjanovic@1 34 D=Dict;
idamnjanovic@1 35 Dt=DictT;
idamnjanovic@1 36 else
idamnjanovic@1 37 error('If Dictionary is a function handle,Transpose Dictionary also needs to be a function handle. ');
idamnjanovic@1 38 end
idamnjanovic@1 39 catch
idamnjanovic@1 40 error('If Dictionary is a function handle, Transpose Dictionary needs to be specified. Exiting.');
idamnjanovic@1 41 end
idamnjanovic@1 42 else
idamnjanovic@1 43 error('Dictionary is of unsupported type. Use explicit matrix, function_handle or object. Exiting.');
idamnjanovic@1 44 end
idamnjanovic@1 45 %%
idamnjanovic@1 46 [n,P]=size(X);
idamnjanovic@1 47
idamnjanovic@2 48 %E2 = errorGoal^2;
idamnjanovic@1 49
idamnjanovic@1 50
idamnjanovic@1 51 A = sparse(m,size(X,2));
idamnjanovic@1 52 for k=1:1:P,
idamnjanovic@1 53
idamnjanovic@1 54 x = X(:,k);
idamnjanovic@1 55 residual=x;
idamnjanovic@1 56 indx = [];
idamnjanovic@1 57 j=0;
idamnjanovic@1 58
idamnjanovic@1 59 currResNorm = norm(residual);
idamnjanovic@2 60 errorGoal=errorGoal1*currResNorm;
idamnjanovic@1 61
idamnjanovic@1 62 a = zeros(m,1);
idamnjanovic@1 63
idamnjanovic@1 64
idamnjanovic@1 65 while currResNorm>errorGoal & j < maxNumCoef,
idamnjanovic@1 66
idamnjanovic@1 67 j = j+1;
idamnjanovic@1 68 dir=Dt(residual);
idamnjanovic@1 69
idamnjanovic@1 70 [tmp__, pos]=max(abs(dir));
idamnjanovic@1 71 indx(j)=pos;
idamnjanovic@1 72 a(pos)=dir(pos);
idamnjanovic@1 73 e = zeros(m,1);
idamnjanovic@1 74 e(pos) = 1;
idamnjanovic@1 75 residual=residual-D(e)*a(pos);
idamnjanovic@1 76
idamnjanovic@1 77 currResNorm = norm(residual);
idamnjanovic@1 78 end;
idamnjanovic@1 79 if (~isempty(indx))
idamnjanovic@1 80 A(indx,k)=a(indx);
idamnjanovic@1 81 end
idamnjanovic@1 82 end;
idamnjanovic@1 83 return;
idamnjanovic@1 84
idamnjanovic@1 85