diff util/SMALL_learn.m @ 8:33850553b702

(none)
author idamnjanovic
date Mon, 22 Mar 2010 10:56:54 +0000
parents
children fc395272d53e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util/SMALL_learn.m	Mon Mar 22 10:56:54 2010 +0000
@@ -0,0 +1,72 @@
+function DL = SMALL_learn(Problem,DL)
+%%% SMALL Dictionary Learning   
+%   Ivan Damnjanovic 2009
+%   Function gets as input Problem and Dictionary Learning (DL) structures 
+%   In Problem structure field b with the training set needs to be defined
+%   In DL fields with name of the toolbox and solver, and parameters file 
+%   for particular dictionary learning technique needs to be present.
+%
+%   Outputs are Learned dictionary and time spent as a part of DL structure
+%%
+ 
+  fprintf('\nStarting Dictionary Learning %s... \n', DL.name);
+  start=cputime;
+  
+  if strcmpi(DL.toolbox,'KSVD')
+    param=DL.param; 
+    param.data=Problem.b;
+ 
+    D = eval([DL.name,'(param, ''t'', 5);']);
+  elseif strcmpi(DL.toolbox,'KSVDS')
+    param=DL.param; 
+    param.data=Problem.b;
+    
+    D = eval([DL.name,'(param, ''t'', 5);']);
+  elseif strcmpi(DL.toolbox,'SPAMS')
+    
+    X  = Problem.b; 
+    param=DL.param;
+    
+    D = eval([DL.name,'(X, param);']);
+    %   As some versions of SPAMS does not produce unit norm column
+    %   dictionaries, we need to make sure that columns are normalised to
+    %   unit lenght.
+    
+    for i = 1: size(D,2)
+        D(:,i)=D(:,i)/norm(D(:,i));
+    end
+    
+%   To introduce new dictionary learning technique put the files in
+%   your Matlab path. Next, unique name <TolboxID> for your toolbox needs 
+%   to be defined and also prefferd API for toolbox functions <Preffered_API>
+%   
+% elseif strcmpi(DL.toolbox,'<ToolboxID>')
+%     % This is an example of API that can be used:
+%     % - get training set from Problem part of structure
+%     % - assign parameters defined in the main program
+%
+%     X  = Problem.b; 
+%     param=DL.param;
+%
+%     % - Evaluate the function (DL.name - defined in the main) with
+%     %   parameters given above
+%
+%     D = eval([DL.name,'(<Preffered_API>);']);
+
+  else
+    printf('\nToolbox has not been registered. Please change SMALL_learn file.\n');
+    return
+  end
+  
+%%
+%   Dictionary Learning time
+
+  DL.time = cputime - start;
+  fprintf('\n%s finished task in %2f seconds. \n', DL.name, DL.time);
+
+%   If dictionary is given as a sparse matrix change it to full  
+
+  DL.D = full(D);
+  
+end
+  
\ No newline at end of file