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