annotate util/SMALL_learn.m @ 192:f1e601cc916d danieleb

removed error check for wLength
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Thu, 01 Mar 2012 16:57:51 +0000
parents 7426503fc4d1
children fd0b5d36f6ad
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;
daniele@173 85
daniele@173 86 elseif strcmpi(DL.toolbox,'dl_ramirez')
daniele@173 87 DL = dl_ramirez(Problem,DL);
daniele@173 88 D = normcol(DL.D);
ivan@155 89
idamnjanovic@8 90 % To introduce new dictionary learning technique put the files in
idamnjanovic@8 91 % your Matlab path. Next, unique name <TolboxID> for your toolbox needs
idamnjanovic@8 92 % to be defined and also prefferd API for toolbox functions <Preffered_API>
idamnjanovic@8 93 %
idamnjanovic@8 94 % elseif strcmpi(DL.toolbox,'<ToolboxID>')
idamnjanovic@8 95 % % This is an example of API that can be used:
idamnjanovic@8 96 % % - get training set from Problem part of structure
idamnjanovic@8 97 % % - assign parameters defined in the main program
idamnjanovic@8 98 %
idamnjanovic@8 99 % X = Problem.b;
idamnjanovic@8 100 % param=DL.param;
idamnjanovic@8 101 %
idamnjanovic@8 102 % % - Evaluate the function (DL.name - defined in the main) with
idamnjanovic@8 103 % % parameters given above
idamnjanovic@8 104 %
idamnjanovic@8 105 % D = eval([DL.name,'(<Preffered_API>);']);
idamnjanovic@8 106
idamnjanovic@8 107 else
idamnjanovic@8 108 printf('\nToolbox has not been registered. Please change SMALL_learn file.\n');
idamnjanovic@8 109 return
idamnjanovic@8 110 end
idamnjanovic@8 111
idamnjanovic@8 112 %%
idamnjanovic@8 113 % Dictionary Learning time
idamnjanovic@36 114 tElapsed=toc(tStart);
ivan@152 115 DL.time = cputime - start;
ivan@152 116 if (DL.profile)
maria@86 117 fprintf('\n%s finished task in %2f seconds (cpu time). \n', DL.name, DL.time);
maria@86 118 fprintf('\n%s finished task in %2f seconds (tic-toc time). \n', DL.name, tElapsed);
ivan@152 119 end
idamnjanovic@36 120 DL.time=tElapsed;
idamnjanovic@8 121 % If dictionary is given as a sparse matrix change it to full
idamnjanovic@8 122
idamnjanovic@8 123 DL.D = full(D);
idamnjanovic@8 124
idamnjanovic@8 125 end
daniele@173 126