comparison util/SMALL_learn.m @ 8:33850553b702

(none)
author idamnjanovic
date Mon, 22 Mar 2010 10:56:54 +0000
parents
children fc395272d53e
comparison
equal deleted inserted replaced
7:0151f1ea080d 8:33850553b702
1 function DL = SMALL_learn(Problem,DL)
2 %%% SMALL Dictionary Learning
3 % Ivan Damnjanovic 2009
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
6 % In DL fields with name of the toolbox and solver, and parameters file
7 % for particular dictionary learning technique needs to be present.
8 %
9 % Outputs are Learned dictionary and time spent as a part of DL structure
10 %%
11
12 fprintf('\nStarting Dictionary Learning %s... \n', DL.name);
13 start=cputime;
14
15 if strcmpi(DL.toolbox,'KSVD')
16 param=DL.param;
17 param.data=Problem.b;
18
19 D = eval([DL.name,'(param, ''t'', 5);']);
20 elseif strcmpi(DL.toolbox,'KSVDS')
21 param=DL.param;
22 param.data=Problem.b;
23
24 D = eval([DL.name,'(param, ''t'', 5);']);
25 elseif strcmpi(DL.toolbox,'SPAMS')
26
27 X = Problem.b;
28 param=DL.param;
29
30 D = eval([DL.name,'(X, param);']);
31 % As some versions of SPAMS does not produce unit norm column
32 % dictionaries, we need to make sure that columns are normalised to
33 % unit lenght.
34
35 for i = 1: size(D,2)
36 D(:,i)=D(:,i)/norm(D(:,i));
37 end
38
39 % To introduce new dictionary learning technique put the files in
40 % your Matlab path. Next, unique name <TolboxID> for your toolbox needs
41 % to be defined and also prefferd API for toolbox functions <Preffered_API>
42 %
43 % elseif strcmpi(DL.toolbox,'<ToolboxID>')
44 % % This is an example of API that can be used:
45 % % - get training set from Problem part of structure
46 % % - assign parameters defined in the main program
47 %
48 % X = Problem.b;
49 % param=DL.param;
50 %
51 % % - Evaluate the function (DL.name - defined in the main) with
52 % % parameters given above
53 %
54 % D = eval([DL.name,'(<Preffered_API>);']);
55
56 else
57 printf('\nToolbox has not been registered. Please change SMALL_learn file.\n');
58 return
59 end
60
61 %%
62 % Dictionary Learning time
63
64 DL.time = cputime - start;
65 fprintf('\n%s finished task in %2f seconds. \n', DL.name, DL.time);
66
67 % If dictionary is given as a sparse matrix change it to full
68
69 DL.D = full(D);
70
71 end
72