comparison util/classes/dictionaryMatrices/iterativeprojections.m @ 170:68fb71aa5339 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:41 +0100
parents 290cca7d3469
children 8fc38e8df8c6
comparison
equal deleted inserted replaced
169:290cca7d3469 170:68fb71aa5339
1 function [A G res muMin] = grassmannian(n,m,nIter,dd1,dd2,initA,verb) 1 function [dic mus srs] = iterativeprojections(dic,mu,Y,X,params)
2 % grassmanian attempts to create an n by m matrix with minimal mutual 2 % grassmanian attempts to create an n by m matrix with minimal mutual
3 % coherence using an iterative projection method. 3 % coherence using an iterative projection method.
4 % 4 %
5 % [A G res] = grassmanian(n,m,nIter,dd1,dd2,initA) 5 % REFERENCE
6 % 6 %
7 % REFERENCE
8 % M. Elad, Sparse and Redundant Representations, Springer 2010.
9 7
10 %% Parameters and Defaults 8 %% Parameters and Defaults
11 error(nargchk(2,7,nargin)); 9 if ~nargin, testiterativeprojections; return; end
12 10
13 if ~exist('verb','var') || isempty(verb), verb = false; end %verbose output 11 if ~exist('params','var') || isempty(param), params = struct; end
14 if ~exist('initA','var') || isempty(initA), initA = randn(n,m); end %initial matrix 12 if ~isfield(params,'nIter'), params.nIter = 10; end %number of iterations
15 if ~exist('dd2','var') || isempty(dd2), dd2 = 0.99; end %shrinking factor 13 if ~isfield(params,'eps'), params.eps = 1e-9; end %tolerance level
16 if ~exist('dd1','var') || isempty(dd1), dd1 = 0.9; end %percentage of coherences to be shrinked 14 [n m] = size(dic);
17 if ~exist('nIter','var') || isempty(nIter), nIter = 10; end %number of iterations
18 15
19 %% Main algo 16 SNR = @(dic) snr(Y,dic*X); %SNR function
20 A = normc(initA); %normalise columns 17 MU = @(dic) max(max(abs((dic'*dic)-diag(diag(dic'*dic))))); %coherence function
21 [Uinit Sigma] = svd(A);
22 G = A'*A; %gram matrix
23 18
24 muMin = sqrt((m-n)/(n*(m-1))); %Lower bound on mutual coherence (equiangular tight frame) 19 %% Main algorithm
25 res = zeros(nIter,1); 20 dic = normc(dic); %normalise columns
26 if verb 21 alpha = m/n; %ratio between number of atoms and ambient dimension
27 fprintf(1,'Iter mu_min mu \n'); 22
23 mus = zeros(params.nIter,1); %coherence at each iteration
24 srs = zeros(params.nIter,1); %signal to noise ratio at each iteration
25 iIter = 1;
26 while iIter<=params.nIter && MU(dic)>mu
27 fprintf(1,'Iteration number %u\n', iIter);
28 % calculate snr and coherence
29 mus(iIter) = MU(dic);
30 srs(iIter) = SNR(dic);
31
32 % calculate gram matrix
33 G = dic'*dic;
34
35 % project into the structural constraint set
36 H = zeros(size(G)); %initialise matrix
37 ind1 = find(abs(G(:))<=mu); %find elements smaller than mu
38 ind2 = find(abs(G(:))>mu); %find elements bigger than mu
39 H(ind1) = G(ind1); %copy elements belonging to ind1
40 H(ind2) = mu*sign(G(ind2)); %threshold elements belonging to ind2
41 H(1:m+1:end) = 1; %set diagonal to one
42
43 % project into spectral constraint set
44 [~ , S, V] = svd(H);
45 %G = alpha*(V(:,1:n)*V(:,1:n)');
46 G = V(:,1:n)*S(1:n,1:n)*V(:,1:n)';
47
48 % calculate dictionary
49 [~, S V] = svd(G);
50 dic = sqrt(S(1:n,:))*V';
51
52 % rotate dictionary
53 options = struct('nIter',100,'step',0.001);
54 [~, ~, W] = rotatematrix(Y,dic*X,'conjgradlie',options);
55 dic = W*dic;
56
57 iIter = iIter+1;
28 end 58 end
59 if iIter<params.nIter
60 mus(iIter:end) = mus(iIter);
61 srs(iIter:end) = srs(iIter);
62 end
63 % Test function
64 function testiterativeprojections
65 clc
66 %define parameters
67 n = 256; %ambient dimension
68 m = 512; %number of atoms
69 N = 1024; %number of signals
70 mu_min = sqrt((m-n)/(n*(m-1))); %minimum coherence
29 71
30 % optimise gram matrix 72 %initialise data
31 for iIter = 1:nIter 73 X = sprandn(m,N,1); %matrix of coefficients
32 gg = sort(abs(G(:))); %sort inner products from less to most correlated 74 phi = normc(randn(n,m)); %dictionary
33 pos = find(abs(G(:))>=gg(round(dd1*(m^2-m))) & abs(G(:)-1)>1e-6); %find large elements of gram matrix 75 temp = randn(n);
34 G(pos) = G(pos)*dd2; %shrink large elements of gram matrix 76 W = expm(0.5*(temp-temp')); %rotation matrix
35 [U S V] = svd(G); %compute new SVD of gram matrix 77 Y = W*phi*X; %observed signals
36 S(n+1:end,1+n:end) = 0; %set small eigenvalues to zero (this ensures rank(G)<=d)
37 G = U*S*V'; %update gram matrix
38 G = diag(1./abs(sqrt(diag(G))))*G*diag(1./abs(sqrt(diag(G)))); %normalise gram matrix diagonal
39 if verb
40 Geye = G - eye(size(G));
41 fprintf(1,'%6i %12.8f %12.8f \n',iIter,muMin,max(abs(Geye(:))));
42 end
43 end
44 78
45 % [~, Sigma_gram V_gram] = svd(G); %calculate svd decomposition of gramian 79 %optimise dictionary
80 [~, mus srs] = iterativeprojections(phi,0.2,Y,X);
46 81
47 % A = normc(A); %normalise dictionary 82 %plot results
83 nIter = length(mus);
48 84
49 [V_gram Sigma_gram] = svd(G); %calculate svd decomposition of gramian 85 figure,
50 Sigma_new = sqrt(Sigma_gram(1:n,:)).*sign(Sigma); %calculate singular values of dictionary 86 subplot(2,1,1)
51 A = Uinit*Sigma_new*V_gram'; %update dictionary 87 plot(1:nIter,srs,'kd-');
88 xlabel('nIter');
89 ylabel('snr (dB)');
90 grid on
52 91
53 % param.step = 0.01; 92 subplot(2,1,2), hold on
54 % param.reg = 0.01; 93 plot(1:nIter,mus,'ko-');
55 % param.nIter = 20; 94 plot([1 nIter],[mu_min mu_min],'k')
56 % A = rotatematrix(initA,A,'linesearchlie',param); 95 grid on
96 legend('\mu','\mu_{min}');
57 97
58 % %% Debug visualization function
59 % function plotcart2d(A)
60 % compass(A(1,:),A(2,:));