-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_tx_reco.m
226 lines (199 loc) · 8.79 KB
/
main_tx_reco.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
clearvars;
close all force;
addpath('functions')
%addpath('/home/vincent/idv/generichots/matlab')
addpath('../libsvm/matlab')
%% Variables initialization
path_timit = '/home/vincent/idv/Cochlea/timit/timit/';
curr_data_folder = 'hots_data';
path_data = fullfile(pwd, curr_data_folder);
aff = 0;
create_events = 1;
mode_event_generation = 'spikegram_jittered';
launch_hots = 1;
nb_levels_crossing = 50;
ratio_hots_learning_of_train_timit = 0.05;
ratio_classif_learning_of_train_timit = 0.15;
ratio_classif_test_of_test_timit = 0.20;
params.path_data = path_data;
params.nbLayers = 2;
params.nbCenters = [8, 32, 128, 32, 256];
params.tau = [10000., 50000., 250000., 640000., 256000.];
params.radius = [5, 10, 15, 25, 35];
params.ksi = [2e-5, 4e-4, 4e-4, 4e-4, 4e-4];
params.nPow = 3;
params.nbDim = 1;
params.nbChannels = nb_levels_crossing;
params.typeCenters = 2;
if create_events
ratios = [ratio_hots_learning_of_train_timit, ratio_classif_learning_of_train_timit, ...
ratio_classif_test_of_test_timit];
create_events_from_timit_database(path_timit, ratios, nb_levels_crossing, mode_event_generation)
end
file_ev_train_hots = [path_timit, 'train_hots.dat'];
file_ev_train = [path_timit, 'train_classif.dat'];
file_label_train = [path_timit, 'train_classif.label'];
file_ev_test = [path_timit, 'test_classif.dat'];
file_label_test = [path_timit, 'test_classif.label'];
[events_train_hots] = load_audio_data(file_ev_train_hots);
[events_train] = load_audio_data(file_ev_train);
[events_test] = load_audio_data(file_ev_test);
[label_train_phon] = load_labels(file_label_train);
[label_test_phon] = load_labels(file_label_test);
% Critique : verifier l'output dans la fonction (notamment si toutes les
% classes apparaissent au moins une fois
type_classes_label = 0;
[label_train, classes_phon_1] = change_class_labels(label_train_phon, type_classes_label);
[label_test] = change_class_labels(label_test_phon, type_classes_label);
events_train_hots.p = zeros(size(events_train_hots.p));
events_train.p = zeros(size(events_train.p));
events_test.p = zeros(size(events_test.p));
params.nbPols = numel(unique(events_train_hots.p));
if launch_hots
% eventsname = {'events_train_hots.dat', 'events_train_classif.dat', 'events_test_classif.dat'};
% gen_file_ev_train_hots = fullfile(params.path_data, eventsname{1});
% gen_file_ev_train = fullfile(params.path_data, eventsname{2});
% gen_file_ev_test = fullfile(params.path_data, eventsname{3});
% system(['cp -f ', file_ev_train_hots, ' ', gen_file_ev_train_hots]);
% system(['cp -f ', file_ev_train, ' ', gen_file_ev_train]);
% system(['cp -f ', file_ev_test, ' ', gen_file_ev_test]);
% compute_generic_hots(params);
% ^ those remplace this one, slower
compute_generic_hots(params, events_train_hots, events_train, events_test);
end
[centers, events, events2] = read_generichots_output(params);
% [centers, events] = compute_matlab_hots(params, events_train_hots, events_train, events_test);
ceil(100*density_centers(centers))
%% Affichages
if aff
occs = cell(1,params.nbLayers);
nb_plots = numel(events);
if nb_plots > 4
nb_plots_x = 2;
nb_plots_y = ceil(nb_plots/2);
else
nb_plots_x = 1;
nb_plots_y = nb_plots;
end
handle_subp = [];
figure;
for ind = 1:nb_plots
handle_subp(ind) = subplot(nb_plots_y,nb_plots_x,ind);
plot_events(events{ind});
if ind == 1
title('input');
else
title(['output of layer ', num2str(ind)-1]);
end
end
linkaxes(handle_subp);
axis([5.15e7 5.45e7 0 49])
for ind = 1:params.nbLayers
occs(ind) = {occurancies_centers(centers{ind}, events{ind+1})};
plot_centers(centers{ind}, occs{ind}, 8);
% plot_centers_temporal(centers{ind}, occs{ind}, params.tau(ind), 4);
% figure;
% plot_events(events{ind+1});
figure;
sbp1 = subplot(311);
plot_events(events{ind+1});
sbp2 = subplot(312);
plot_events_labelcolor(events{ind+1}, label_train, classes_phon_1)
sbp3 = subplot(313);
events_zero.ts = 0:500:label_train{2}(end);
events_zero.level = floor(nb_levels_crossing/2)*ones(size(events_zero.ts));
events_zero.channel = events_zero.level;
events_zero.p = events_zero.level;
plot_events_labelcolor(events_zero, label_train, classes_phon_1)
linkaxes([sbp1, sbp2, sbp3]);
axis([5.15e7 5.45e7 0 49])
end
end
disp('phase 1 terminee')
%% Reco
for type_classes_label = [2,1,3,0]
[label_train, classes_phon_1] = change_class_labels(label_train_phon, type_classes_label);
[label_test] = change_class_labels(label_test_phon, type_classes_label);
% label_train
% [label_train{1}(end-5:end), label_train{2}(end-5:end), label_train{3}(end-5:end)]
% label_test
% [label_test{1}(end-5:end), label_test{2}(end-5:end), label_test{3}(end-5:end)]
% for ind = 1:params.nbLayers+1
% events{ind}
% events2{ind}
% [events{ind}.ts(end-5:end), events{ind}.level(end-5:end)]
% [events2{ind}.ts(end-5:end), events2{ind}.level(end-5:end)]
% end
all_sigs_train = compute_all_signatures1D_from_events(events{params.nbLayers+1}, label_train, ...
params.nbCenters(params.nbLayers));
all_sigs_test = compute_all_signatures1D_from_events(events2{params.nbLayers+1}, label_test, ...
params.nbCenters(params.nbLayers));
% labels = all_sigs_train(:,1);
% features = all_sigs_train(:,3:end).*repmat(all_sigs_train(:,2),1,size(all_sigs_train,2)-2);
% save('test_features_non_norm_mar24_16h40.mat','labels','features');
max_k = 50;
reco_rate_metasigs = compute_reco_using_metasigs(all_sigs_train, all_sigs_test);
reco_rate_euclidean = compute_reco_using_kppv(all_sigs_train, all_sigs_test, max_k, 'euclidean');
reco_rate_bhattacharrya = compute_reco_using_kppv(all_sigs_train, all_sigs_test, max_k, 'bhattacharrya');
[max_reco_rate_euclidean, k_max_reco_rate_euclidean] = max(reco_rate_euclidean);
[max_reco_rate_bhattacharrya, k_max_reco_rate_bhattacharrya] = max(reco_rate_bhattacharrya);
reco_rate_mlp = compute_reco_using_mlp(all_sigs_train, all_sigs_test);
reco_rate_svm = compute_reco_using_svm(all_sigs_train, all_sigs_test);
switch type_classes_label
case 0
type = 'TIMIT phonemas, 61 classes';
case 1
type = 'Reynolds & Antoniou (2003), 7 classes';
case 2
type = 'Halberstadt (1998), 3 classes';
case 3
type = 'Lee & Hon (1989), 36 classes';
otherwise
error('wtf type_classes_label');
end
fprintf('-> Type %s :\n', type);
fprintf('Recognition rate with meta signatures : %d%%\n', floor(reco_rate_metasigs*100));
fprintf('Recognition rate with kppv (euclidean) : %d%% with k=%d\n', ...
floor(max_reco_rate_euclidean*100), k_max_reco_rate_euclidean);
fprintf('Recognition rate with kppv (bhattacharrya) : %d%% with k=%d\n', ...
floor(max_reco_rate_bhattacharrya*100), k_max_reco_rate_bhattacharrya);
fprintf(['Recognition rate with MLP (trainscg, crossentropy, '...
'[100,1000] neurons in hidden layers : %d%%\n'], floor(reco_rate_mlp*100));
fprintf(['Recognition rate with SVM (C-SVC, default parameters, no shrinking): %d%%\n\n'], floor(reco_rate_svm*100));
end
% if aff
% % draw_all_signatures(all_sigs_train);
% figure;
% plot(reco_rate, '*')
% axis([1 numel(reco_rate) 0 1])
% xlabel('k')
% ylabel('recognition rate')
% title('recognition rate of sigs using kppv');
% end
% -> Type Halberstadt (1998), 3 classes :
% Recognition rate with meta signatures : 61%
% Recognition rate with kppv (euclidean) : 67% with k=48
% Recognition rate with kppv (bhattacharrya) : 62% with k=22
% Recognition rate with MLP (trainscg, crossentropy, [100,1000] neurons in hidden layers : 68%
% Recognition rate with SVM (C-SVC, default parameters, no shrinking): 61%
%
% -> Type Reynolds & Antoniou (2003), 7 classes :
% Recognition rate with meta signatures : 25%
% Recognition rate with kppv (euclidean) : 37% with k=47
% Recognition rate with kppv (bhattacharrya) : 29% with k=16
% Recognition rate with MLP (trainscg, crossentropy, [100,1000] neurons in hidden layers : 42%
% Recognition rate with SVM (C-SVC, default parameters, no shrinking): 33%
%
% -> Type Lee & Hon (1989), 36 classes :
% Recognition rate with meta signatures : 2%
% Recognition rate with kppv (euclidean) : 19% with k=4
% Recognition rate with kppv (bhattacharrya) : 17% with k=12
% Recognition rate with MLP (trainscg, crossentropy, [100,1000] neurons in hidden layers : 31%
% Recognition rate with SVM (C-SVC, default parameters, no shrinking): 21%
%
% -> Type TIMIT phonemas, 61 classes :
% Recognition rate with meta signatures : 1%
% Recognition rate with kppv (euclidean) : 3% with k=49
% Recognition rate with kppv (bhattacharrya) : 5% with k=5
% Recognition rate with MLP (trainscg, crossentropy, [100,1000] neurons in hidden layers : 18%
% Recognition rate with SVM (C-SVC, default parameters, no shrinking): 0%