annotate util/SMALL_learn.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 b14209313ba4
children 7426503fc4d1 75b5dedcfd45 759313488e7b
rev   line source
idamnjanovic@8 1 function DL = SMALL_learn(Problem,DL)
ivan@121 2 %% SMALL Dictionary Learning
ivan@121 3 %
ivan@121 4 % Function gets as input Problem and Dictionary Learning (DL) structures
ivan@121 5 % In Problem structure field b with the training set needs to be defined
ivan@121 6 % In DL fields with name of the toolbox and solver, and parameters file
ivan@121 7 % for particular dictionary learning technique needs to be present.
ivan@121 8 %
ivan@121 9 % Outputs are Learned dictionary and time spent as a part of DL structure
ivan@121 10
idamnjanovic@24 11 %
idamnjanovic@24 12 % Centre for Digital Music, Queen Mary, University of London.
idamnjanovic@24 13 % This file copyright 2009 Ivan Damnjanovic.
idamnjanovic@24 14 %
idamnjanovic@24 15 % This program is free software; you can redistribute it and/or
idamnjanovic@24 16 % modify it under the terms of the GNU General Public License as
idamnjanovic@24 17 % published by the Free Software Foundation; either version 2 of the
idamnjanovic@24 18 % License, or (at your option) any later version. See the file
idamnjanovic@24 19 % COPYING included with this distribution for more information.
idamnjanovic@8 20 %%
ivan@152 21 if (DL.profile)
idamnjanovic@8 22 fprintf('\nStarting Dictionary Learning %s... \n', DL.name);
ivan@152 23 end
idamnjanovic@8 24 start=cputime;
idamnjanovic@36 25 tStart=tic;
idamnjanovic@8 26 if strcmpi(DL.toolbox,'KSVD')
idamnjanovic@8 27 param=DL.param;
idamnjanovic@8 28 param.data=Problem.b;
idamnjanovic@8 29
idamnjanovic@36 30 D = eval([DL.name,'(param)']);%, ''t'', 5);']);
idamnjanovic@8 31 elseif strcmpi(DL.toolbox,'KSVDS')
idamnjanovic@8 32 param=DL.param;
idamnjanovic@8 33 param.data=Problem.b;
idamnjanovic@8 34
idamnjanovic@8 35 D = eval([DL.name,'(param, ''t'', 5);']);
idamnjanovic@8 36 elseif strcmpi(DL.toolbox,'SPAMS')
idamnjanovic@8 37
idamnjanovic@8 38 X = Problem.b;
idamnjanovic@8 39 param=DL.param;
idamnjanovic@8 40
idamnjanovic@8 41 D = eval([DL.name,'(X, param);']);
idamnjanovic@8 42 % As some versions of SPAMS does not produce unit norm column
idamnjanovic@8 43 % dictionaries, we need to make sure that columns are normalised to
idamnjanovic@8 44 % unit lenght.
idamnjanovic@8 45
idamnjanovic@8 46 for i = 1: size(D,2)
idamnjanovic@8 47 D(:,i)=D(:,i)/norm(D(:,i));
idamnjanovic@8 48 end
idamnjanovic@36 49 elseif strcmpi(DL.toolbox,'SMALL')
idamnjanovic@8 50
idamnjanovic@36 51 X = Problem.b;
idamnjanovic@36 52 param=DL.param;
idamnjanovic@36 53
idamnjanovic@36 54 D = eval([DL.name,'(X, param);']);
idamnjanovic@36 55 % we need to make sure that columns are normalised to
idamnjanovic@36 56 % unit lenght.
idamnjanovic@36 57
idamnjanovic@36 58 for i = 1: size(D,2)
idamnjanovic@36 59 D(:,i)=D(:,i)/norm(D(:,i));
idamnjanovic@36 60 end
ivan@121 61
ivan@152 62 elseif strcmpi(DL.toolbox,'TwoStepDL')
ivan@152 63
ivan@152 64 DL=SMALL_two_step_DL(Problem, DL);
ivan@152 65
ivan@152 66 % we need to make sure that columns are normalised to
ivan@152 67 % unit lenght.
ivan@152 68
ivan@152 69 for i = 1: size(DL.D,2)
ivan@152 70 DL.D(:,i)=DL.D(:,i)/norm(DL.D(:,i));
ivan@152 71 end
ivan@155 72 D = DL.D;
ivan@155 73
ivan@155 74 elseif strcmpi(DL.toolbox,'MMbox')
ivan@155 75
ivan@155 76 DL = wrapper_mm_DL(Problem, DL);
ivan@155 77
ivan@155 78 % we need to make sure that columns are normalised to
ivan@155 79 % unit lenght.
ivan@155 80
ivan@155 81 for i = 1: size(DL.D,2)
ivan@155 82 DL.D(:,i)=DL.D(:,i)/norm(DL.D(:,i));
ivan@155 83 end
ivan@152 84 D = DL.D;
ivan@155 85
idamnjanovic@8 86 % To introduce new dictionary learning technique put the files in
idamnjanovic@8 87 % your Matlab path. Next, unique name <TolboxID> for your toolbox needs
idamnjanovic@8 88 % to be defined and also prefferd API for toolbox functions <Preffered_API>
idamnjanovic@8 89 %
idamnjanovic@8 90 % elseif strcmpi(DL.toolbox,'<ToolboxID>')
idamnjanovic@8 91 % % This is an example of API that can be used:
idamnjanovic@8 92 % % - get training set from Problem part of structure
idamnjanovic@8 93 % % - assign parameters defined in the main program
idamnjanovic@8 94 %
idamnjanovic@8 95 % X = Problem.b;
idamnjanovic@8 96 % param=DL.param;
idamnjanovic@8 97 %
idamnjanovic@8 98 % % - Evaluate the function (DL.name - defined in the main) with
idamnjanovic@8 99 % % parameters given above
idamnjanovic@8 100 %
idamnjanovic@8 101 % D = eval([DL.name,'(<Preffered_API>);']);
idamnjanovic@8 102
idamnjanovic@8 103 else
idamnjanovic@8 104 printf('\nToolbox has not been registered. Please change SMALL_learn file.\n');
idamnjanovic@8 105 return
idamnjanovic@8 106 end
idamnjanovic@8 107
idamnjanovic@8 108 %%
idamnjanovic@8 109 % Dictionary Learning time
idamnjanovic@36 110 tElapsed=toc(tStart);
ivan@152 111 DL.time = cputime - start;
ivan@152 112 if (DL.profile)
maria@86 113 fprintf('\n%s finished task in %2f seconds (cpu time). \n', DL.name, DL.time);
maria@86 114 fprintf('\n%s finished task in %2f seconds (tic-toc time). \n', DL.name, tElapsed);
ivan@152 115 end
idamnjanovic@36 116 DL.time=tElapsed;
idamnjanovic@8 117 % If dictionary is given as a sparse matrix change it to full
idamnjanovic@8 118
idamnjanovic@8 119 DL.D = full(D);
idamnjanovic@8 120
idamnjanovic@8 121 end
idamnjanovic@8 122