annotate util/classes/@dictionary/dictionary.m @ 171:e8428989412f 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:52 +0100
parents e3035d45d014
children 8fc38e8df8c6
rev   line source
daniele@160 1 classdef dictionary
daniele@160 2 %% Dictionary for sparse representation
daniele@160 3 properties
daniele@160 4 phi %Matrix containing the dictionary
daniele@160 5 len %Length of basis functions
daniele@160 6 nAtoms %Number of basis function
daniele@160 7 name %String containing the matrix ensemble from which the dictionary is drawn
daniele@160 8 end
daniele@160 9 properties (Dependent = true)
daniele@160 10 redundancy %Redundancy of the dictionary: nAtoms/len
daniele@160 11 coherence %Maximum inner product of different basis
daniele@160 12 isNormalised %True if the atoms have unit norm
daniele@160 13 rank %rank of the dictionary
daniele@160 14 end
daniele@160 15
daniele@160 16 methods
daniele@160 17 %% Constructor
daniele@160 18 function obj = dictionary(phi,len,nAtoms)
daniele@160 19 % obj = dictionary(phi,len,nAtoms)
daniele@160 20 % INPUTS:
daniele@160 21 % - phi: either a string specifying a matrix ensamble or a
daniele@160 22 % matrix defining an explicit dictionary
daniele@160 23 % - len: length of the atoms (only for implicit dictionaries)
daniele@160 24 % - nAtoms: number of atoms (only for implicit dictionaries)
daniele@160 25 if nargin
daniele@160 26 if ~ischar(phi)
daniele@160 27 [obj.len obj.nAtoms] = size(phi);
daniele@160 28 obj.phi = phi;
daniele@160 29 obj.name = 'explicit';
daniele@160 30 else
daniele@160 31 switch lower(phi)
daniele@160 32 case 'dct'
daniele@160 33 obj.phi = dctmatrix(len,nAtoms);
daniele@160 34 case 'grassmanian'
daniele@160 35 obj.phi = grassmanian(len,nAtoms);
daniele@160 36 otherwise
daniele@160 37 obj.phi = MatrixEnsemble(len,nAtoms,phi);
daniele@160 38 end
daniele@160 39 obj.len = len;
daniele@160 40 obj.nAtoms = nAtoms;
daniele@160 41 obj.name = lower(phi);
daniele@160 42 end
daniele@160 43 end
daniele@160 44 end
daniele@160 45
daniele@160 46 %% Dependent properties
daniele@160 47 function redundancy = get.redundancy(obj)
daniele@160 48 redundancy = obj.nAtoms/obj.len;
daniele@160 49 end
daniele@160 50 function coherence = get.coherence(obj)
daniele@160 51 obj.phi = normcol(obj.phi);
daniele@160 52 G = obj.phi'*obj.phi;
daniele@160 53 G = G - eye(size(G));
daniele@160 54 coherence = max(abs(G(:)));
daniele@160 55 end
daniele@160 56 function isNormalised = get.isNormalised(obj)
daniele@160 57 isNormalised = norm(sum(conj(obj.phi).*obj.phi) - ...
daniele@160 58 ones(1,obj.nAtoms))<1e-9;
daniele@160 59 end
daniele@160 60 function r = get.rank(obj)
daniele@160 61 r = rank(obj.phi);
daniele@160 62 end
daniele@160 63 %% Operations
daniele@160 64 function obj = normalize(obj)
daniele@160 65 obj.phi = normcol(obj.phi);
daniele@160 66 end
daniele@160 67
daniele@160 68 %% Visualization
daniele@160 69 function image(obj)
daniele@160 70 %Image of the dictionary
daniele@160 71 if isreal(obj.phi)
daniele@160 72 imagesc(obj.phi);
daniele@160 73 title('Dictionary');
daniele@160 74 xlabel('Atom number');
daniele@160 75 else
daniele@160 76 subplot(2,1,1)
daniele@160 77 imagesc(real(obj.phi));
daniele@160 78 title('Real');
daniele@160 79 xlabel('Atom number');
daniele@160 80 subplot(2,1,2)
daniele@160 81 imagesc(imag(obj.phi));
daniele@160 82 title('Imaginary');
daniele@160 83 xlabel('Atom number');
daniele@160 84 end
daniele@160 85 end
daniele@160 86 function imagegram(obj)
daniele@160 87 G = obj.phi'*obj.phi;
daniele@160 88 imagesc(G);
daniele@160 89 title('Gram Matrix')
daniele@160 90 end
daniele@160 91 function plot(obj,n)
daniele@160 92 %Plot of the n-th basis
daniele@160 93 if isreal(obj.phi)
daniele@160 94 plot(obj.phi(:,n));
daniele@160 95 title(['Atom number ' num2str(n) '/' num2str(size(obj.phi,2))]);
daniele@160 96 else
daniele@160 97 subplot(2,1,1)
daniele@160 98 plot(real(obj.phi(:,n)));
daniele@160 99 title(['Atom number ' num2str(n) '/' num2str(size(obj.phi,2)) ' - Real']);
daniele@160 100 subplot(2,1,2)
daniele@160 101 plot(imag(obj.phi(:,n)));
daniele@160 102 title(['Atom number ' num2str(n) '/' num2str(size(obj.phi,2)) ' - Imaginary']);
daniele@160 103 end
daniele@160 104 end
daniele@160 105
daniele@160 106 function movie(obj)
daniele@160 107 %Movie of the basis
daniele@160 108 for i=1:size(obj.phi,2)
daniele@160 109 obj.plot(i);
daniele@160 110 pause(1/25);
daniele@160 111 end
daniele@160 112 end
daniele@160 113 end
daniele@160 114 end