annotate util/ksvd utils/ompbox utils/ompGabor.m @ 138:56d719a5fd31 ivand_dev

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