Mercurial > hg > smallbox
comparison util/classes/dictionaryMatrices/grassmannian.m @ 162:88578ec2f94a danieleb
Updated grassmannian function and minor debugs
author | Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk> |
---|---|
date | Wed, 31 Aug 2011 13:52:23 +0100 |
parents | e3035d45d014 |
children | 1495bdfa13e9 |
comparison
equal
deleted
inserted
replaced
160:e3035d45d014 | 162:88578ec2f94a |
---|---|
10 | 10 |
11 if ~exist('verb','var') || isempty(verb), verb = false; end %verbose output | 11 if ~exist('verb','var') || isempty(verb), verb = false; end %verbose output |
12 if ~exist('initA','var') || isempty(initA), initA = randn(n,m); end %initial matrix | 12 if ~exist('initA','var') || isempty(initA), initA = randn(n,m); end %initial matrix |
13 if ~exist('dd2','var') || isempty(dd2), dd2 = 0.95; end %shrinking factor | 13 if ~exist('dd2','var') || isempty(dd2), dd2 = 0.95; end %shrinking factor |
14 if ~exist('dd1','var') || isempty(dd1), dd1 = 0.9; end %percentage of coherences to be shrinked | 14 if ~exist('dd1','var') || isempty(dd1), dd1 = 0.9; end %percentage of coherences to be shrinked |
15 if ~exist('nIter','var') || isempty(nIter), nIter = 5; end %number of iterations | 15 if ~exist('nIter','var') || isempty(nIter), nIter = 10; end %number of iterations |
16 | 16 |
17 %% Compute svd and gramian | 17 %% Main algo |
18 A = normc(initA); %normalise columns | 18 A = normc(initA); %normalise columns |
19 [Uinit Sigma] = svd(A); %calculate svd of the matrix | 19 G = A'*A; %gram matrix |
20 G = A'*A; %gramian matrix | |
21 | 20 |
22 muMin = sqrt((m-n)/(n*(m-1))); %Lower bound on mutual coherence | 21 muMin = sqrt((m-n)/(n*(m-1))); %Lower bound on mutual coherence (equiangular tight frame) |
23 res = zeros(nIter,1); | 22 res = zeros(nIter,1); |
24 for iIter = 1:nIter | 23 if verb |
25 gg = sort(abs(G(:))); %sort inner products from less to ost correlated | 24 fprintf(1,'Iter mu_min mu \n'); |
26 pos = find(abs(G(:))>gg(round(dd1*(m^2-m))) & abs(G(:)-1)>1e-6); | |
27 G(pos) = G(pos)*dd2; | |
28 [U S V] = svd(G); | |
29 S(n+1:end,1+n:end) = 0; | |
30 G = U*S*V'; | |
31 G = diag(1./abs(sqrt(diag(G))))*G*diag(1./abs(sqrt(diag(G)))); | |
32 gg = sort(abs(G(:))); | |
33 pos = find(abs(G(:))>gg(round(dd1*(m^2-m))) & abs(G(:)-1)>1e-6); | |
34 res(iIter) = max(abs(G(pos))); | |
35 if verb | |
36 fprintf(1,'%6i %12.8f %12.8f %12.8f \n',... | |
37 [iIter,muMin,mean(abs(G(pos))),max(abs(G(pos)))]); | |
38 end | |
39 end | 25 end |
40 | 26 |
41 [~, Sigma_gram V_gram] = svd(G); %calculate svd decomposition of gramian | 27 % optimise gram matrix |
42 Sigma_new = sqrt(Sigma_gram(1:n,:)).*sign(Sigma); | 28 for iIter = 1:nIter |
43 A = Uinit*Sigma_new*V_gram'; | 29 gg = sort(abs(G(:))); %sort inner products from less to most correlated |
44 A = normc(A); | 30 pos = find(abs(G(:))>=gg(round(dd1*(m^2-m))) & abs(G(:)-1)>1e-6); %find large elements of gram matrix |
31 G(pos) = G(pos)*dd2; %shrink large elements of gram matrix | |
32 [U S V] = svd(G); %compute new SVD of gram matrix | |
33 S(n+1:end,1+n:end) = 0; %set small eigenvalues to zero (this ensures rank(G)<=d) | |
34 G = U*S*V'; %update gram matrix | |
35 G = diag(1./abs(sqrt(diag(G))))*G*diag(1./abs(sqrt(diag(G)))); %normalise gram matrix diagonal | |
36 if verb | |
37 Geye = G - eye(size(G)); | |
38 fprintf(1,'%6i %12.8f %12.8f \n',iIter,muMin,max(abs(Geye(:)))); | |
39 end | |
40 end | |
41 | |
42 % [~, Sigma_gram V_gram] = svd(G); %calculate svd decomposition of gramian | |
43 % Sigma_new = sqrt(Sigma_gram(1:n,:)).*sign(Sigma); %calculate singular values of dictionary | |
44 % A = Uinit*Sigma_new*V_gram'; %update dictionary | |
45 % A = normc(A); %normalise dictionary | |
46 | |
47 [U S] = svd(G); %calculate svd decomposition of gramian | |
48 A = sqrt(S(1:n,1:n))*U(:,1:n)'; %calculate valid frame, s.t. A'*A=G | |
49 | |
50 % %% Debug visualization function | |
51 % function plotcart2d(A) | |
52 % compass(A(1,:),A(2,:)); |