changeset 202:5bb579c9874e luisf_dev

Merge
author bmailhe
date Tue, 20 Mar 2012 14:51:31 +0000
parents 5140b0e06c22 (current diff) 751fa3bddd30 (diff)
children 5fe60504a6a9 233e75809e4a
files config/SMALL_two_step_DL_config.m
diffstat 8 files changed, 149 insertions(+), 154 deletions(-) [+]
line wrap: on
line diff
--- a/DL/two-step DL/SMALL_two_step_DL.m	Tue Mar 20 14:50:35 2012 +0000
+++ b/DL/two-step DL/SMALL_two_step_DL.m	Tue Mar 20 14:51:31 2012 +0000
@@ -30,8 +30,7 @@
 
 % initialize the dictionary %
 
-% todo: check second if statement
-if (isfield(DL.param,'initdict')) && ~isempty(DL.param.initdict);
+if (isfield(DL.param,'initdict'))
   if (any(size(DL.param.initdict)==1) && all(iswhole(DL.param.initdict(:))))
     dico = sig(:,DL.param.initdict(1:dictsize));
   else
@@ -98,7 +97,6 @@
 % want sparse representation of training set, and in Problem.b1 in this
 % version of software we store the signal that needs to be represented
 % (for example the whole image)
-global SMALL_path
 
 tmpTraining = Problem.b1;
 Problem.b1 = sig;
@@ -112,15 +110,11 @@
 for i = 1:iternum
     Problem.A = dico;
     solver = SMALL_solve(Problem, solver);
-    
-    % configuration file
-    run([SMALL_path '/config/SMALL_two_step_DL_config.m'])
-   
-%     [dico, solver.solution] = dico_update(dico, sig, solver.solution, ...
-%         typeUpdate, flow, learningRate);
-%     if (decorrelate)
-%         dico = dico_decorr(dico, mu, solver.solution);
-%     end
+    [dico, solver.solution] = dico_update(dico, sig, solver.solution, ...
+        typeUpdate, flow, learningRate);
+    if (decorrelate)
+        dico = dico_decorr(dico, mu, solver.solution);
+    end
     
    if ((show_dictionary)&&(mod(i,show_iter)==0))
        dictimg = SMALL_showdict(dico,[8 8],...
@@ -145,4 +139,4 @@
   Y(blockids) = sum(X(:,blockids).^2);
 end
 
-end
+end
\ No newline at end of file
--- a/SMALLboxInit.m	Tue Mar 20 14:50:35 2012 +0000
+++ b/SMALLboxInit.m	Tue Mar 20 14:51:31 2012 +0000
@@ -1,5 +1,4 @@
 global SMALL_path;
-SMALL_path=[fileparts(mfilename('fullpath')) filesep];
+SMALL_path = fileparts(mfilename('fullpath'));
 
-% SMALL_p = genpath(SMALL_path);
-% addpath(SMALL_p);
+addpath(genpath(SMALL_path));
--- a/SMALLboxSetup.m	Tue Mar 20 14:50:35 2012 +0000
+++ b/SMALLboxSetup.m	Tue Mar 20 14:51:31 2012 +0000
@@ -66,14 +66,10 @@
 
 end
 
-
-
-
-SMALL_path=pwd;
+SMALL_path=fileparts(mfilename('fullpath'));
 SMALL_p=genpath(SMALL_path);
 addpath(SMALL_p);
 
-
 %%
 
 
--- a/config/SMALL_learn_config.m	Tue Mar 20 14:50:35 2012 +0000
+++ b/config/SMALL_learn_config.m	Tue Mar 20 14:51:31 2012 +0000
@@ -1,18 +1,32 @@
+%% Configuration file used in SMALL_learn
+%
+%   Use this file to change the dictionary learning algorithms in SMALLBox
+%   Please refer to the documentation before editing this file
 
+%   Centre for Digital Music, Queen Mary, University of London.
+%   This file copyright 2009 Ivan Damnjanovic.
+%
+%   This program is free software; you can redistribute it and/or
+%   modify it under the terms of the GNU General Public License as
+%   published by the Free Software Foundation; either version 2 of the
+%   License, or (at your option) any later version.  See the file
+%   COPYING included with this distribution for more information.
+%
+%%
 
-  if strcmpi(DL.toolbox,'KSVD')
-    param=DL.param; 
+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; 
+elseif strcmpi(DL.toolbox,'KSVDS')
+    param=DL.param;
     param.data=Problem.b;
     
     D = eval([DL.name,'(param, ''t'', 5);']);
-  elseif strcmpi(DL.toolbox,'SPAMS')
+elseif strcmpi(DL.toolbox,'SPAMS')
     
-    X  = Problem.b; 
+    X  = Problem.b;
     param=DL.param;
     
     D = eval([DL.name,'(X, param);']);
@@ -23,9 +37,9 @@
     for i = 1: size(D,2)
         D(:,i)=D(:,i)/norm(D(:,i));
     end
-  elseif strcmpi(DL.toolbox,'SMALL')
+elseif strcmpi(DL.toolbox,'SMALL')
     
-    X  = Problem.b; 
+    X  = Problem.b;
     param=DL.param;
     
     D = eval([DL.name,'(X, param);']);
@@ -36,8 +50,8 @@
         D(:,i)=D(:,i)/norm(D(:,i));
     end
     
-   elseif strcmpi(DL.toolbox,'TwoStepDL')
-        
+elseif strcmpi(DL.toolbox,'TwoStepDL')
+    
     DL=SMALL_two_step_DL(Problem, DL);
     
     %   we need to make sure that columns are normalised to
@@ -49,7 +63,7 @@
     D = DL.D;
     
 elseif strcmpi(DL.toolbox,'MMbox')
-        
+    
     DL = wrapper_mm_DL(Problem, DL);
     
     %   we need to make sure that columns are normalised to
@@ -58,18 +72,18 @@
     for i = 1: size(DL.D,2)
         DL.D(:,i)=DL.D(:,i)/norm(DL.D(:,i));
     end
-    D = DL.D; 
-    
+    D = DL.D;
+      
 %   To introduce new dictionary learning technique put the files in
-%   your Matlab path. Next, unique name <TolboxID> for your toolbox needs 
+%   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; 
+%     X  = Problem.b;
 %     param=DL.param;
 %
 %     % - Evaluate the function (DL.name - defined in the main) with
@@ -77,7 +91,7 @@
 %
 %     D = eval([DL.name,'(<Preffered_API>);']);
 
-  else
+else
     printf('\nToolbox has not been registered. Please change SMALL_learn file.\n');
     return
-  end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/SMALL_solve_config.m	Tue Mar 20 14:51:31 2012 +0000
@@ -0,0 +1,80 @@
+%% Configuration file used in SMALL_solve
+%
+%   Use this file to change the solvers in SMALLBox
+%   Please refer to the documentation before editing this file
+
+%   Centre for Digital Music, Queen Mary, University of London.
+%   This file copyright 2009 Ivan Damnjanovic.
+%
+%   This program is free software; you can redistribute it and/or
+%   modify it under the terms of the GNU General Public License as
+%   published by the Free Software Foundation; either version 2 of the
+%   License, or (at your option) any later version.  See the file
+%   COPYING included with this distribution for more information.
+%
+%%
+
+if strcmpi(solver.toolbox,'sparselab')
+    y = eval([solver.name,'(SparseLab_A, b, n,',solver.param,');']);
+elseif strcmpi(solver.toolbox,'sparsify')
+    if isa(Problem.A,'float')
+        y = eval([solver.name,'(b, A, n,',solver.param,');']);
+    else
+        y = eval([solver.name,'(b, A, n, ''P_trans'', AT,',solver.param,');']);
+    end
+elseif (strcmpi(solver.toolbox,'spgl1')||strcmpi(solver.toolbox,'gpsr'))
+    y = eval([solver.name,'(b, A,',solver.param,');']);
+elseif (strcmpi(solver.toolbox,'SPAMS'))
+    y = eval([solver.name,'(b, A, solver.param);']);
+elseif (strcmpi(solver.toolbox,'SMALL'))
+    if isa(Problem.A,'float')
+        y = eval([solver.name,'(A, b, n,',solver.param,');']);
+    else
+        y = eval([solver.name,'(A, b, n,',solver.param,',AT);']);
+    end
+elseif (strcmpi(solver.toolbox, 'ompbox'))
+    G=A'*A;
+    epsilon=solver.param.epsilon;
+    maxatoms=solver.param.maxatoms;
+    y = eval([solver.name,'(A, b, G,epsilon,''maxatoms'',maxatoms,''checkdict'',''off'');']);
+elseif (strcmpi(solver.toolbox, 'ompsbox'))
+    basedict = Problem.basedict;
+    if issparse(Problem.A)
+        A = Problem.A;
+    else
+        A = sparse(Problem.A);
+    end
+    G = dicttsep(basedict,A,dictsep(basedict,A,speye(size(A,2))));
+    epsilon=solver.param.epsilon;
+    maxatoms=solver.param.maxatoms;
+    y = eval([solver.name,'(basedict, A, b, G,epsilon,''maxatoms'',maxatoms,''checkdict'',''off'');']);
+    Problem.sparse=1;
+elseif (strcmpi(solver.toolbox, 'ALPS'))
+    if ~isa(Problem.A,'float')
+        % ALPS does not accept implicit dictionary definition
+        A = opToMatrix(Problem.A, 1);
+    end
+    [y, numiter, time, y_path] = wrapper_ALPS_toolbox(b, A, solver.param);
+elseif (strcmpi(solver.toolbox, 'MMbox'))
+    if ~isa(Problem.A,'float')
+        % MMbox does not accept implicit dictionary definition
+        A = opToMatrix(Problem.A, 1);
+    end
+    
+    [y, cost] = wrapper_mm_solver(b, A, solver.param);
+    
+    %   To introduce new sparse representation algorithm put the files in
+    %   your Matlab path. Next, unique name <TolboxID> for your toolbox and
+    %   prefferd API <Preffered_API> needs to be defined.
+    %
+    % elseif strcmpi(solver.toolbox,'<ToolboxID>')
+    %
+    %     % - Evaluate the function (solver.name - defined in the main) with
+    %     %   parameters given above
+    %
+    %     y = eval([solver.name,'(<Preffered_API>);']);
+    
+else
+    printf('\nToolbox has not been registered. Please change SMALL_solver file.\n');
+    return
+end
--- a/config/SMALL_two_step_DL_config.m	Tue Mar 20 14:50:35 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-
-    %DICTIONARY UPDATE STEP
-    if strcmpi(typeUpdate,'mocod')			%if update is MOCOD create parameters structure
-        mocodParams = struct('zeta',DL.param.zeta,...	%coherence regularization factor
-            'eta',DL.param.eta,...		%atoms norm regularization factor
-            'Dprev',dico);				%previous dictionary
-        % dico = dico_update(dico,sig,solver.solution,typeUpdate,flow,learningRate,mocodParams);
-        if ~isfield(DL.param,'decFcn'), DL.param.decFcn = 'none'; end
-
-        dico = dico_update_mocod(dico,sig,solver.solution,typeUpdate,flow,learningRate,mocodParams);
-           
-    else
-        [dico, solver.solution] = dico_update(dico, sig, solver.solution, ...
-            typeUpdate, flow, learningRate);
-        dico = normcols(dico);
-    end
-    
-    switch lower(DL.param.decFcn)
-        case 'ink-svd'
-            dico = dico_decorr_symetric(dico,mu,solver.solution);
-        case 'grassmannian'
-            [n m] = size(dico);
-            dico = grassmannian(n,m,[],0.9,0.99,dico);
-        case 'shrinkgram'
-            dico = shrinkgram(dico,mu);
-        case 'iterproj'
-            dico = iterativeprojections(dico,mu,Problem.b1,solver.solution);
-        otherwise
-    end
-    
\ No newline at end of file
--- a/util/SMALL_learn.m	Tue Mar 20 14:50:35 2012 +0000
+++ b/util/SMALL_learn.m	Tue Mar 20 14:51:31 2012 +0000
@@ -1,9 +1,9 @@
 function DL = SMALL_learn(Problem,DL)
-%% SMALL Dictionary Learning   
-%   
-%   Function gets as input Problem and Dictionary Learning (DL) structures 
+%% SMALL Dictionary Learning
+%
+%   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 
+%   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
@@ -18,28 +18,31 @@
 %   License, or (at your option) any later version.  See the file
 %   COPYING included with this distribution for more information.
 %%
+
 global SMALL_path
+
 if (DL.profile)
-  fprintf('\nStarting Dictionary Learning %s... \n', DL.name);
+    fprintf('\nStarting Dictionary Learning %s... \n', DL.name);
 end
-  start=cputime;
-  tStart=tic;
-    
-  % configuration file
-  run([SMALL_path 'config/SMALL_learn_config.m']);
-    
+
+start=cputime;
+tStart=tic;
+
+% toolboxes configuration file
+run(fullfile(SMALL_path, 'config/SMALL_learn_config.m'));
+
 %%
 %   Dictionary Learning time
 tElapsed=toc(tStart);
 DL.time = cputime - start;
 if (DL.profile)
-  fprintf('\n%s finished task in %2f seconds (cpu time). \n', DL.name, DL.time);
-  fprintf('\n%s finished task in %2f seconds (tic-toc time). \n', DL.name, tElapsed);
+    fprintf('\n%s finished task in %2f seconds (cpu time). \n', DL.name, DL.time);
+    fprintf('\n%s finished task in %2f seconds (tic-toc time). \n', DL.name, tElapsed);
 end
 DL.time=tElapsed;
-%   If dictionary is given as a sparse matrix change it to full  
+%   If dictionary is given as a sparse matrix change it to full
 
-  DL.D = full(D);
-  
+DL.D = full(D);
+
 end
-  
+
--- a/util/SMALL_solve.m	Tue Mar 20 14:50:35 2012 +0000
+++ b/util/SMALL_solve.m	Tue Mar 20 14:51:31 2012 +0000
@@ -15,9 +15,11 @@
 %   published by the Free Software Foundation; either version 2 of the
 %   License, or (at your option) any later version.  See the file
 %   COPYING included with this distribution for more information.
-%   
+%
 %%
 
+global SMALL_path
+
 if isa(Problem.A,'float')
     A = Problem.A;
     SparseLab_A=Problem.A;
@@ -45,72 +47,9 @@
 
 start=cputime;
 tStart=tic;
-if strcmpi(solver.toolbox,'sparselab')
-    y = eval([solver.name,'(SparseLab_A, b, n,',solver.param,');']);
-elseif strcmpi(solver.toolbox,'sparsify')
-    if isa(Problem.A,'float')
-        y = eval([solver.name,'(b, A, n,',solver.param,');']);
-    else
-        y = eval([solver.name,'(b, A, n, ''P_trans'', AT,',solver.param,');']);
-    end
-elseif (strcmpi(solver.toolbox,'spgl1')||strcmpi(solver.toolbox,'gpsr'))
-    y = eval([solver.name,'(b, A,',solver.param,');']);
-elseif (strcmpi(solver.toolbox,'SPAMS'))
-    y = eval([solver.name,'(b, A, solver.param);']);
-elseif (strcmpi(solver.toolbox,'SMALL'))
-    if isa(Problem.A,'float')
-        y = eval([solver.name,'(A, b, n,',solver.param,');']);
-    else
-        y = eval([solver.name,'(A, b, n,',solver.param,',AT);']);
-    end
-elseif (strcmpi(solver.toolbox, 'ompbox'))
-    G=A'*A;
-    epsilon=solver.param.epsilon;
-    maxatoms=solver.param.maxatoms;
-    y = eval([solver.name,'(A, b, G,epsilon,''maxatoms'',maxatoms,''checkdict'',''off'');']);
-elseif (strcmpi(solver.toolbox, 'ompsbox'))
-    basedict = Problem.basedict;
-    if issparse(Problem.A)
-        A = Problem.A;
-    else
-        A = sparse(Problem.A);
-    end
-    G = dicttsep(basedict,A,dictsep(basedict,A,speye(size(A,2))));
-    epsilon=solver.param.epsilon;
-    maxatoms=solver.param.maxatoms;
-    y = eval([solver.name,'(basedict, A, b, G,epsilon,''maxatoms'',maxatoms,''checkdict'',''off'');']);
-    Problem.sparse=1;
-elseif (strcmpi(solver.toolbox, 'ALPS'))
-    if ~isa(Problem.A,'float')
-        % ALPS does not accept implicit dictionary definition
-        A = opToMatrix(Problem.A, 1);
-    end
-    [y, numiter, time, y_path] = wrapper_ALPS_toolbox(b, A, solver.param);
-elseif (strcmpi(solver.toolbox, 'MMbox'))
-    if ~isa(Problem.A,'float')
-        % MMbox does not accept implicit dictionary definition
-        A = opToMatrix(Problem.A, 1);
-    end
-    
-    [y, cost] = wrapper_mm_solver(b, A, solver.param);
-    
-     
-    
-    %   To introduce new sparse representation algorithm put the files in
-    %   your Matlab path. Next, unique name <TolboxID> for your toolbox and
-    %   prefferd API <Preffered_API> needs to be defined.
-    %
-    % elseif strcmpi(solver.toolbox,'<ToolboxID>')
-    %
-    %     % - Evaluate the function (solver.name - defined in the main) with
-    %     %   parameters given above
-    %
-    %     y = eval([solver.name,'(<Preffered_API>);']);
-    
-else
-    printf('\nToolbox has not been registered. Please change SMALL_solver file.\n');
-    return
-end
+
+% solvers configuration file
+run(fullfile(SMALL_path, 'config/SMALL_solve_config.m'));
 
 %%
 %   Sparse representation time