Mercurial > hg > smallbox
comparison util/SMALL_learn.m @ 224:fd0b5d36f6ad danieleb
Updated the contents of this branch with the contents of the default branch.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Thu, 12 Apr 2012 13:52:28 +0100 |
parents | 7426503fc4d1 a986ee86651e |
children |
comparison
equal
deleted
inserted
replaced
196:82b0d3f982cb | 224:fd0b5d36f6ad |
---|---|
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 | 27 |
86 elseif strcmpi(DL.toolbox,'dl_ramirez') | 28 start=cputime; |
87 DL = dl_ramirez(Problem,DL); | 29 tStart=tic; |
88 D = normcol(DL.D); | |
89 | |
90 % To introduce new dictionary learning technique put the files in | |
91 % your Matlab path. Next, unique name <TolboxID> for your toolbox needs | |
92 % to be defined and also prefferd API for toolbox functions <Preffered_API> | |
93 % | |
94 % elseif strcmpi(DL.toolbox,'<ToolboxID>') | |
95 % % This is an example of API that can be used: | |
96 % % - get training set from Problem part of structure | |
97 % % - assign parameters defined in the main program | |
98 % | |
99 % X = Problem.b; | |
100 % param=DL.param; | |
101 % | |
102 % % - Evaluate the function (DL.name - defined in the main) with | |
103 % % parameters given above | |
104 % | |
105 % D = eval([DL.name,'(<Preffered_API>);']); | |
106 | 30 |
107 else | 31 % toolboxes configuration file |
108 printf('\nToolbox has not been registered. Please change SMALL_learn file.\n'); | 32 run(fullfile(SMALL_path, 'config/SMALL_learn_config.m')); |
109 return | 33 |
110 end | |
111 | |
112 %% | 34 %% |
113 % Dictionary Learning time | 35 % Dictionary Learning time |
114 tElapsed=toc(tStart); | 36 tElapsed=toc(tStart); |
115 DL.time = cputime - start; | 37 DL.time = cputime - start; |
116 if (DL.profile) | 38 if (DL.profile) |
117 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); |
118 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); |
119 end | 41 end |
120 DL.time=tElapsed; | 42 DL.time=tElapsed; |
121 % 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 |
122 | 44 |
123 DL.D = full(D); | 45 DL.D = full(D); |
124 | 46 |
125 end | 47 end |
126 | 48 |