Mercurial > hg > smallbox
comparison util/classes/dictionaryMatrices/shrinkgram.m @ 171:e8428989412f danieleb
Added dictionary decorrelation functions and test script for Letters paper.
author | Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk> |
---|---|
date | Thu, 06 Oct 2011 14:33:52 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
170:68fb71aa5339 | 171:e8428989412f |
---|---|
1 function [dic mus] = shrinkgram(dic,mu,dd1,dd2,params) | |
2 % grassmanian attempts to create an n by m matrix with minimal mutual | |
3 % coherence using an iterative projection method. | |
4 % | |
5 % [A G res] = grassmanian(n,m,nIter,dd1,dd2,initA) | |
6 % | |
7 % REFERENCE | |
8 % M. Elad, Sparse and Redundant Representations, Springer 2010. | |
9 | |
10 %% Parameters and Defaults | |
11 if ~nargin, testshrinkgram; return; end | |
12 | |
13 if ~exist('dd2','var') || isempty(dd2), dd2 = 0.9; end %shrinking factor | |
14 if ~exist('dd1','var') || isempty(dd1), dd1 = 0.9; end %percentage of coherences to be shrinked | |
15 if ~exist('params','var') || isempty(params), params = struct; end | |
16 if ~isfield(params,'nIter'), params.nIter = 100; end | |
17 | |
18 %% Main algo | |
19 dic = normc(dic); %normalise columns | |
20 G = dic'*dic; %gram matrix | |
21 [n m] = size(dic); | |
22 | |
23 MU = @(G) max(max(abs(G-diag(diag(G))))); %coherence function | |
24 | |
25 mus = ones(params.nIter,1); | |
26 iIter = 1; | |
27 % optimise gram matrix | |
28 while iIter<=params.nIter && MU(G)>mu | |
29 mus(iIter) = MU(G); %calculate coherence | |
30 gg = sort(abs(G(:))); %sort inner products from less to most correlated | |
31 pos = find(abs(G(:))>=gg(round(dd1*(m^2-m))) & abs(G(:)-1)>1e-6); %find large elements of gram matrix | |
32 G(pos) = G(pos)*dd2; %shrink large elements of gram matrix | |
33 [U S V] = svd(G); %compute new SVD of gram matrix | |
34 S(n+1:end,1+n:end) = 0; %set small eigenvalues to zero (this ensures rank(G)<=d) | |
35 G = U*S*V'; %update gram matrix | |
36 G = diag(1./abs(sqrt(diag(G))))*G*diag(1./abs(sqrt(diag(G)))); %normalise gram matrix diagonal | |
37 iIter = iIter+1; | |
38 end | |
39 %if iIter<params.nIter | |
40 % mus(iIter:end) = mus(iIter-1); | |
41 %end | |
42 | |
43 [V_gram Sigma_gram] = svd(G); %calculate svd decomposition of gramian | |
44 dic = sqrt(Sigma_gram(1:n,:))*V_gram'; %update dictionary | |
45 | |
46 function testshrinkgram | |
47 clc | |
48 %define parameters | |
49 n = 256; %ambient dimension | |
50 m = 512; %number of atoms | |
51 N = 1024; %number of signals | |
52 mu_min = sqrt((m-n)/(n*(m-1))); %minimum coherence | |
53 | |
54 %initialise data | |
55 phi = normc(randn(n,m)); %dictionary | |
56 | |
57 %optimise dictionary | |
58 [~, mus] = shrinkgram(phi,0.2); | |
59 | |
60 %plot results | |
61 nIter = length(mus); | |
62 | |
63 figure, hold on | |
64 plot(1:nIter,mus,'ko-'); | |
65 plot([1 nIter],[mu_min mu_min],'k') | |
66 grid on | |
67 legend('\mu','\mu_{min}'); |