annotate util/SMALL_learn.m @ 8:33850553b702

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