comparison core/magnatagatune/MTTMixedFeatureSon.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 classdef MTTMixedFeatureSon < MTTAudioFeature & handle
2 % ---
3 % This Class contains a wrapper for sons feature extraction
4 %
5 % The usual workflow for these features constist of three steps
6 % 1. extract: extracts the basic single-file dependent features
7 % 2. define_global_transform: calculates the global feature
8 % transformation parameters
9 % 3. finalise: applies the common transformations to a specific feature
10 % ---
11
12 properties(Constant = true)
13
14 % svn hook
15 my_revision = str2double(substr('$Rev: 741 $', 5, -1));
16 end
17
18 properties
19 % ---
20 % Set default parameters
21 % ---
22 my_params = struct( ...
23 'son_filename','features_rbm_50x1010', ...
24 'son_conf', '' ...
25 );
26 end
27
28 % ---
29 % member functions
30 % ---
31 methods
32
33 % ---
34 % constructor: pointer to feature in database
35 % ---
36 function feature = MTTMixedFeatureSon(varargin)
37
38 feature = feature@MTTAudioFeature(varargin{:});
39
40 end
41 % ---
42 % extract feature data from raw audio features
43 % ---
44 function data = extract(feature, clip)
45 % ---
46 % get features. this includes possible
47 % local normalisations
48 % ---
49
50 global globalvars;
51 global comparison_ids;
52 global sonfeatbase;
53 global db_MTTClip;
54
55 if isempty(sonfeatbase);
56 sonfeatbase = load(feature.my_params.son_filename);
57 end
58 %
59
60 % ---
61 % note: this should reference clip.my_db
62 % get the actual clip id
63 idx = db_MTTClip.comparison_ids(clip.id);
64
65 % ---
66 % NOTE: we just copy everything in a big matrix and then
67 % normalise the data later
68 % ---
69 if isfield(sonfeatbase,'nfvec')
70 rawf = sonfeatbase.nfvec;
71 elseif isfield(sonfeatbase,'sonfeatures')
72 rawf = sonfeatbase.sonfeatures';
73 end
74
75 if idx <= size(rawf,2)
76
77 % get the vector from loaded data
78 data.sonraw = rawf(:,idx);
79
80 else
81 % ---
82 % CAVE: Clip indices outside
83 % the range of the supplied mat file
84 % are filled up with zeros
85 % ---
86 data.sonraw = zeros(size(rawf,1),1);
87 end
88
89
90
91 data.vector_info = {'Sonfeat'};
92 % padd further info struct
93 data.vector_info(end+1:size(data.sonraw,1)) =...
94 cell(size(data.sonraw,1) - numel(data.vector_info) , 1);
95
96 % ---
97 % prepare field for final features
98 % ---
99 data.final.vector = [];
100 data.final.vector_info = struct();
101 data.final.dim = 0;
102
103 % save info data
104 data.info.type = 'MTTMixedFeatureSon';
105 data.info.owner_id = clip.id;
106 data.info.creatorrev = feature.my_revision;
107
108 % save parameters
109 data.info.params = feature.my_params;
110 end
111
112 function define_global_transform(features)
113 % calculate and set normalization factors from the group of
114 % input features. These features will be set for the full database
115
116 final = zeros(size(features(1).data.sonraw,1), numel(features));
117 for i = 1:numel(features)
118 if ~isempty(features(i).data.sonraw)
119 final(:,i) = features(i).data.sonraw;
120 end
121 end
122
123 % set common to 1 to tell normalisation is done
124 features(1).my_db.set_common([1]);
125
126 % save the normalised features straight away!
127 features.finalise(final);
128 end
129
130
131 function finalise(features, final)
132 % applies a final transformation and
133 % collects the information of this feature within a single vector
134 % see info for types in specific dimensions
135 % check if features have been finalised already
136
137 % ---
138 % set feature labelling
139 % ---
140
141 info = {};
142
143 % ---
144 % construct resulting feature vector out of features
145 % ---
146 if nargin == 2 && isempty(final)
147
148 % the final vector etc already are set to zero;
149 return;
150
151 elseif nargin == 2 && (numel(features) == size(final, 2))
152 % the features have already been preassembled
153
154 for i = 1:numel(features)
155
156 % check for neccesary parameters
157 if isempty(features(i).my_db.commondb)
158
159 error('Define the global transformation first')
160 return;
161 end
162
163 features(i).data.final.vector = final(:,i);
164 features(i).data.final.dim = size(final,1);
165
166 % fill up info struct and append to feature
167 features(i).data.final.vector_info.labels = ...
168 features(i).data.vector_info;
169 end
170 else
171 % ---
172 % if features have been added after gettin gnormalisation
173 % parameters, ther should be still an option to include
174 % them
175 % ---
176
177 for i = 1:numel(features)
178
179 % check for neccesary parameters
180 if isempty(features(i).my_db.commondb)
181
182 error('Define the global transformation first')
183 return;
184 end
185
186 final = zeros(numel(features(1).data.sonraw), numel(features));
187 for i = 1:numel(features)
188 if ~isempty(features(i).data.sonraw)
189 final(:,i) = features(i).data.sonraw;
190 end
191 end
192 features(i).data.final.vector = final;
193 features(i).data.final.dim = size(final,1);
194
195 % fill up info struct and append to feature
196 features(i).data.final.vector_info.labels = ...
197 features(i).data.vector_info;
198 end
199
200 end
201
202 % ---
203 % TODO: Maybe delete more basic features again at this point?
204 % ---
205 end
206
207 % ---
208 % destructor: do we really want to remove this
209 % from the database? No, but
210 % TODO: create marker for unused objects in db, and a cleanup
211 % function
212 % ---
213 function delete(feature)
214
215 end
216 end
217 end