annotate util/SMALL_learn.m @ 189:75b5dedcfd45 luisf_dev

created initialization file; changing SMALL_learn in order to initialize plugins.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 16 Feb 2012 18:24:43 +0000
parents b14209313ba4
children
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;
ivan@155 85
idamnjanovic@8 86 % To introduce new dictionary learning technique put the files in
idamnjanovic@8 87 % your Matlab path. Next, unique name <TolboxID> for your toolbox needs
idamnjanovic@8 88 % to be defined and also prefferd API for toolbox functions <Preffered_API>
idamnjanovic@8 89 %
idamnjanovic@8 90 % elseif strcmpi(DL.toolbox,'<ToolboxID>')
idamnjanovic@8 91 % % This is an example of API that can be used:
idamnjanovic@8 92 % % - get training set from Problem part of structure
idamnjanovic@8 93 % % - assign parameters defined in the main program
idamnjanovic@8 94 %
idamnjanovic@8 95 % X = Problem.b;
idamnjanovic@8 96 % param=DL.param;
idamnjanovic@8 97 %
idamnjanovic@8 98 % % - Evaluate the function (DL.name - defined in the main) with
idamnjanovic@8 99 % % parameters given above
idamnjanovic@8 100 %
idamnjanovic@8 101 % D = eval([DL.name,'(<Preffered_API>);']);
idamnjanovic@8 102
idamnjanovic@8 103 else
luis@189 104 % register other toolboxes from the extra plugins folder
luis@189 105 folders = dir('extra');
luis@189 106 extra_plugins = folders(arrayfun(@(x) x.name(1), folders) ~= '.');
luis@189 107 extra_plugins = extra_plugins([extra_plugins.isdir])
luis@189 108
luis@189 109 if length(extra_plugins) > 0
luis@189 110 printf('Found %i extra plugin(s) in the extra plugins folder.\n', length(extra_plugins));
luis@189 111
luis@189 112 for i=1:length(extra_plugins)
luis@189 113 printf('Initializing extra plugin "%s"', extra_plugins(i).name);
luis@189 114
luis@189 115 %% adds all files from path
luis@189 116 genpath(['extra/', extra_plugins(i).name]);
luis@189 117
luis@189 118 % open plugin's init file
luis@189 119
luis@189 120
luis@189 121 init_file = ['extra/', extra_plugins(i).name, '/init.m'];
luis@189 122
luis@189 123 if ~(exist(init_file == 2)
luis@189 124 error(['Plugin ', extra_plugins(i).name, ' init file does not exist. Exiting now...'])
luis@189 125 else
luis@189 126 % get the correct function handle and run it
luis@189 127 init_file
luis@189 128
luis@189 129 end
luis@189 130 end
luis@189 131
luis@189 132 else
luis@189 133 printf('No extra plugins found.')
luis@189 134 end
luis@189 135
luis@189 136
luis@189 137
idamnjanovic@8 138 printf('\nToolbox has not been registered. Please change SMALL_learn file.\n');
idamnjanovic@8 139 return
idamnjanovic@8 140 end
idamnjanovic@8 141
idamnjanovic@8 142 %%
idamnjanovic@8 143 % Dictionary Learning time
idamnjanovic@36 144 tElapsed=toc(tStart);
ivan@152 145 DL.time = cputime - start;
ivan@152 146 if (DL.profile)
maria@86 147 fprintf('\n%s finished task in %2f seconds (cpu time). \n', DL.name, DL.time);
maria@86 148 fprintf('\n%s finished task in %2f seconds (tic-toc time). \n', DL.name, tElapsed);
ivan@152 149 end
idamnjanovic@36 150 DL.time=tElapsed;
idamnjanovic@8 151 % If dictionary is given as a sparse matrix change it to full
idamnjanovic@8 152
idamnjanovic@8 153 DL.D = full(D);
idamnjanovic@8 154
idamnjanovic@8 155 end
idamnjanovic@8 156