Mercurial > hg > smallbox
comparison solvers/SMALL_ompGabor/omp2Gabor.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 = omp2Gabor(varargin) | |
2 %% omp2Gabor Error-constrained Orthogonal Matching Pursuit. | |
3 % | |
4 % This file is part of SMALLbox [2] and it is adaptation of Ron | |
5 % Rubenstein omp solver [1] for Gabor dictionary as defined in | |
6 % Audio Inpainting by Adler et al [3]. The dictionary is presented as | |
7 % DCT+DST and solver pics two atoms per iteration (given the frequency one | |
8 % from DCT and one from DST). For more information look in [3]. | |
9 % | |
10 % GAMMA = OMP2(D,X,G,EPSILON) solves the optimization problem | |
11 % | |
12 % min |GAMMA|_0 s.t. |X - D*GAMMA|_2 <= EPSILON | |
13 % gamma | |
14 % | |
15 % for each of the signals in X, using Batch Orthogonal Matching Pursuit. | |
16 % Here, D is a dictionary with normalized columns, X is a matrix | |
17 % containing column signals, EPSILON is the error target for each signal, | |
18 % and G is the Gramm matrix D'*D. The output GAMMA is a matrix containing | |
19 % the sparse representations as its columns. | |
20 % | |
21 % GAMMA = OMP2(D,X,[],EPSILON) performs the same operation, but without | |
22 % the matrix G, using OMP-Cholesky. This call produces the same output as | |
23 % Batch-OMP, but is significantly slower. Using this syntax is only | |
24 % recommended when available memory is too small to store G. | |
25 % | |
26 % GAMMA = OMP2(DtX,XtX,G,EPSILON) is the fastest implementation of OMP2, | |
27 % but also requires the most memory. Here, DtX stores the projections | |
28 % D'*X, and XtX is a row vector containing the squared norms of the | |
29 % signals, sum(X.*X). In this case Batch-OMP is used, but without having | |
30 % to compute D'*X and XtX in advance, which slightly improves runtime. | |
31 % Note that in general, the call | |
32 % | |
33 % GAMMA = OMP2(D'*X, sum(X.*X), G, EPSILON); | |
34 % | |
35 % will be faster than the call | |
36 % | |
37 % GAMMA = OMP2(D,X,G,EPSILON); | |
38 % | |
39 % due to optimized matrix multiplications in Matlab. However, when the | |
40 % entire matrix D'*X cannot be stored in memory, one of the other two | |
41 % versions can be used. Both compute D'*X for just one signal at a time, | |
42 % and thus require much less memory. | |
43 % | |
44 % GAMMA = OMP2(...,PARAM1,VAL1,PARAM2,VAL2,...) specifies additional | |
45 % parameters for OMP2. Available parameters are: | |
46 % | |
47 % 'gammamode' - Specifies the representation mode for GAMMA. Can be | |
48 % either 'full' or 'sparse', corresponding to a full or | |
49 % sparse matrix, respectively. By default, GAMMA is | |
50 % returned as a sparse matrix. | |
51 % 'maxatoms' - Limits the number of atoms in the representation of each | |
52 % signal. If specified, the number of atoms in each | |
53 % representation does not exceed this number, even if the | |
54 % error target is not met. Specifying maxatoms<0 implies | |
55 % no limit (default). | |
56 % 'messages' - Specifies whether progress messages should be displayed. | |
57 % When positive, this is the number of seconds between | |
58 % status prints. When negative, indicates that no messages | |
59 % should be displayed (this is the default). | |
60 % 'checkdict' - Specifies whether dictionary normalization should be | |
61 % verified. When set to 'on' (default) the dictionary | |
62 % atoms are verified to be of unit L2-norm. Setting this | |
63 % parameter to 'off' disables verification and accelerates | |
64 % function performance. Note that an unnormalized | |
65 % dictionary will produce invalid results. | |
66 % 'profile' - Can be either 'on' or 'off'. When 'on', profiling | |
67 % information is displayed at the end of the funciton | |
68 % execution. | |
69 % | |
70 % | |
71 % Summary of OMP2 versions: | |
72 % | |
73 % version | speed | memory | |
74 % ------------------------------------------------------------- | |
75 % OMP2(DtX,XtX,G,EPSILON) | very fast | very large | |
76 % OMP2(D,X,G,EPSILON) | fast | moderate | |
77 % OMP2(D,X,[],EPSILON) | very slow | small | |
78 % ------------------------------------------------------------- | |
79 % | |
80 % | |
81 % References: | |
82 % [1] M. Elad, R. Rubinstein, and M. Zibulevsky, "Efficient Implementation | |
83 % of the K-SVD Algorithm using Batch Orthogonal Matching Pursuit", | |
84 % Technical Report - CS, Technion, April 2008. | |
85 % | |
86 % See also OMP. | |
87 | |
88 | |
89 % Ron Rubinstein | |
90 % Computer Science Department | |
91 % Technion, Haifa 32000 Israel | |
92 % ronrubin@cs | |
93 % | |
94 % April 2009 | |
95 | |
96 % | |
97 % Centre for Digital Music, Queen Mary, University of London. | |
98 % This file copyright 2011 Ivan Damnjanovic. | |
99 % | |
100 % This program is free software; you can redistribute it and/or | |
101 % modify it under the terms of the GNU General Public License as | |
102 % published by the Free Software Foundation; either version 2 of the | |
103 % License, or (at your option) any later version. See the file | |
104 % COPYING included with this distribution for more information. | |
105 %% | |
106 | |
107 % default options | |
108 | |
109 sparse_gamma = 1; | |
110 msgdelta = -1; | |
111 maxatoms = -1; | |
112 checkdict = 1; | |
113 profile = 0; | |
114 | |
115 | |
116 % determine number of parameters | |
117 | |
118 paramnum = 1; | |
119 while (paramnum<=nargin && ~ischar(varargin{paramnum})) | |
120 paramnum = paramnum+1; | |
121 end | |
122 paramnum = paramnum-1; | |
123 | |
124 | |
125 % parse options | |
126 | |
127 for i = paramnum+1:2:length(varargin) | |
128 paramname = varargin{i}; | |
129 paramval = varargin{i+1}; | |
130 | |
131 switch lower(paramname) | |
132 | |
133 case 'gammamode' | |
134 if (strcmpi(paramval,'sparse')) | |
135 sparse_gamma = 1; | |
136 elseif (strcmpi(paramval,'full')) | |
137 sparse_gamma = 0; | |
138 else | |
139 error('Invalid GAMMA mode'); | |
140 end | |
141 | |
142 case 'maxatoms' | |
143 maxatoms = paramval; | |
144 | |
145 case 'messages' | |
146 msgdelta = paramval; | |
147 | |
148 case 'checkdict' | |
149 if (strcmpi(paramval,'on')) | |
150 checkdict = 1; | |
151 elseif (strcmpi(paramval,'off')) | |
152 checkdict = 0; | |
153 else | |
154 error('Invalid checkdict option'); | |
155 end | |
156 | |
157 case 'profile' | |
158 if (strcmpi(paramval,'on')) | |
159 profile = 1; | |
160 elseif (strcmpi(paramval,'off')) | |
161 profile = 0; | |
162 else | |
163 error('Invalid profile mode'); | |
164 end | |
165 | |
166 otherwise | |
167 error(['Unknown option: ' paramname]); | |
168 end | |
169 | |
170 end | |
171 | |
172 | |
173 % determine call type | |
174 | |
175 if (paramnum==4) | |
176 | |
177 n1 = size(varargin{1},1); | |
178 n2 = size(varargin{2},1); | |
179 n3 = size(varargin{3},1); | |
180 | |
181 if ( (n1>1 && n2==1) || (n1==1 && n2==1 && n3==1) ) % DtX,XtX,G,EPSILON | |
182 | |
183 DtX = varargin{1}; | |
184 XtX = varargin{2}; | |
185 G = varargin{3}; | |
186 epsilon = varargin{4}; | |
187 D = []; | |
188 X = []; | |
189 | |
190 else % D,X,G,EPSILON | |
191 | |
192 D = varargin{1}; | |
193 X = varargin{2}; | |
194 G = varargin{3}; | |
195 epsilon = varargin{4}; | |
196 DtX = []; | |
197 XtX = []; | |
198 | |
199 end | |
200 | |
201 else | |
202 error('Invalid number of parameters'); | |
203 end | |
204 | |
205 G=[]; | |
206 | |
207 % verify dictionary normalization | |
208 | |
209 if (checkdict) | |
210 if (isempty(G)) | |
211 atomnorms = sum(D.*D); | |
212 else | |
213 atomnorms = diag(G); | |
214 end | |
215 if (any(abs(atomnorms-1) > 1e-2)) | |
216 error('Dictionary columns must be normalized to unit length'); | |
217 end | |
218 end | |
219 | |
220 | |
221 % omp | |
222 | |
223 gamma = omp2mexGabor(D,X,DtX,XtX,G,epsilon,sparse_gamma,msgdelta,maxatoms,profile); |