Mercurial > hg > camir-aes2014
comparison core/magnatagatune/MTTMixedFeatureSlaney08GenreBasicSmRBM.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 % -- | |
2 % This class loads and hanles the aufdio features included with the MTT | |
3 % Library | |
4 % | |
5 % Features are extracted and then porcessed by son's RBM toolbox | |
6 % --- | |
7 classdef MTTMixedFeatureSlaney08GenreBasicSmRBM < MTTAudioFeature & handle | |
8 | |
9 properties(Constant = true) | |
10 | |
11 my_revision = str2double(substr('$Rev: 457 $', 5, -1)); | |
12 end | |
13 | |
14 properties | |
15 | |
16 % --- | |
17 % Set default parameters | |
18 % --- | |
19 my_basetype = 'MTTMixedFeatureSlaney08GenreBasicSm'; | |
20 | |
21 my_params = MTTAudioFeature.inherited_params(... | |
22 'MTTMixedFeatureSlaney08GenreBasicSm', ... | |
23 ... % --- | |
24 ... % Following: RBM params | |
25 ... % --- | |
26 'norm_pre_rbm', 0, ... % norm before RBM? | |
27 'norm_post_rbm', 0, ... % norm before RBM? | |
28 'rbm_hidNum',200, ... % number of hidden units | |
29 'rbm_eNum', 100, ... | |
30 'rbm_bNum', 1, ... | |
31 'rbm_gNum', 1, ... | |
32 'rbm_lrate1' , 0.05, ... % initial learning rate | |
33 'rbm_lrate2', 0.1, ... % learning rate | |
34 'rbm_momentum', 0.5, ... | |
35 'rbm_cost', 0.00002, ... % cost function | |
36 'rbm_N', 50, ... | |
37 'rbm_MAX_INC', 10 ... | |
38 ); | |
39 end | |
40 % --- | |
41 % member functions | |
42 % --- | |
43 methods | |
44 | |
45 % --- | |
46 % constructor: pointer to feature in database | |
47 % --- | |
48 function feature = MTTMixedFeatureSlaney08GenreBasicSmRBM(varargin) | |
49 | |
50 feature = feature@MTTAudioFeature(varargin{:}); | |
51 end | |
52 | |
53 % --- | |
54 % load feature data from xml file | |
55 % --- | |
56 function data = extract(feature, clip) | |
57 % load feature data by parsing xml | |
58 | |
59 global globalvars; | |
60 | |
61 % --- | |
62 % we extract the base features, and save | |
63 % the pointers to these. | |
64 % the main work is then done in the define_global_transf | |
65 % and finalise functions. | |
66 % --- | |
67 data.basefeat = clip.features(feature.my_basetype,... | |
68 feature.my_params); | |
69 | |
70 % save info data | |
71 data.info.type = class(feature); | |
72 data.info.owner = clip; | |
73 data.info.owner_id = clip.id; | |
74 data.info.creatorrev = feature.my_revision; | |
75 | |
76 % save param data | |
77 data.info.params = feature.my_params; | |
78 | |
79 % prepare field for final features | |
80 data.final.vector = []; | |
81 data.final.dim = 0; | |
82 data.final.vector_info.labels = {}; | |
83 end | |
84 | |
85 function define_global_transform(features) | |
86 | |
87 if numel(features) == 1 | |
88 error ('Insert feature array for this method'); | |
89 end | |
90 | |
91 % --- | |
92 % We collect all the relevant genretag | |
93 % features and get the transform on this basis. | |
94 % --- | |
95 for i = 1:numel(features) | |
96 basef(i) = features(i).data.basefeat; | |
97 end | |
98 | |
99 % call the features own transsform function | |
100 basef.define_global_transform(); | |
101 | |
102 % --- | |
103 % finalise the basic features, and | |
104 % get the feature vectors; | |
105 % --- | |
106 X = basef.vector(); | |
107 | |
108 % check dataset dimension | |
109 if numel(features) < basef.dim; | |
110 | |
111 error ('Not enough feature vectors for RBM calculation. need %d samples', ... | |
112 basef.dim); | |
113 end | |
114 | |
115 % --- | |
116 % NOTE: should the data be normalised and scaled to -1:1 | |
117 % instead of being in a range of 0-1 AND max-min = 1 | |
118 % --- | |
119 if features(1).my_params.norm_pre_rbm == 1 | |
120 | |
121 [X, pstd] = mapminmax(X,-1,1); | |
122 common.rbm.pre_norm = pstd; | |
123 elseif features(1).my_params.norm_pre_rbm == 2 | |
124 | |
125 [X, pstd] = mapstd(X,0,1); | |
126 common.rbm.pre_norm = pstd; | |
127 end | |
128 | |
129 | |
130 % --- | |
131 % TRAIN RBM | |
132 % --- | |
133 conf.sNum = size(X,2); | |
134 conf.eNum = features(1).my_params.rbm_eNum; | |
135 conf.bNum = features(1).my_params.rbm_bNum; | |
136 conf.gNum = features(1).my_params.rbm_gNum; | |
137 conf.hidNum = features(1).my_params.rbm_hidNum; | |
138 conf.MAX_INC = features(1).my_params.rbm_MAX_INC; | |
139 conf.N = features(1).my_params.rbm_N; | |
140 conf.params = [ features(1).my_params.rbm_lrate1 features(1).my_params.rbm_lrate2 ... | |
141 features(1).my_params.rbm_momentum features(1).my_params.rbm_cost]; | |
142 W1 = zeros(0,0); | |
143 [common.rbm.W1 common.rbm.vB1 common.rbm.hB1] = training_rbm_(conf,W1,X'); | |
144 | |
145 % --- | |
146 % This transforms the features using the learnt RBM | |
147 % --- | |
148 Y = logistic(X' * common.rbm.W1 + repmat(common.rbm.hB1,conf.sNum,1))'; | |
149 | |
150 | |
151 % normalise values after processing | |
152 if features(1).my_params.norm_post_rbm | |
153 | |
154 [Y,pmm] = mapminmax(Y,0,1); | |
155 common.rbm.post_norm = pmm; | |
156 end | |
157 | |
158 % --- | |
159 % set common feature values for mixed features | |
160 % --- | |
161 features(1).my_db.set_common(common); | |
162 | |
163 % save the transformed features straight away! | |
164 features.finalise(Y); | |
165 end | |
166 | |
167 function finalise(feature, final) | |
168 % applies a final transformation and | |
169 % collects the information of this feature within a single vector | |
170 % see info for types in specific dimensions | |
171 | |
172 max_size = feature(1).my_params.rbm_hidNum; | |
173 | |
174 % prepare information | |
175 info = {'RBM'}; | |
176 info(2:max_size) = num2cell(2:max_size); | |
177 | |
178 % check if features have been finalised already | |
179 if nargin == 2 && isempty(final) | |
180 | |
181 % the final vector etc already are set to zero; | |
182 return; | |
183 | |
184 elseif nargin == 2 && (numel(feature) == size(final, 2)) | |
185 | |
186 for i = 1:numel(feature) | |
187 | |
188 % save final vector and description | |
189 feature(i).data.final.vector = final(:,i); | |
190 feature(i).data.final.dim = max_size; | |
191 feature(i).data.final.vector_info.labels = info; | |
192 end | |
193 | |
194 else | |
195 % features have to be transformed first | |
196 % --- | |
197 % TODO: this code remains untested | |
198 % --- | |
199 | |
200 % check for neccesary parameters | |
201 if isempty(feature(1).my_db.commondb) | |
202 | |
203 error('Define the global transformation first') | |
204 return; | |
205 end | |
206 | |
207 | |
208 for i = 1:numel(feature) | |
209 | |
210 % check for neccesary parameters | |
211 if isempty(feature(i).my_db.commondb) | |
212 | |
213 error('Define the global transformation first') | |
214 end | |
215 | |
216 % --- | |
217 % get feature vector and apply transformation | |
218 % --- | |
219 X = feature(i).data.basefeat.vector(); | |
220 | |
221 % --- | |
222 % apply normalisation used for removing mean | |
223 % in training data | |
224 % --- | |
225 if feature(1).my_params.norm_pre_rbm == 1 | |
226 | |
227 X = mapminmax('apply', X, feature(1).common.rbm.pre_norm); | |
228 elseif feature(1).my_params.norm_pre_rbm == 2 | |
229 | |
230 X = mapstd('apply', X, feature(1).common.rbm.pre_norm); | |
231 end | |
232 | |
233 % --- | |
234 % RBM: This transforms the features using the learnt RBM | |
235 % --- | |
236 conf.sNum = size(X,1); | |
237 vec = logistic(X * common.rbm.W1 + repmat(common.rbm.hB1,conf.sNum,1)); | |
238 | |
239 | |
240 % normalise pca values after transformation | |
241 if feature(1).my_params.norm_post_rbm | |
242 | |
243 vec = mapminmax('apply', vec,... | |
244 feature(1).common.rbm.post_norm); | |
245 end | |
246 | |
247 % --- | |
248 % cut vector to final size. | |
249 % NOTE: this should be done before | |
250 % transformation to reduce computation time | |
251 % --- | |
252 vec = vec(1:max_size); | |
253 | |
254 % save final vector and description | |
255 feature(i).data.final.vector = vec; | |
256 feature(i).data.final.dim = numel(vec); | |
257 feature(i).data.final.vector_info.labels = info; | |
258 end | |
259 end | |
260 end | |
261 | |
262 end | |
263 end |