comparison solvers/SMALL_ompGabor/ompGabor.m @ 140:31d2864dfdd4 ivand_dev

Audio Impainting additional constraints with cvx added
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Mon, 25 Jul 2011 17:27:05 +0100
parents
children
comparison
equal deleted inserted replaced
139:4bd6856a7128 140:31d2864dfdd4
1 function gamma = omp(varargin)
2 %OMP Sparsity-constrained Orthogonal Matching Pursuit.
3 % GAMMA = OMP(D,X,G,T) solves the optimization problem
4 %
5 % min |X - D*GAMMA|_2 s.t. |GAMMA|_0 <= T
6 % gamma
7 %
8 % for each of the signals in X, using Batch Orthogonal Matching Pursuit.
9 % Here, D is a dictionary with normalized columns, X is a matrix
10 % containing column signals, T is the # of non-zeros in each signal
11 % representation, and G is the Gramm matrix D'*D. The output GAMMA is a
12 % matrix containing the sparse representations as its columns.
13 %
14 % GAMMA = OMP(D,X,[],T) performs the same operation, but without the
15 % matrix G, using OMP-Cholesky. This call produces the same output as
16 % Batch-OMP, but is significantly slower. Using this syntax is only
17 % recommended when available memory is too small to store G.
18 %
19 % GAMMA = OMP(DtX,G,T) is the fastest implementation of OMP, but also
20 % requires the most memory. Here, DtX stores the projections D'*X. In this
21 % case Batch-OMP is used, but without having to compute D'*X in advance,
22 % which slightly improves runtime. Note that in general, the call
23 %
24 % GAMMA = OMP(D'*X,G,T);
25 %
26 % will be faster than the call
27 %
28 % GAMMA = OMP(D,X,G,T);
29 %
30 % due to optimized matrix multiplications in Matlab. However, when the
31 % entire matrix D'*X cannot be stored in memory, one of the other two
32 % versions can be used. Both compute D'*X for just one signal at a time,
33 % and thus require much less memory.
34 %
35 % GAMMA = OMP(...,PARAM1,VAL1,PARAM2,VAL2,...) specifies additional
36 % parameters for OMP. Available parameters are:
37 %
38 % 'gammamode' - Specifies the representation mode for GAMMA. Can be
39 % either 'full' or 'sparse', corresponding to a full or
40 % sparse matrix, respectively. By default, GAMMA is
41 % returned as a sparse matrix.
42 % 'messages' - Specifies whether progress messages should be displayed.
43 % When positive, this is the number of seconds between
44 % status prints. When negative, indicates that no messages
45 % should be displayed (this is the default).
46 % 'checkdict' - Specifies whether dictionary normalization should be
47 % verified. When set to 'on' (default) the dictionary
48 % atoms are verified to be of unit L2-norm. Setting this
49 % parameter to 'off' disables verification and accelerates
50 % function performance. Note that an unnormalized
51 % dictionary will produce invalid results.
52 % 'profile' - Can be either 'on' or 'off'. When 'on', profiling
53 % information is displayed at the end of the funciton
54 % execution.
55 %
56 %
57 % Summary of OMP versions:
58 %
59 % version | speed | memory
60 % --------------------------------------------------
61 % OMP(DtX,G,T) | very fast | very large
62 % OMP(D,X,G,T) | fast | moderate
63 % OMP(D,X,[],T) | very slow | small
64 % --------------------------------------------------
65 %
66 %
67 % References:
68 % [1] M. Elad, R. Rubinstein, and M. Zibulevsky, "Efficient Implementation
69 % of the K-SVD Algorithm using Batch Orthogonal Matching Pursuit",
70 % Technical Report - CS, Technion, April 2008.
71 %
72 % See also OMP2.
73
74
75 % Ron Rubinstein
76 % Computer Science Department
77 % Technion, Haifa 32000 Israel
78 % ronrubin@cs
79 %
80 % April 2009
81
82
83 % default options
84
85 sparse_gamma = 1;
86 msgdelta = -1;
87 checkdict = 1;
88 profile = 0;
89
90
91 % determine number of parameters
92
93 paramnum = 1;
94 while (paramnum<=nargin && ~ischar(varargin{paramnum}))
95 paramnum = paramnum+1;
96 end
97 paramnum = paramnum-1;
98
99
100 % parse options
101
102 for i = paramnum+1:2:length(varargin)
103 paramname = varargin{i};
104 paramval = varargin{i+1};
105
106 switch lower(paramname)
107
108 case 'gammamode'
109 if (strcmpi(paramval,'sparse'))
110 sparse_gamma = 1;
111 elseif (strcmpi(paramval,'full'))
112 sparse_gamma = 0;
113 else
114 error('Invalid GAMMA mode');
115 end
116
117 case 'messages'
118 msgdelta = paramval;
119
120 case 'checkdict'
121 if (strcmpi(paramval,'on'))
122 checkdict = 1;
123 elseif (strcmpi(paramval,'off'))
124 checkdict = 0;
125 else
126 error('Invalid checkdict option');
127 end
128
129 case 'profile'
130 if (strcmpi(paramval,'on'))
131 profile = 1;
132 elseif (strcmpi(paramval,'off'))
133 profile = 0;
134 else
135 error('Invalid profile mode');
136 end
137
138 otherwise
139 error(['Unknown option: ' paramname]);
140 end
141
142 end
143
144
145 % determine call type
146
147 if (paramnum==3)
148 DtX = varargin{1};
149 G = varargin{2};
150 T = varargin{3};
151 D = [];
152 X = [];
153 elseif (paramnum==4)
154 D = varargin{1};
155 X = varargin{2};
156 G = varargin{3};
157 T = varargin{4};
158 DtX = [];
159 else
160 error('Invalid number of parameters');
161 end
162
163
164 % verify dictionary normalization
165
166 if (checkdict)
167 if (isempty(G))
168 atomnorms = sum(D.*D);
169 else
170 atomnorms = diag(G);
171 end
172 if (any(abs(atomnorms-1) > 1e-2))
173 error('Dictionary columns must be normalized to unit length');
174 end
175 end
176
177
178 % omp
179
180 gamma = ompmexGabor(D,X,DtX,G,T,sparse_gamma,msgdelta,profile);