comparison util/SMALL_learn.m @ 36:e6191f5bb21b

(none)
author idamnjanovic
date Mon, 14 Mar 2011 15:32:52 +0000
parents fc395272d53e
children f6cc633fd94b
comparison
equal deleted inserted replaced
35:ea9ef4bd7102 36:e6191f5bb21b
18 % Outputs are Learned dictionary and time spent as a part of DL structure 18 % Outputs are Learned dictionary and time spent as a part of DL structure
19 %% 19 %%
20 20
21 fprintf('\nStarting Dictionary Learning %s... \n', DL.name); 21 fprintf('\nStarting Dictionary Learning %s... \n', DL.name);
22 start=cputime; 22 start=cputime;
23 23 tStart=tic;
24 if strcmpi(DL.toolbox,'KSVD') 24 if strcmpi(DL.toolbox,'KSVD')
25 param=DL.param; 25 param=DL.param;
26 param.data=Problem.b; 26 param.data=Problem.b;
27 27
28 D = eval([DL.name,'(param, ''t'', 5);']); 28 D = eval([DL.name,'(param)']);%, ''t'', 5);']);
29 elseif strcmpi(DL.toolbox,'KSVDS') 29 elseif strcmpi(DL.toolbox,'KSVDS')
30 param=DL.param; 30 param=DL.param;
31 param.data=Problem.b; 31 param.data=Problem.b;
32 32
33 D = eval([DL.name,'(param, ''t'', 5);']); 33 D = eval([DL.name,'(param, ''t'', 5);']);
42 % unit lenght. 42 % unit lenght.
43 43
44 for i = 1: size(D,2) 44 for i = 1: size(D,2)
45 D(:,i)=D(:,i)/norm(D(:,i)); 45 D(:,i)=D(:,i)/norm(D(:,i));
46 end 46 end
47 elseif strcmpi(DL.toolbox,'SMALL')
47 48
49 X = Problem.b;
50 param=DL.param;
51
52 D = eval([DL.name,'(X, param);']);
53 % we need to make sure that columns are normalised to
54 % unit lenght.
55
56 for i = 1: size(D,2)
57 D(:,i)=D(:,i)/norm(D(:,i));
58 end
59 elseif strcmpi(DL.toolbox,'mpv2')
60 X = Problem.b(:,1:1:40000);
61 jD0 = mpv2.SimpleMatrix(DL.param.D);
62 jDicLea = mpv2.DictionaryLearning(jD0, 1,1);
63 % !!!!! MAYBE lambda is not needed for ILS - NEED TO CHECK!!!!
64 jDicLea.setLambda('L', DL.param.lambda, DL.param.lambda, 1000);
65 jDicLea.setVerbose(2);
66 jDicLea.setORMP(16, 1e-6, DL.param.abs);
67 eval(['jDicLea.',DL.name,'( X(:), DL.param.iternum );']);
68 jD = jDicLea.getDictionary();
69
70 D = reshape(jD.getAll(), size(X,1), DL.param.K);
71
48 % To introduce new dictionary learning technique put the files in 72 % To introduce new dictionary learning technique put the files in
49 % your Matlab path. Next, unique name <TolboxID> for your toolbox needs 73 % your Matlab path. Next, unique name <TolboxID> for your toolbox needs
50 % to be defined and also prefferd API for toolbox functions <Preffered_API> 74 % to be defined and also prefferd API for toolbox functions <Preffered_API>
51 % 75 %
52 % elseif strcmpi(DL.toolbox,'<ToolboxID>') 76 % elseif strcmpi(DL.toolbox,'<ToolboxID>')
67 return 91 return
68 end 92 end
69 93
70 %% 94 %%
71 % Dictionary Learning time 95 % Dictionary Learning time
72 96 tElapsed=toc(tStart);
73 DL.time = cputime - start; 97 DL.time = cputime - start;
74 fprintf('\n%s finished task in %2f seconds. \n', DL.name, DL.time); 98 fprintf('\n%s finished task in %2f seconds. \n', DL.name, DL.time);
75 99 fprintf('\n%s finished task in %2f seconds. \n', DL.name, tElapsed);
100 DL.time=tElapsed;
76 % If dictionary is given as a sparse matrix change it to full 101 % If dictionary is given as a sparse matrix change it to full
77 102
78 DL.D = full(D); 103 DL.D = full(D);
79 104
80 end 105 end