annotate util/SMALL_learn.m @ 128:8e660fd14774 ivand_dev

Feature 186
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Mon, 13 Jun 2011 14:55:45 +0100
parents 5ded5e2e7d07
children 485747bf39e0
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 %%
idamnjanovic@8 21
idamnjanovic@8 22 fprintf('\nStarting Dictionary Learning %s... \n', DL.name);
idamnjanovic@8 23 start=cputime;
idamnjanovic@36 24 tStart=tic;
idamnjanovic@8 25 if strcmpi(DL.toolbox,'KSVD')
idamnjanovic@8 26 param=DL.param;
idamnjanovic@8 27 param.data=Problem.b;
idamnjanovic@8 28
idamnjanovic@36 29 D = eval([DL.name,'(param)']);%, ''t'', 5);']);
idamnjanovic@8 30 elseif strcmpi(DL.toolbox,'KSVDS')
idamnjanovic@8 31 param=DL.param;
idamnjanovic@8 32 param.data=Problem.b;
idamnjanovic@8 33
idamnjanovic@8 34 D = eval([DL.name,'(param, ''t'', 5);']);
idamnjanovic@8 35 elseif strcmpi(DL.toolbox,'SPAMS')
idamnjanovic@8 36
idamnjanovic@8 37 X = Problem.b;
idamnjanovic@8 38 param=DL.param;
idamnjanovic@8 39
idamnjanovic@8 40 D = eval([DL.name,'(X, param);']);
idamnjanovic@8 41 % As some versions of SPAMS does not produce unit norm column
idamnjanovic@8 42 % dictionaries, we need to make sure that columns are normalised to
idamnjanovic@8 43 % unit lenght.
idamnjanovic@8 44
idamnjanovic@8 45 for i = 1: size(D,2)
idamnjanovic@8 46 D(:,i)=D(:,i)/norm(D(:,i));
idamnjanovic@8 47 end
idamnjanovic@36 48 elseif strcmpi(DL.toolbox,'SMALL')
idamnjanovic@8 49
idamnjanovic@36 50 X = Problem.b;
idamnjanovic@36 51 param=DL.param;
idamnjanovic@36 52
idamnjanovic@36 53 D = eval([DL.name,'(X, param);']);
idamnjanovic@36 54 % we need to make sure that columns are normalised to
idamnjanovic@36 55 % unit lenght.
idamnjanovic@36 56
idamnjanovic@36 57 for i = 1: size(D,2)
idamnjanovic@36 58 D(:,i)=D(:,i)/norm(D(:,i));
idamnjanovic@36 59 end
ivan@121 60
idamnjanovic@8 61 % To introduce new dictionary learning technique put the files in
idamnjanovic@8 62 % your Matlab path. Next, unique name <TolboxID> for your toolbox needs
idamnjanovic@8 63 % to be defined and also prefferd API for toolbox functions <Preffered_API>
idamnjanovic@8 64 %
idamnjanovic@8 65 % elseif strcmpi(DL.toolbox,'<ToolboxID>')
idamnjanovic@8 66 % % This is an example of API that can be used:
idamnjanovic@8 67 % % - get training set from Problem part of structure
idamnjanovic@8 68 % % - assign parameters defined in the main program
idamnjanovic@8 69 %
idamnjanovic@8 70 % X = Problem.b;
idamnjanovic@8 71 % param=DL.param;
idamnjanovic@8 72 %
idamnjanovic@8 73 % % - Evaluate the function (DL.name - defined in the main) with
idamnjanovic@8 74 % % parameters given above
idamnjanovic@8 75 %
idamnjanovic@8 76 % D = eval([DL.name,'(<Preffered_API>);']);
idamnjanovic@8 77
idamnjanovic@8 78 else
idamnjanovic@8 79 printf('\nToolbox has not been registered. Please change SMALL_learn file.\n');
idamnjanovic@8 80 return
idamnjanovic@8 81 end
idamnjanovic@8 82
idamnjanovic@8 83 %%
idamnjanovic@8 84 % Dictionary Learning time
idamnjanovic@36 85 tElapsed=toc(tStart);
idamnjanovic@8 86 DL.time = cputime - start;
maria@86 87 fprintf('\n%s finished task in %2f seconds (cpu time). \n', DL.name, DL.time);
maria@86 88 fprintf('\n%s finished task in %2f seconds (tic-toc time). \n', DL.name, tElapsed);
idamnjanovic@36 89 DL.time=tElapsed;
idamnjanovic@8 90 % If dictionary is given as a sparse matrix change it to full
idamnjanovic@8 91
idamnjanovic@8 92 DL.D = full(D);
idamnjanovic@8 93
idamnjanovic@8 94 end
idamnjanovic@8 95