annotate util/SMALL_learn.m @ 24:fc395272d53e

(none)
author idamnjanovic
date Tue, 27 Apr 2010 13:33:00 +0000
parents 33850553b702
children e6191f5bb21b
rev   line source
idamnjanovic@8 1 function DL = SMALL_learn(Problem,DL)
idamnjanovic@8 2 %%% SMALL Dictionary Learning
idamnjanovic@24 3 %
idamnjanovic@24 4 % Centre for Digital Music, Queen Mary, University of London.
idamnjanovic@24 5 % This file copyright 2009 Ivan Damnjanovic.
idamnjanovic@24 6 %
idamnjanovic@24 7 % This program is free software; you can redistribute it and/or
idamnjanovic@24 8 % modify it under the terms of the GNU General Public License as
idamnjanovic@24 9 % published by the Free Software Foundation; either version 2 of the
idamnjanovic@24 10 % License, or (at your option) any later version. See the file
idamnjanovic@24 11 % COPYING included with this distribution for more information.
idamnjanovic@24 12 %
idamnjanovic@8 13 % Function gets as input Problem and Dictionary Learning (DL) structures
idamnjanovic@8 14 % In Problem structure field b with the training set needs to be defined
idamnjanovic@8 15 % In DL fields with name of the toolbox and solver, and parameters file
idamnjanovic@8 16 % for particular dictionary learning technique needs to be present.
idamnjanovic@8 17 %
idamnjanovic@8 18 % Outputs are Learned dictionary and time spent as a part of DL structure
idamnjanovic@8 19 %%
idamnjanovic@8 20
idamnjanovic@8 21 fprintf('\nStarting Dictionary Learning %s... \n', DL.name);
idamnjanovic@8 22 start=cputime;
idamnjanovic@8 23
idamnjanovic@8 24 if strcmpi(DL.toolbox,'KSVD')
idamnjanovic@8 25 param=DL.param;
idamnjanovic@8 26 param.data=Problem.b;
idamnjanovic@8 27
idamnjanovic@8 28 D = eval([DL.name,'(param, ''t'', 5);']);
idamnjanovic@8 29 elseif strcmpi(DL.toolbox,'KSVDS')
idamnjanovic@8 30 param=DL.param;
idamnjanovic@8 31 param.data=Problem.b;
idamnjanovic@8 32
idamnjanovic@8 33 D = eval([DL.name,'(param, ''t'', 5);']);
idamnjanovic@8 34 elseif strcmpi(DL.toolbox,'SPAMS')
idamnjanovic@8 35
idamnjanovic@8 36 X = Problem.b;
idamnjanovic@8 37 param=DL.param;
idamnjanovic@8 38
idamnjanovic@8 39 D = eval([DL.name,'(X, param);']);
idamnjanovic@8 40 % As some versions of SPAMS does not produce unit norm column
idamnjanovic@8 41 % dictionaries, we need to make sure that columns are normalised to
idamnjanovic@8 42 % unit lenght.
idamnjanovic@8 43
idamnjanovic@8 44 for i = 1: size(D,2)
idamnjanovic@8 45 D(:,i)=D(:,i)/norm(D(:,i));
idamnjanovic@8 46 end
idamnjanovic@8 47
idamnjanovic@8 48 % To introduce new dictionary learning technique put the files in
idamnjanovic@8 49 % your Matlab path. Next, unique name <TolboxID> for your toolbox needs
idamnjanovic@8 50 % to be defined and also prefferd API for toolbox functions <Preffered_API>
idamnjanovic@8 51 %
idamnjanovic@8 52 % elseif strcmpi(DL.toolbox,'<ToolboxID>')
idamnjanovic@8 53 % % This is an example of API that can be used:
idamnjanovic@8 54 % % - get training set from Problem part of structure
idamnjanovic@8 55 % % - assign parameters defined in the main program
idamnjanovic@8 56 %
idamnjanovic@8 57 % X = Problem.b;
idamnjanovic@8 58 % param=DL.param;
idamnjanovic@8 59 %
idamnjanovic@8 60 % % - Evaluate the function (DL.name - defined in the main) with
idamnjanovic@8 61 % % parameters given above
idamnjanovic@8 62 %
idamnjanovic@8 63 % D = eval([DL.name,'(<Preffered_API>);']);
idamnjanovic@8 64
idamnjanovic@8 65 else
idamnjanovic@8 66 printf('\nToolbox has not been registered. Please change SMALL_learn file.\n');
idamnjanovic@8 67 return
idamnjanovic@8 68 end
idamnjanovic@8 69
idamnjanovic@8 70 %%
idamnjanovic@8 71 % Dictionary Learning time
idamnjanovic@8 72
idamnjanovic@8 73 DL.time = cputime - start;
idamnjanovic@8 74 fprintf('\n%s finished task in %2f seconds. \n', DL.name, DL.time);
idamnjanovic@8 75
idamnjanovic@8 76 % If dictionary is given as a sparse matrix change it to full
idamnjanovic@8 77
idamnjanovic@8 78 DL.D = full(D);
idamnjanovic@8 79
idamnjanovic@8 80 end
idamnjanovic@8 81