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