Mercurial > hg > smallbox
view 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 |
line wrap: on
line source
function [A G res muMin] = grassmannian(n,m,nIter,dd1,dd2,initA,verb) % grassmanian attempts to create an n by m matrix with minimal mutual % coherence using an iterative projection method. % % [A G res] = grassmanian(n,m,nIter,dd1,dd2,initA) % % %% Parameters and Defaults error(nargchk(2,7,nargin)); if ~exist('verb','var') || isempty(verb), verb = false; end %verbose output if ~exist('initA','var') || isempty(initA), initA = randn(n,m); end %initial matrix if ~exist('dd2','var') || isempty(dd2), dd2 = 0.95; end %shrinking factor if ~exist('dd1','var') || isempty(dd1), dd1 = 0.9; end %percentage of coherences to be shrinked if ~exist('nIter','var') || isempty(nIter), nIter = 10; end %number of iterations %% Main algo A = normc(initA); %normalise columns G = A'*A; %gram matrix muMin = sqrt((m-n)/(n*(m-1))); %Lower bound on mutual coherence (equiangular tight frame) res = zeros(nIter,1); if verb fprintf(1,'Iter mu_min mu \n'); end % optimise gram matrix for iIter = 1:nIter gg = sort(abs(G(:))); %sort inner products from less to most correlated pos = find(abs(G(:))>=gg(round(dd1*(m^2-m))) & abs(G(:)-1)>1e-6); %find large elements of gram matrix G(pos) = G(pos)*dd2; %shrink large elements of gram matrix [U S V] = svd(G); %compute new SVD of gram matrix S(n+1:end,1+n:end) = 0; %set small eigenvalues to zero (this ensures rank(G)<=d) G = U*S*V'; %update gram matrix G = diag(1./abs(sqrt(diag(G))))*G*diag(1./abs(sqrt(diag(G)))); %normalise gram matrix diagonal if verb Geye = G - eye(size(G)); fprintf(1,'%6i %12.8f %12.8f \n',iIter,muMin,max(abs(Geye(:)))); end end % [~, Sigma_gram V_gram] = svd(G); %calculate svd decomposition of gramian % Sigma_new = sqrt(Sigma_gram(1:n,:)).*sign(Sigma); %calculate singular values of dictionary % A = Uinit*Sigma_new*V_gram'; %update dictionary % A = normc(A); %normalise dictionary [U S] = svd(G); %calculate svd decomposition of gramian A = sqrt(S(1:n,1:n))*U(:,1:n)'; %calculate valid frame, s.t. A'*A=G % %% Debug visualization function % function plotcart2d(A) % compass(A(1,:),A(2,:));