comparison solvers/SMALL_cgp.m @ 22:524cc3fff5ac

(none)
author idamnjanovic
date Tue, 27 Apr 2010 13:32:27 +0000
parents 01cad25206d6
children 92a9b18c3bd3
comparison
equal deleted inserted replaced
21:0211faef9add 22:524cc3fff5ac
1 function [A, resF]=SMALL_cgp(Dict,X, m, maxNumCoef, errorGoal, varargin) 1 function [A, resF]=SMALL_cgp(Dict,X, m, maxNumCoef, errorGoal, varargin)
2 %============================================= 2 %%% Conjugate Gradient Pursuit Multiple vectors sparse representation
3 %
4 % Centre for Digital Music, Queen Mary, University of London.
5 % This file copyright 2009 Ivan Damnjanovic.
6 %
7 % This program is free software; you can redistribute it and/or
8 % modify it under the terms of the GNU General Public License as
9 % published by the Free Software Foundation; either version 2 of the
10 % License, or (at your option) any later version. See the file
11 % COPYING included with this distribution for more information.
12 %
3 % Sparse coding of a group of signals based on a given 13 % Sparse coding of a group of signals based on a given
4 % dictionary and specified number of atoms to use. 14 % dictionary and specified number of atoms to use.
5 % input arguments: Dict - the dictionary 15 % input arguments: Dict - the dictionary
6 % X - the signals to represent 16 % X - the signals to represent
7 % m - number of atoms in Dictionary 17 % m - number of atoms in Dictionary
11 % optional: if Dict is function handle then Transpose Dictionary 21 % optional: if Dict is function handle then Transpose Dictionary
12 % handle needs to be specified. 22 % handle needs to be specified.
13 % 23 %
14 % output arguments: A - sparse coefficient matrix. 24 % output arguments: A - sparse coefficient matrix.
15 % 25 %
16 % based on KSVD toolbox solver found on Miki Elad webpage (finding inverse
17 % with pinv() is changed with conjugate gradient method)
18 % Ivan Damnjanovic 2009
19 %=============================================
20 %%
21 %% 26 %%
22 27
23 % This Dictionary check is based on Thomas Blumensath work in sparsify 0_4 greedy solvers 28 % This Dictionary check is based on Thomas Blumensath work in sparsify 0_4 greedy solvers
24 if isa(Dict,'float') 29 if isa(Dict,'float')
25 D =@(z) Dict*z; 30 D =@(z) Dict*z;
41 end 46 end
42 else 47 else
43 error('Dictionary is of unsupported type. Use explicit matrix, function_handle or object. Exiting.'); 48 error('Dictionary is of unsupported type. Use explicit matrix, function_handle or object. Exiting.');
44 end 49 end
45 %% 50 %%
46 51 positivity=1;
47 [n,P]=size(X); 52 [n,P]=size(X);
48 53
49 54
50 55
51 A = sparse(m,size(X,2)); 56 A = sparse(m,size(X,2));
65 70
66 while j < maxNumCoef, 71 while j < maxNumCoef,
67 72
68 j = j+1; 73 j = j+1;
69 dir=Dt(residual); 74 dir=Dt(residual);
70 75 if exist('positivity','var')&&(positivity==1)
71 [tmp__, pos]=max(abs(dir)); 76 [tmp__, pos]=max(dir);
77 else
78 [tmp__, pos]=max(abs(dir));
79 end
72 indx(j)=pos; 80 indx(j)=pos;
73 81
74 p(indx)=dir(indx); 82 p(indx)=dir(indx);
75 Dp=D(p); 83 Dp=D(p);
76 pDDp=Dp'*Dp; 84 pDDp=Dp'*Dp;