annotate util/SMALL_learn.m @ 154:0de08f68256b ivand_dev

ALPS toolbox - Algebraic Pursuit added to smallbox
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Fri, 12 Aug 2011 11:17:47 +0100
parents 485747bf39e0
children b14209313ba4
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@152 72 D = DL.D;
idamnjanovic@8 73 % To introduce new dictionary learning technique put the files in
idamnjanovic@8 74 % your Matlab path. Next, unique name <TolboxID> for your toolbox needs
idamnjanovic@8 75 % to be defined and also prefferd API for toolbox functions <Preffered_API>
idamnjanovic@8 76 %
idamnjanovic@8 77 % elseif strcmpi(DL.toolbox,'<ToolboxID>')
idamnjanovic@8 78 % % This is an example of API that can be used:
idamnjanovic@8 79 % % - get training set from Problem part of structure
idamnjanovic@8 80 % % - assign parameters defined in the main program
idamnjanovic@8 81 %
idamnjanovic@8 82 % X = Problem.b;
idamnjanovic@8 83 % param=DL.param;
idamnjanovic@8 84 %
idamnjanovic@8 85 % % - Evaluate the function (DL.name - defined in the main) with
idamnjanovic@8 86 % % parameters given above
idamnjanovic@8 87 %
idamnjanovic@8 88 % D = eval([DL.name,'(<Preffered_API>);']);
idamnjanovic@8 89
idamnjanovic@8 90 else
idamnjanovic@8 91 printf('\nToolbox has not been registered. Please change SMALL_learn file.\n');
idamnjanovic@8 92 return
idamnjanovic@8 93 end
idamnjanovic@8 94
idamnjanovic@8 95 %%
idamnjanovic@8 96 % Dictionary Learning time
idamnjanovic@36 97 tElapsed=toc(tStart);
ivan@152 98 DL.time = cputime - start;
ivan@152 99 if (DL.profile)
maria@86 100 fprintf('\n%s finished task in %2f seconds (cpu time). \n', DL.name, DL.time);
maria@86 101 fprintf('\n%s finished task in %2f seconds (tic-toc time). \n', DL.name, tElapsed);
ivan@152 102 end
idamnjanovic@36 103 DL.time=tElapsed;
idamnjanovic@8 104 % If dictionary is given as a sparse matrix change it to full
idamnjanovic@8 105
idamnjanovic@8 106 DL.D = full(D);
idamnjanovic@8 107
idamnjanovic@8 108 end
idamnjanovic@8 109