changeset 184:8fc38e8df8c6 danieleb

Minor edits
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Fri, 27 Jan 2012 13:18:50 +0000
parents 0d7a81655ef2
children 2f5ce7c8792a f1e601cc916d
files util/DisplayFigureTitle.m util/classes/@dictionary/dictionary.m util/classes/@dictionary/plotcumcoherence.m util/classes/@dictionary/plotcumcoherencebounds.m util/classes/dictionaryMatrices/iterativeprojections.m util/classes/dictionaryMatrices/rotatematrix.m
diffstat 6 files changed, 83 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util/DisplayFigureTitle.m	Fri Jan 27 13:18:50 2012 +0000
@@ -0,0 +1,5 @@
+function DisplayFigureTitle(title)
+
+set(gcf,'Units','Normalized');
+txh = annotation(gcf,'textbox',[0.4,0.95,0.2,0.05]);
+set(txh,'String',title,'LineStyle','none','HorizontalAlignment','center');
--- a/util/classes/@dictionary/dictionary.m	Fri Jan 27 13:15:11 2012 +0000
+++ b/util/classes/@dictionary/dictionary.m	Fri Jan 27 13:18:50 2012 +0000
@@ -31,7 +31,7 @@
                     switch lower(phi)
                         case 'dct'
                             obj.phi = dctmatrix(len,nAtoms);
-                        case 'grassmanian'
+                        case 'grassmannian'
                             obj.phi = grassmanian(len,nAtoms);
                         otherwise
                             obj.phi = MatrixEnsemble(len,nAtoms,phi);
@@ -41,8 +41,7 @@
                     obj.name   = lower(phi);
                 end
             end
-        end
-        
+		end
         %% Dependent properties
         function redundancy = get.redundancy(obj)
             redundancy = obj.nAtoms/obj.len;
@@ -63,8 +62,7 @@
         %% Operations
         function obj = normalize(obj)
             obj.phi = normcol(obj.phi);
-        end
-        
+		end
         %% Visualization
         function image(obj)
             %Image of the dictionary
@@ -101,8 +99,7 @@
                 plot(imag(obj.phi(:,n)));
                 title(['Atom number ' num2str(n) '/' num2str(size(obj.phi,2)) ' - Imaginary']);
             end
-        end
-        
+		end
         function movie(obj)
             %Movie of the basis
             for i=1:size(obj.phi,2)
--- a/util/classes/@dictionary/plotcumcoherence.m	Fri Jan 27 13:15:11 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-function plotcumcoherence(obj,mu)
-if ~exist('mu','var') || isempty(mu), mu = cumcoherence(obj); end
-[d N] = size(obj.phi);
-
-% Plot cumulative coherence with lower and upper bounds
-mumin = (1:d)*sqrt((N-d)/(d*(N-1)));
-mumax = (1:d);
-figure,
-subplot(1,6,1:2)
-hold on, grid on
-plot(1,mumax(1),'k-s');
-plot(1,mu(1),'ko');
-plot(1,mumin(1),'k-d')
-set(gca,'XScale','log','YScale','log');
-axis tight
-ylabel('\mu');
-ylim([mumin(1) 10])
-
-subplot(1,6,3:6)
-hold on, grid on
-plot(2:d,mumax(2:end),'k-s');
-plot(2:d,mu(2:end),'k-o');
-plot(2:d,mumin(2:end),'k-d');
-set(gca,'XScale','log','YScale','log');
-axis tight
-xlabel('k');
-ylabel('\mu(k)');
-ylim([mumin(1) 10])
-
-% Plot recovery bounds
-plot(2:d,1-mu(1:d-1),'r-o')
-plot(2:d,1-mumin(1:d-1)','r-d')
-plot([2 d],[1/3 1/3],'b');
-legend('\mu_{max}(k)','\mu(k)','\mu_{min}(k)','Exact-Sparse \mu','Exact-Sparse \mu_{min}','Sparse');
-
-
-% v = conv(mu,[1 1]);
-% ind = find(v<1, 1, 'last');
-% 
-% line([ind ind], [min(mu) max(mu)],'Color','red');
-% title(['Minimum allowed sparsity (Tanner):' num2str(ind/obj.len)]);
-end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util/classes/@dictionary/plotcumcoherencebounds.m	Fri Jan 27 13:18:50 2012 +0000
@@ -0,0 +1,65 @@
+function plotcumcoherencebounds(obj)
+
+[d N] = size(obj.phi);
+
+mu1 = cumcoherence(obj,1);
+mu2 = cumcoherence(obj,2);
+mu1_min = (1:d)*sqrt((N-d)/(d*(N-1)));
+
+figure, subplot(2,1,1)
+hold on, grid on
+plot(1:d,mu1,'k-')
+plot(1:d,mu2,'k--')
+plot(1:d,mu1_min,'b-.')
+set(gca,'XScale','log','YScale','log');
+axis tight
+ylabel('p-cumulative coherence')
+xlabel('k')
+legend('\mu_1(k)','\mu_2(k)','\mu_{1_{min}}(k)')
+
+% temp = conv(mu1,[1 1]);
+% kMax = find(temp<1,1,'last');
+% title(['Worst case bound: k_{max} = ' num2str(kMax)])
+% 
+% % subplot(2,1,2)
+% p_BP_fails = exp(-1./(8*mu1(1)^2*(1:d)));
+% p_TH_fails = exp(-1./(128*mu2.^2));
+% plot(1:d,p_BP_fails,'k-+');
+% plot(1:d,p_TH_fails,'k-o');
+% legend('P(BP fails)','P(TH fails)');
+
+% % Plot cumulative coherence with lower and upper bounds
+% mumin = (1:d)*sqrt((N-d)/(d*(N-1)));
+% mumax = (1:d);
+% figure,
+% subplot(1,6,1:2)
+% hold on, grid on
+% plot(1,mumax(1),'k-s');
+% plot(1,mu(1),'ko');
+% plot(1,mumin(1),'k-d')
+% 
+% 
+% subplot(1,6,3:6)
+% hold on, grid on
+% plot(2:d,mumax(2:end),'k-s');
+% plot(2:d,mu(2:end),'k-o');
+% plot(2:d,mumin(2:end),'k-d');
+% set(gca,'XScale','log','YScale','log');
+% axis tight
+% xlabel('k');
+% ylabel('\mu(k)');
+% ylim([mumin(1) 10])
+% 
+% % Plot recovery bounds
+% plot(2:d,1-mu(1:d-1),'r-o')
+% plot(2:d,1-mumin(1:d-1)','r-d')
+% plot([2 d],[1/3 1/3],'b');
+% legend('\mu_{max}(k)','\mu(k)','\mu_{min}(k)','Exact-Sparse \mu','Exact-Sparse \mu_{min}','Sparse');
+
+
+% v = conv(mu,[1 1]);
+% ind = find(v<1, 1, 'last');
+% 
+% line([ind ind], [min(mu) max(mu)],'Color','red');
+% title(['Minimum allowed sparsity (Tanner):' num2str(ind/obj.len)]);
+end
--- a/util/classes/dictionaryMatrices/iterativeprojections.m	Fri Jan 27 13:15:11 2012 +0000
+++ b/util/classes/dictionaryMatrices/iterativeprojections.m	Fri Jan 27 13:18:50 2012 +0000
@@ -32,7 +32,7 @@
 	% calculate gram matrix
 	G = dic'*dic;
 	
-	% project into the structural constraint set
+	% project onto the structural constraint set
 	H = zeros(size(G));				%initialise matrix
 	ind1 = find(abs(G(:))<=mu);		%find elements smaller than mu
 	ind2 = find(abs(G(:))>mu);		%find elements bigger than mu
--- a/util/classes/dictionaryMatrices/rotatematrix.m	Fri Jan 27 13:15:11 2012 +0000
+++ b/util/classes/dictionaryMatrices/rotatematrix.m	Fri Jan 27 13:18:50 2012 +0000
@@ -1,5 +1,5 @@
 function [Dhat cost W] = rotatematrix(D,Phi,method,param)
-%
+% 
 %
 %
 % REFERENCE
@@ -90,24 +90,25 @@
 param.nIter = 300;				%number of iterations
 param.step  = 0.001;			%step size
 param.mu    = 0.01;			%regularization factor (for tangent method)
-methods = {'unconstrained','tangent','linesearchlie','conjgradlie'};
+methods = {'tangent','linesearchlie','conjgradlie'};
 
 Phi = randn(n,m);				%initial dictionary
 Qtrue = expm(skew(randn(n)));	%rotation matrix
 D = Qtrue*Phi;					%target dictionary
 
 cost = zeros(param.nIter,length(methods));
+times = zeros(param.nIter,length(methods));
 for iIter=1:length(methods)
 	tic
 	[~, cost(:,iIter)] = rotatematrix(D,Phi,methods{iIter},param);
-	time = toc;
-	sprintf('Method %s completed in %f seconds \n',methods{iIter},time)
+	times(:,iIter) = linspace(0,toc,param.nIter);
+	sprintf('Method %s completed in %f seconds \n',methods{iIter},toc)
 end
 
-figure, plot(cost)
-set(gca,'XScale','log','Yscale','log')
+figure, plot(times,cost)
+set(gca,'XScale','lin','Yscale','log')
 legend(methods)
 grid on
-xlabel('number of iterations')
+xlabel('time (sec)')
 ylabel('J(W)')
 end