Mercurial > hg > smallbox
comparison util/classes/dictionaryMatrices/grassmannian.m @ 160:e3035d45d014 danieleb
Added support classes
author | Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk> |
---|---|
date | Wed, 31 Aug 2011 10:53:10 +0100 |
parents | |
children | 88578ec2f94a |
comparison
equal
deleted
inserted
replaced
159:23763c5fbda5 | 160:e3035d45d014 |
---|---|
1 function [A G res muMin] = grassmannian(n,m,nIter,dd1,dd2,initA,verb) | |
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 % | |
8 %% Parameters and Defaults | |
9 error(nargchk(2,7,nargin)); | |
10 | |
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 | |
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 | |
15 if ~exist('nIter','var') || isempty(nIter), nIter = 5; end %number of iterations | |
16 | |
17 %% Compute svd and gramian | |
18 A = normc(initA); %normalise columns | |
19 [Uinit Sigma] = svd(A); %calculate svd of the matrix | |
20 G = A'*A; %gramian matrix | |
21 | |
22 muMin = sqrt((m-n)/(n*(m-1))); %Lower bound on mutual coherence | |
23 res = zeros(nIter,1); | |
24 for iIter = 1:nIter | |
25 gg = sort(abs(G(:))); %sort inner products from less to ost correlated | |
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 | |
40 | |
41 [~, Sigma_gram V_gram] = svd(G); %calculate svd decomposition of gramian | |
42 Sigma_new = sqrt(Sigma_gram(1:n,:)).*sign(Sigma); | |
43 A = Uinit*Sigma_new*V_gram'; | |
44 A = normc(A); |