comparison util/SMALL_learn.m @ 220:0d30f9074dd9

Merge
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 15:56:39 +0100
parents a986ee86651e
children fd0b5d36f6ad 198d4d9cee74
comparison
equal deleted inserted replaced
165:775caafd5651 220:0d30f9074dd9
1 function DL = SMALL_learn(Problem,DL) 1 function DL = SMALL_learn(Problem,DL)
2 %% SMALL Dictionary Learning 2 %% SMALL Dictionary Learning
3 % 3 %
4 % Function gets as input Problem and Dictionary Learning (DL) structures 4 % Function gets as input Problem and Dictionary Learning (DL) structures
5 % In Problem structure field b with the training set needs to be defined 5 % In Problem structure field b with the training set needs to be defined
6 % In DL fields with name of the toolbox and solver, and parameters file 6 % In DL fields with name of the toolbox and solver, and parameters file
7 % for particular dictionary learning technique needs to be present. 7 % for particular dictionary learning technique needs to be present.
8 % 8 %
9 % Outputs are Learned dictionary and time spent as a part of DL structure 9 % Outputs are Learned dictionary and time spent as a part of DL structure
10 10
11 % 11 %
16 % modify it under the terms of the GNU General Public License as 16 % modify it under the terms of the GNU General Public License as
17 % published by the Free Software Foundation; either version 2 of the 17 % published by the Free Software Foundation; either version 2 of the
18 % License, or (at your option) any later version. See the file 18 % License, or (at your option) any later version. See the file
19 % COPYING included with this distribution for more information. 19 % COPYING included with this distribution for more information.
20 %% 20 %%
21
22 SMALLboxInit
23
21 if (DL.profile) 24 if (DL.profile)
22 fprintf('\nStarting Dictionary Learning %s... \n', DL.name); 25 fprintf('\nStarting Dictionary Learning %s... \n', DL.name);
23 end 26 end
24 start=cputime;
25 tStart=tic;
26 if strcmpi(DL.toolbox,'KSVD')
27 param=DL.param;
28 param.data=Problem.b;
29
30 D = eval([DL.name,'(param)']);%, ''t'', 5);']);
31 elseif strcmpi(DL.toolbox,'KSVDS')
32 param=DL.param;
33 param.data=Problem.b;
34
35 D = eval([DL.name,'(param, ''t'', 5);']);
36 elseif strcmpi(DL.toolbox,'SPAMS')
37
38 X = Problem.b;
39 param=DL.param;
40
41 D = eval([DL.name,'(X, param);']);
42 % As some versions of SPAMS does not produce unit norm column
43 % dictionaries, we need to make sure that columns are normalised to
44 % unit lenght.
45
46 for i = 1: size(D,2)
47 D(:,i)=D(:,i)/norm(D(:,i));
48 end
49 elseif strcmpi(DL.toolbox,'SMALL')
50
51 X = Problem.b;
52 param=DL.param;
53
54 D = eval([DL.name,'(X, param);']);
55 % we need to make sure that columns are normalised to
56 % unit lenght.
57
58 for i = 1: size(D,2)
59 D(:,i)=D(:,i)/norm(D(:,i));
60 end
61
62 elseif strcmpi(DL.toolbox,'TwoStepDL')
63
64 DL=SMALL_two_step_DL(Problem, DL);
65
66 % we need to make sure that columns are normalised to
67 % unit lenght.
68
69 for i = 1: size(DL.D,2)
70 DL.D(:,i)=DL.D(:,i)/norm(DL.D(:,i));
71 end
72 D = DL.D;
73
74 elseif strcmpi(DL.toolbox,'MMbox')
75
76 DL = wrapper_mm_DL(Problem, DL);
77
78 % we need to make sure that columns are normalised to
79 % unit lenght.
80
81 for i = 1: size(DL.D,2)
82 DL.D(:,i)=DL.D(:,i)/norm(DL.D(:,i));
83 end
84 D = DL.D;
85
86 % To introduce new dictionary learning technique put the files in
87 % your Matlab path. Next, unique name <TolboxID> for your toolbox needs
88 % to be defined and also prefferd API for toolbox functions <Preffered_API>
89 %
90 % elseif strcmpi(DL.toolbox,'<ToolboxID>')
91 % % This is an example of API that can be used:
92 % % - get training set from Problem part of structure
93 % % - assign parameters defined in the main program
94 %
95 % X = Problem.b;
96 % param=DL.param;
97 %
98 % % - Evaluate the function (DL.name - defined in the main) with
99 % % parameters given above
100 %
101 % D = eval([DL.name,'(<Preffered_API>);']);
102 27
103 else 28 start=cputime;
104 printf('\nToolbox has not been registered. Please change SMALL_learn file.\n'); 29 tStart=tic;
105 return 30
106 end 31 % toolboxes configuration file
107 32 run(fullfile(SMALL_path, 'config/SMALL_learn_config.m'));
33
108 %% 34 %%
109 % Dictionary Learning time 35 % Dictionary Learning time
110 tElapsed=toc(tStart); 36 tElapsed=toc(tStart);
111 DL.time = cputime - start; 37 DL.time = cputime - start;
112 if (DL.profile) 38 if (DL.profile)
113 fprintf('\n%s finished task in %2f seconds (cpu time). \n', DL.name, DL.time); 39 fprintf('\n%s finished task in %2f seconds (cpu time). \n', DL.name, DL.time);
114 fprintf('\n%s finished task in %2f seconds (tic-toc time). \n', DL.name, tElapsed); 40 fprintf('\n%s finished task in %2f seconds (tic-toc time). \n', DL.name, tElapsed);
115 end 41 end
116 DL.time=tElapsed; 42 DL.time=tElapsed;
117 % If dictionary is given as a sparse matrix change it to full 43 % If dictionary is given as a sparse matrix change it to full
118 44
119 DL.D = full(D); 45 DL.D = full(D);
120 46
121 end 47 end
122 48