annotate solvers/SMALL_MP.m @ 128:8e660fd14774 ivand_dev

Feature 186
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Mon, 13 Jun 2011 14:55:45 +0100
parents 524cc3fff5ac
children
rev   line source
idamnjanovic@3 1 function [A]=SMALL_MP(Dict,X, m, maxNumCoef, errorGoal, varargin)
ivan@128 2 %% Implementation of Matching Pursuit algorithm
ivan@128 3 % Sparse coding of a group of signals based on a given
ivan@128 4 % dictionary and specified number of atoms to use.
ivan@128 5 % input arguments: Dict - the dictionary
ivan@128 6 % X - the signals to represent
ivan@128 7 % m - number of atoms in Dictionary
ivan@128 8 % errorGoal - the maximal allowed representation error for
ivan@128 9 % each signal.
ivan@128 10 %
ivan@128 11 % optional: if Dict is function handle then Transpose Dictionary
ivan@128 12 % handle needs to be specified.
ivan@128 13 %
ivan@128 14
idamnjanovic@22 15 %
idamnjanovic@22 16 % Centre for Digital Music, Queen Mary, University of London.
idamnjanovic@22 17 % This file copyright 2009 Ivan Damnjanovic.
idamnjanovic@22 18 %
idamnjanovic@22 19 % This program is free software; you can redistribute it and/or
idamnjanovic@22 20 % modify it under the terms of the GNU General Public License as
idamnjanovic@22 21 % published by the Free Software Foundation; either version 2 of the
idamnjanovic@22 22 % License, or (at your option) any later version. See the file
idamnjanovic@22 23 % COPYING included with this distribution for more information.
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