comparison Code/Classifiers/getConfusionMatrix.m @ 4:92ca03a8fa99 tip

Update to ICASSP 2013 benchmark
author Dawn Black
date Wed, 13 Feb 2013 11:02:39 +0000
parents
children
comparison
equal deleted inserted replaced
3:e1cfa7765647 4:92ca03a8fa99
1 function [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames,...
2 masterFileOutputID, distanceMeasure )
3
4 groupNames = char(groupNames);
5
6 % for emotion detection give the confusion matrix as
7 % -----------------------------------------------------------------
8 % positive correctly identified | positive incorrectly identified (1,2)
9 % negative incorrectly identified (2,1) | negative correctly identified
10 % ------------------------------------------------------------------
11 % which group has the most samples?
12 [maxValue, maxIndex] = max( groupStats );
13 maxGroup = groupNames( maxIndex,: );
14
15 % if we are performing emotion detection
16 if( ~isempty(strfind( groupNames(1,:), 'N' )) ...
17 || ~isempty(strfind( groupNames(1,:), 'P' )))
18 confusionMatrix = zeros(2,2);
19
20 % check groups for any missing
21 if( length(groupStats) < 4 )
22 % find the missing group
23 if( groupFind( groupNames, 'N1' ) == 0 )
24 % missing N1
25 groupNames = [groupNames; 'N1'];
26 groupStats = [groupStats 0];
27 end
28 if( groupFind( groupNames, 'N2' ) == 0 )
29 % missing N2
30 groupNames = [groupNames; 'N2'];
31 groupStats = [groupStats 0];
32 end
33 if( groupFind( groupNames, 'P1' ) == 0 )
34 % missing P1
35 groupNames = [groupNames; 'P1'];
36 groupStats = [groupStats 0];
37 end
38 if( groupFind( groupNames, 'P2' ) == 0 )
39 %missing P2
40 groupNames = [groupNames; 'P2'];
41 groupStats = [groupStats 0];
42 end
43 end
44 % let the group with the maximum success (either 1 or 2) be the
45 % cluster for that emotion
46 if( strfind( maxGroup, 'N' ))
47 % negative samples were detected most reliably
48 confusionMatrix(2,2) = maxValue;
49 if( strfind( maxGroup, '1' ))
50 % group 1 is the negative group
51 % find the number of positive samples incorrectly identified
52 idx = groupFind( groupNames, 'P1' );
53 confusionMatrix(1,2) = groupStats( idx );
54 % group 2 is the positive group
55 % find the number of positive samples correctly identified
56 idx = groupFind( groupNames, 'P2' );
57 confusionMatrix(1,1) = groupStats( idx );
58 % find the number of negative samples incorrectly identified
59 idx = groupFind( groupNames, 'N2' );
60 confusionMatrix(2,1) = groupStats( idx );
61 else
62 % group 2 is the negative group
63 % find the number of positive samples incorrectly identified
64 idx = groupFind( groupNames, 'P2' );
65 confusionMatrix(1,2) = groupStats( idx );
66 % group 1 is the positive group
67 % find the number of positive samples correctly identified
68 idx = groupFind( groupNames, 'P1' );
69 confusionMatrix(1,1) = groupStats( idx );
70 % find the number of negative samples incorrectly identified
71 idx = groupFind( groupNames, 'N1' );
72 confusionMatrix(2,1) = groupStats( idx );
73 end
74 else
75 % positive samples were detected most reliably
76 confusionMatrix(1,1) = maxValue;
77 if( strfind( maxGroup, '1' ))
78 % group 1 is the positive group
79 % find the number of positive samples incorrectly identified
80 idx = groupFind( groupNames, 'P2' );
81 confusionMatrix(1,2) = groupStats( idx );
82 % group 2 is the negative group
83 % find the number of negative samples correctly identified
84 idx = groupFind( groupNames, 'N2' );
85 confusionMatrix(2,2) = groupStats( idx );
86 % find the number of negative samples incorrectly identified
87 idx = groupFind( groupNames, 'N1' );
88 confusionMatrix(2,1) = groupStats( idx );
89 else
90 % group 2 is the positive group
91 % find the number of positive samples incorrectly identified
92 idx = groupFind( groupNames, 'P1' );
93 confusionMatrix(1,2) = groupStats( idx );
94 % group 1 is the negative group
95 % find the number of negative samples correctly identified
96 idx = groupFind( groupNames, 'N1' );
97 confusionMatrix(2,2) = groupStats( idx );
98 % find the number of negative samples incorrectly identified
99 idx = groupFind( groupNames, 'N2' );
100 confusionMatrix(2,1) = groupStats( idx );
101 end
102 end
103
104 confusionMatrix(3,3) = confusionMatrix(1,1) + confusionMatrix(2,2);
105 disp(distanceMeasure);
106 % print latex results to the screen
107 str1 = sprintf(' & %2.2f & %2.2f & \\\\', confusionMatrix(1,1), confusionMatrix(1,2) );
108 disp(str1);
109 str1 = sprintf(' & %2.2f & %2.2f & \\\\', confusionMatrix(2,1), confusionMatrix(2,2) );
110 disp(str1);
111 str1 = sprintf(' & & & %2.2f \\\\',confusionMatrix(3,3) );
112 disp(str1);
113 disp(' ');
114
115 fprintf( masterFileOutputID, '\n %f \t %f \n %f \t %f \n %f \t %f \t %f \n', confusionMatrix(1,1), confusionMatrix(1,2), confusionMatrix(2,1), confusionMatrix(2,2), 0, 0, confusionMatrix(3,3));
116 end
117
118 % for gender detection give the confusion matrix as
119 % --------------------------------------------------------------------
120 % male correctly identified as male | male incorrectly identified as female | male incorrectly identified as trans
121 % female incorrectly identified as male | female correctly identified | female incorrectly identified as trans
122 % trans incorrectly identified as male | trans incorrectly identified as female | trans correctly identified
123 % --------------------------------------------------------------------
124
125 % if we are performing gender detection
126 if( ~isempty(strfind( groupNames(1,:), 'F' )) ...
127 || ~isempty(strfind( groupNames(1,:), 'M' ))...
128 || ~isempty(strfind( groupNames(1,:), 'T' )))
129 confusionMatrix = zeros(3,3);
130
131 % check groups for any missing
132 if( length(groupStats) < 9 )
133 % find the missing group
134 if( groupFind( groupNames, 'M1' ) == 0 )
135 groupNames = [groupNames; 'M1'];
136 groupStats = [groupStats 0];
137 end
138 if( groupFind( groupNames, 'M2' ) == 0 )
139 groupNames = [groupNames; 'M2'];
140 groupStats = [groupStats 0];
141 end
142 if( groupFind( groupNames, 'M3' ) == 0 )
143 groupNames = [groupNames; 'M3'];
144 groupStats = [groupStats 0];
145 end
146 if( groupFind( groupNames, 'F1' ) == 0 )
147 groupNames = [groupNames; 'F1'];
148 groupStats = [groupStats 0];
149 end
150 if( groupFind( groupNames, 'F2' ) == 0 )
151 groupNames = [groupNames; 'F2'];
152 groupStats = [groupStats 0];
153 end
154 if( groupFind( groupNames, 'F3' ) == 0 )
155 groupNames = [groupNames; 'F3'];
156 groupStats = [groupStats 0];
157 end
158 if( groupFind( groupNames, 'T1' ) == 0 )
159 groupNames = [groupNames; 'T1'];
160 groupStats = [groupStats 0];
161 end
162 if( groupFind( groupNames, 'T2' ) == 0 )
163 groupNames = [groupNames; 'T2'];
164 groupStats = [groupStats 0];
165 end
166 if( groupFind( groupNames, 'T3' ) == 0 )
167 groupNames = [groupNames; 'T3'];
168 groupStats = [groupStats 0];
169 end
170
171 end
172
173
174 % let the group with the maximum success (either 1, 2 or 3) be the
175 % cluster for that gender
176 if( strfind( maxGroup, 'M' ))
177 % male samples were detected most reliably
178 confusionMatrix(1,1) = maxValue;
179 if( strfind( maxGroup, '1' ))
180 % group 1 is the male group
181 % find the female group (F2 or F3, can't be F1)
182 idx1 = groupFind( groupNames, 'F2' );
183 idx2 = groupFind( groupNames, 'F3' );
184 if( groupStats( idx1 ) > groupStats( idx2 ) )
185 % group 1 is the male group
186 % female is group 2 and trans group 3
187 % find the number of male samples incorrectly identified as female
188 idx = groupFind( groupNames, 'M2' );
189 confusionMatrix(1,2) = groupStats( idx );
190 % find the number of male samples incorrectly identified as trans
191 idx = groupFind( groupNames, 'M3' );
192 confusionMatrix(1,3) = groupStats( idx );
193
194 % female correctly identified as female
195 idx = groupFind( groupNames, 'F2' );
196 confusionMatrix(2,2) = groupStats( idx );
197 % female incorrectly identified as male
198 idx = groupFind( groupNames, 'F1' );
199 confusionMatrix(2,1) = groupStats( idx );
200 % female incorrectly identified as trans
201 idx = groupFind( groupNames, 'F3' );
202 confusionMatrix(2,3) = groupStats( idx );
203
204 % trans correctly identified as trans
205 idx = groupFind( groupNames, 'T3' );
206 confusionMatrix(3,3) = groupStats( idx );
207 % trans incorrectly identified as male
208 idx = groupFind( groupNames, 'T1' );
209 confusionMatrix(3,1) = groupStats( idx );
210 % trans incorrectly identified as female
211 idx = groupFind( groupNames, 'T3' );
212 confusionMatrix(3,2) = groupStats( idx );
213
214 else
215 % female is group 3 and trans is group 2
216
217 % find the number of male samples incorrectly identified as female
218 idx = groupFind( groupNames, 'M3' );
219 confusionMatrix(1,2) = groupStats( idx );
220 % find the number of male samples incorrectly identified as trans
221 idx = groupFind( groupNames, 'M2' );
222 confusionMatrix(1,3) = groupStats( idx );
223
224 % female correctly identified as female
225 idx = groupFind( groupNames, 'F3' );
226 confusionMatrix(2,2) = groupStats( idx );
227 % female incorrectly identified as male
228 idx = groupFind( groupNames, 'F1' );
229 confusionMatrix(2,1) = groupStats( idx );
230 % female incorrectly identified as trans
231 idx = groupFind( groupNames, 'F2' );
232 confusionMatrix(2,3) = groupStats( idx );
233
234 % trans correctly identified as trans
235 idx = groupFind( groupNames, 'T2' );
236 confusionMatrix(3,3) = groupStats( idx );
237 % trans incorrectly identified as male
238 idx = groupFind( groupNames, 'T1' );
239 confusionMatrix(3,1) = groupStats( idx );
240 % trans incorrectly identified as female
241 idx = groupFind( groupNames, 'T3' );
242 confusionMatrix(3,2) = groupStats( idx );
243
244 end
245
246
247 elseif( strfind( maxGroup, '2' ))
248 % group 2 is the male group
249
250 % find the female group (F1 or F3, can't be F2)
251 idx1 = groupFind( groupNames, 'F1' );
252 idx2 = groupFind( groupNames, 'F3' );
253 if( groupStats( idx1 ) > groupStats( idx2 ) )
254 % female is group 1 and trans group 3
255 % find the number of male samples incorrectly identified as female
256 idx = groupFind( groupNames, 'M1' );
257 confusionMatrix(1,2) = groupStats( idx );
258 % find the number of male samples incorrectly identified as trans
259 idx = groupFind( groupNames, 'M3' );
260 confusionMatrix(1,3) = groupStats( idx );
261
262 % female correctly identified as female
263 idx = groupFind( groupNames, 'F1' );
264 confusionMatrix(2,2) = groupStats( idx );
265 % female incorrectly identified as male
266 idx = groupFind( groupNames, 'F2' );
267 confusionMatrix(2,1) = groupStats( idx );
268 % female incorrectly identified as trans
269 idx = groupFind( groupNames, 'F3' );
270 confusionMatrix(2,3) = groupStats( idx );
271
272 % trans correctly identified as trans
273 idx = groupFind( groupNames, 'T3' );
274 confusionMatrix(3,3) = groupStats( idx );
275 % trans incorrectly identified as male
276 idx = groupFind( groupNames, 'T2' );
277 confusionMatrix(3,1) = groupStats( idx );
278 % trans incorrectly identified as female
279 idx = groupFind( groupNames, 'T1' );
280 confusionMatrix(3,2) = groupStats( idx );
281
282 else
283 % female is group 3 and trans is group 1
284
285 % find the number of male samples incorrectly identified as female
286 idx = groupFind( groupNames, 'M3' );
287 confusionMatrix(1,2) = groupStats( idx );
288 % find the number of male samples incorrectly identified as trans
289 idx = groupFind( groupNames, 'M1' );
290 confusionMatrix(1,3) = groupStats( idx );
291
292 % female correctly identified as female
293 idx = groupFind( groupNames, 'F3' );
294 confusionMatrix(2,2) = groupStats( idx );
295 % female incorrectly identified as male
296 idx = groupFind( groupNames, 'F2' );
297 confusionMatrix(2,1) = groupStats( idx );
298 % female incorrectly identified as trans
299 idx = groupFind( groupNames, 'F1' );
300 confusionMatrix(2,3) = groupStats( idx );
301
302 % trans correctly identified as trans
303 idx = groupFind( groupNames, 'T1' );
304 confusionMatrix(3,3) = groupStats( idx );
305 % trans incorrectly identified as male
306 idx = groupFind( groupNames, 'F2' );
307 confusionMatrix(3,1) = groupStats( idx );
308 % trans incorrectly identified as female
309 idx = groupFind( groupNames, 'F3' );
310 confusionMatrix(3,2) = groupStats( idx );
311
312 end
313
314 else
315 % group 3 is the male group
316
317 % find the female group (F1 or F2, can't be F3)
318 idx1 = groupFind( groupNames, 'F1' );
319 idx2 = groupFind( groupNames, 'F2' );
320 if( groupStats( idx1 ) > groupStats( idx2 ) )
321 % female is group 1 and trans group 2
322 % find the number of male samples incorrectly identified as female
323 idx = groupFind( groupNames, 'M1' );
324 confusionMatrix(1,2) = groupStats( idx );
325 % find the number of male samples incorrectly identified as trans
326 idx = groupFind( groupNames, 'M2' );
327 confusionMatrix(1,3) = groupStats( idx );
328
329 % female correctly identified as female
330 idx = groupFind( groupNames, 'F1' );
331 confusionMatrix(2,2) = groupStats( idx );
332 % female incorrectly identified as male
333 idx = groupFind( groupNames, 'F3' );
334 confusionMatrix(2,1) = groupStats( idx );
335 % female incorrectly identified as trans
336 idx = groupFind( groupNames, 'F2' );
337 confusionMatrix(2,3) = groupStats( idx );
338
339 % trans correctly identified as trans
340 idx = groupFind( groupNames, 'T2' );
341 confusionMatrix(3,3) = groupStats( idx );
342 % trans incorrectly identified as male
343 idx = groupFind( groupNames, 'F3' );
344 confusionMatrix(3,1) = groupStats( idx );
345 % trans incorrectly identified as female
346 idx = groupFind( groupNames, 'F1' );
347 confusionMatrix(3,2) = groupStats( idx );
348
349 else
350 % female is group 2 and trans is group 1
351
352 % find the number of male samples incorrectly identified as female
353 idx = groupFind( groupNames, 'M2' );
354 confusionMatrix(1,2) = groupStats( idx );
355 % find the number of male samples incorrectly identified as trans
356 idx = groupFind( groupNames, 'M1' );
357 confusionMatrix(1,3) = groupStats( idx );
358
359 % female correctly identified as female
360 idx = groupFind( groupNames, 'F2' );
361 confusionMatrix(2,2) = groupStats( idx );
362 % female incorrectly identified as male
363 idx = groupFind( groupNames, 'F3' );
364 confusionMatrix(2,1) = groupStats( idx );
365 % female incorrectly identified as trans
366 idx = groupFind( groupNames, 'F1' );
367 confusionMatrix(2,3) = groupStats( idx );
368
369 % trans correctly identified as trans
370 idx = groupFind( groupNames, 'T1' );
371 confusionMatrix(3,3) = groupStats( idx );
372 % trans incorrectly identified as male
373 idx = groupFind( groupNames, 'F3' );
374 confusionMatrix(3,1) = groupStats( idx );
375 % trans incorrectly identified as female
376 idx = groupFind( groupNames, 'F2' );
377 confusionMatrix(3,2) = groupStats( idx );
378
379 end
380
381 end
382
383 % --------------------------------------------------------------------
384 % male correctly identified as male (1,1) | male incorrectly identified as female (1,2) | male incorrectly identified as trans
385 % female incorrectly identified as male (2,1) | female correctly identified (2,2) | female incorrectly identified as trans
386 % trans incorrectly identified as male (3,1) | trans incorrectly identified as female (3,2) | trans correctly identified (3,3)
387 % --------------------------------------------------------------------
388
389 elseif( strfind( maxGroup, 'F' ))
390 % female samples were detected most reliably
391 confusionMatrix(2,2) = maxValue;
392 if( strfind( maxGroup, '1' ))
393 % group 1 is the female group
394 % find the male group (F2 or F3, can't be F1)
395 idx1 = groupFind( groupNames, 'M2' );
396 idx2 = groupFind( groupNames, 'M3' );
397 if( groupStats( idx1 ) > groupStats( idx2 ) )
398 % male is group 2 and trans group 3
399 % find the number of male samples incorrectly identified as female
400 idx = groupFind( groupNames, 'M1' );
401 confusionMatrix(1,2) = groupStats( idx );
402 % find the number of male samples incorrectly identified as trans
403 idx = groupFind( groupNames, 'M3' );
404 confusionMatrix(1,3) = groupStats( idx );
405 % male correctly identified as male
406 idx = groupFind( groupNames, 'M2' );
407 confusionMatrix(1,1) = groupStats( idx );
408
409 % female incorrectly identified as male
410 idx = groupFind( groupNames, 'F2' );
411 confusionMatrix(2,1) = groupStats( idx );
412 % female incorrectly identified as trans
413 idx = groupFind( groupNames, 'F3' );
414 confusionMatrix(2,3) = groupStats( idx );
415
416 % trans correctly identified as trans
417 idx = groupFind( groupNames, 'T3' );
418 confusionMatrix(3,3) = groupStats( idx );
419 % trans incorrectly identified as male
420 idx = groupFind( groupNames, 'T2' );
421 confusionMatrix(3,1) = groupStats( idx );
422 % trans incorrectly identified as female
423 idx = groupFind( groupNames, 'T1' );
424 confusionMatrix(3,2) = groupStats( idx );
425
426 else
427 % female is group 1
428 % male is group 3 and trans is group 2
429
430 % find the number of male samples incorrectly identified as female
431 idx = groupFind( groupNames, 'M1' );
432 confusionMatrix(1,2) = groupStats( idx );
433 % find the number of male samples incorrectly identified as trans
434 idx = groupFind( groupNames, 'M2' );
435 confusionMatrix(1,3) = groupStats( idx );
436 % male correctly identified as male
437 idx = groupFind( groupNames, 'M3' );
438 confusionMatrix(1,1) = groupStats( idx );
439
440 % female incorrectly identified as male
441 idx = groupFind( groupNames, 'F3' );
442 confusionMatrix(2,1) = groupStats( idx );
443 % female incorrectly identified as trans
444 idx = groupFind( groupNames, 'F2' );
445 confusionMatrix(2,3) = groupStats( idx );
446
447 % trans correctly identified as trans
448 idx = groupFind( groupNames, 'T2' );
449 confusionMatrix(3,3) = groupStats( idx );
450 % trans incorrectly identified as male
451 idx = groupFind( groupNames, 'T3' );
452 confusionMatrix(3,1) = groupStats( idx );
453 % trans incorrectly identified as female
454 idx = groupFind( groupNames, 'T1' );
455 confusionMatrix(3,2) = groupStats( idx );
456
457 end
458
459
460 elseif( strfind( maxGroup, '2' ))
461 % group 2 is the female group
462 % find the male group (M1 or M3, can't be M2)
463 idx1 = groupFind( groupNames, 'M1' );
464 idx2 = groupFind( groupNames, 'M3' );
465 if( groupStats( idx1 ) > groupStats( idx2 ) )
466 % male is group 1 and trans group 3
467 % find the number of male samples incorrectly identified as female
468 idx = groupFind( groupNames, 'M2' );
469 confusionMatrix(1,2) = groupStats( idx );
470 % find the number of male samples incorrectly identified as trans
471 idx = groupFind( groupNames, 'M3' );
472 confusionMatrix(1,3) = groupStats( idx );
473 % male correctly identified as male
474 idx = groupFind( groupNames, 'M1' );
475 confusionMatrix(1,1) = groupStats( idx );
476
477 % female incorrectly identified as male
478 idx = groupFind( groupNames, 'F1' );
479 confusionMatrix(2,1) = groupStats( idx );
480 % female incorrectly identified as trans
481 idx = groupFind( groupNames, 'F3' );
482 confusionMatrix(2,3) = groupStats( idx );
483
484 % trans correctly identified as trans
485 idx = groupFind( groupNames, 'T3' );
486 confusionMatrix(3,3) = groupStats( idx );
487 % trans incorrectly identified as male
488 idx = groupFind( groupNames, 'T1' );
489 confusionMatrix(3,1) = groupStats( idx );
490 % trans incorrectly identified as female
491 idx = groupFind( groupNames, 'T2' );
492 confusionMatrix(3,2) = groupStats( idx );
493
494 else
495 % group 2 is the female group
496 % male is group 3 and trans is group 1
497
498 % find the number of male samples incorrectly identified as female
499 idx = groupFind( groupNames, 'M2' );
500 confusionMatrix(1,2) = groupStats( idx );
501 % find the number of male samples incorrectly identified as trans
502 idx = groupFind( groupNames, 'M1' );
503 confusionMatrix(1,3) = groupStats( idx );
504 % male correctly identified as male
505 idx = groupFind( groupNames, 'M3' );
506 confusionMatrix(1,1) = groupStats( idx );
507
508 % female incorrectly identified as male
509 idx = groupFind( groupNames, 'F3' );
510 confusionMatrix(2,1) = groupStats( idx );
511 % female incorrectly identified as trans
512 idx = groupFind( groupNames, 'F1' );
513 confusionMatrix(2,3) = groupStats( idx );
514
515 % trans correctly identified as trans
516 idx = groupFind( groupNames, 'T1' );
517 confusionMatrix(3,3) = groupStats( idx );
518 % trans incorrectly identified as male
519 idx = groupFind( groupNames, 'T3' );
520 confusionMatrix(3,1) = groupStats( idx );
521 % trans incorrectly identified as female
522 idx = groupFind( groupNames, 'T2' );
523 confusionMatrix(3,2) = groupStats( idx );
524
525 end
526
527 else
528 % group 3 is the female group
529 % find the male group (M1 or M2, can't be M3)
530 idx1 = groupFind( groupNames, 'M1' );
531 idx2 = groupFind( groupNames, 'M2' );
532 if( groupStats( idx1 ) > groupStats( idx2 ) )
533 % male is group 1 and trans group 2
534 % find the number of male samples incorrectly identified as female
535 idx = groupFind( groupNames, 'M3' );
536 confusionMatrix(1,2) = groupStats( idx );
537 % find the number of male samples incorrectly identified as trans
538 idx = groupFind( groupNames, 'M2' );
539 confusionMatrix(1,3) = groupStats( idx );
540 % male correctly identified as male
541 idx = groupFind( groupNames, 'M1' );
542 confusionMatrix(1,1) = groupStats( idx );
543
544 % female incorrectly identified as male
545 idx = groupFind( groupNames, 'F1' );
546 confusionMatrix(2,1) = groupStats( idx );
547 % female incorrectly identified as trans
548 idx = groupFind( groupNames, 'F2' );
549 confusionMatrix(2,3) = groupStats( idx );
550
551 % trans correctly identified as trans
552 idx = groupFind( groupNames, 'T2' );
553 confusionMatrix(3,3) = groupStats( idx );
554 % trans incorrectly identified as male
555 idx = groupFind( groupNames, 'T1' );
556 confusionMatrix(3,1) = groupStats( idx );
557 % trans incorrectly identified as female
558 idx = groupFind( groupNames, 'T3' );
559 confusionMatrix(3,2) = groupStats( idx );
560
561 else
562 % female is group 3
563 % male is group 2 and trans is group 1
564
565 % find the number of male samples incorrectly identified as female
566 idx = groupFind( groupNames, 'M3' );
567 confusionMatrix(1,2) = groupStats( idx );
568 % find the number of male samples incorrectly identified as trans
569 idx = groupFind( groupNames, 'M1' );
570 confusionMatrix(1,3) = groupStats( idx );
571 % male correctly identified as male
572 idx = groupFind( groupNames, 'M2' );
573 confusionMatrix(1,1) = groupStats( idx );
574
575 % female incorrectly identified as male
576 idx = groupFind( groupNames, 'F2' );
577 confusionMatrix(2,1) = groupStats( idx );
578 % female incorrectly identified as trans
579 idx = groupFind( groupNames, 'F1' );
580 confusionMatrix(2,3) = groupStats( idx );
581
582 % trans correctly identified as trans
583 idx = groupFind( groupNames, 'T1' );
584 confusionMatrix(3,3) = groupStats( idx );
585 % trans incorrectly identified as male
586 idx = groupFind( groupNames, 'T2' );
587 confusionMatrix(3,1) = groupStats( idx );
588 % trans incorrectly identified as female
589 idx = groupFind( groupNames, 'T3' );
590 confusionMatrix(3,2) = groupStats( idx );
591
592 end
593
594 end
595 % --------------------------------------------------------------------
596 % male correctly identified as male (1,1) | male incorrectly identified as female (1,2) | male incorrectly identified as trans
597 % female incorrectly identified as male (2,1) | female correctly identified (2,2) | female incorrectly identified as trans
598 % trans incorrectly identified as male (3,1) | trans incorrectly identified as female (3,2) | trans correctly identified (3,3)
599 % --------------------------------------------------------------------
600
601 elseif( strfind( maxGroup, 'T' ))
602 % trans samples were detected most reliably
603 confusionMatrix(3,3) = maxValue;
604 if( strfind( maxGroup, '1' ))
605 % group 1 is the trans group
606 % find the female group (F2 or F3, can't be F1)
607 idx1 = groupFind( groupNames, 'F2' );
608 idx2 = groupFind( groupNames, 'F3' );
609 if( groupStats( idx1 ) > groupStats( idx2 ) )
610 % female is group 2 and male group 3
611 % find the number of male samples incorrectly identified as female
612 idx = groupFind( groupNames, 'M2' );
613 confusionMatrix(1,2) = groupStats( idx );
614 % find the number of male samples incorrectly identified as trans
615 idx = groupFind( groupNames, 'M1' );
616 confusionMatrix(1,3) = groupStats( idx );
617 % male correctly identified as male
618 idx = groupFind( groupNames, 'M3' );
619 confusionMatrix(1,1) = groupStats( idx );
620
621 % female correctly identified as female
622 idx = groupFind( groupNames, 'F2' );
623 confusionMatrix(2,2) = groupStats( idx );
624 % female incorrectly identified as male
625 idx = groupFind( groupNames, 'F3' );
626 confusionMatrix(2,1) = groupStats( idx );
627 % female incorrectly identified as trans
628 idx = groupFind( groupNames, 'F1' );
629 confusionMatrix(1,3) = groupStats( idx );
630
631 % trans incorrectly identified as male
632 idx = groupFind( groupNames, 'T3' );
633 confusionMatrix(3,1) = groupStats( idx );
634 % trans incorrectly identified as female
635 idx = groupFind( groupNames, 'T2' );
636 confusionMatrix(3,2) = groupStats( idx );
637
638 else
639 % female is group 3 and male is group 2
640 % find the number of male samples incorrectly identified as female
641 idx = groupFind( groupNames, 'M3' );
642 confusionMatrix(1,2) = groupStats( idx );
643 % find the number of male samples incorrectly identified as trans
644 idx = groupFind( groupNames, 'M1' );
645 confusionMatrix(1,3) = groupStats( idx );
646 % male correctly identified as male
647 idx = groupFind( groupNames, 'M2' );
648 confusionMatrix(1,1) = groupStats( idx );
649
650 % female correctly identified as female
651 idx = groupFind( groupNames, 'F3' );
652 confusionMatrix(2,2) = groupStats( idx );
653 % female incorrectly identified as male
654 idx = groupFind( groupNames, 'F2' );
655 confusionMatrix(2,1) = groupStats( idx );
656 % female incorrectly identified as trans
657 idx = groupFind( groupNames, 'F1' );
658 confusionMatrix(1,3) = groupStats( idx );
659
660 % trans incorrectly identified as male
661 idx = groupFind( groupNames, 'T2' );
662 confusionMatrix(3,1) = groupStats( idx );
663 % trans incorrectly identified as female
664 idx = groupFind( groupNames, 'T3' );
665 confusionMatrix(3,2) = groupStats( idx );
666 end
667
668 elseif( strfind( maxGroup, '2' ))
669 % group 2 is the trans group
670 % find the female group (F1 or F3, can't be F2)
671 idx1 = groupFind( groupNames, 'F1' );
672 idx2 = groupFind( groupNames, 'F3' );
673 if( groupStats( idx1 ) > groupStats( idx2 ) )
674 % female is group 1 and male group 3
675 % find the number of male samples incorrectly identified as female
676 idx = groupFind( groupNames, 'M1' );
677 confusionMatrix(1,2) = groupStats( idx );
678 % find the number of male samples incorrectly identified as trans
679 idx = groupFind( groupNames, 'M2' );
680 confusionMatrix(1,3) = groupStats( idx );
681 % male correctly identified as male
682 idx = groupFind( groupNames, 'M3' );
683 confusionMatrix(1,1) = groupStats( idx );
684
685 % female correctly identified as female
686 idx = groupFind( groupNames, 'F1' );
687 confusionMatrix(2,2) = groupStats( idx );
688 % female incorrectly identified as male
689 idx = groupFind( groupNames, 'F3' );
690 confusionMatrix(2,1) = groupStats( idx );
691 % female incorrectly identified as trans
692 idx = groupFind( groupNames, 'F2' );
693 confusionMatrix(1,3) = groupStats( idx );
694
695 % trans incorrectly identified as male
696 idx = groupFind( groupNames, 'T3' );
697 confusionMatrix(3,1) = groupStats( idx );
698 % trans incorrectly identified as female
699 idx = groupFind( groupNames, 'T1' );
700 confusionMatrix(3,2) = groupStats( idx );
701
702 else
703 % group 2 is the trans group
704 % female is group 3 and male is group 1
705 % find the number of male samples incorrectly identified as female
706 idx = groupFind( groupNames, 'M3' );
707 confusionMatrix(1,2) = groupStats( idx );
708 % find the number of male samples incorrectly identified as trans
709 idx = groupFind( groupNames, 'M2' );
710 confusionMatrix(1,3) = groupStats( idx );
711 % male correctly identified as male
712 idx = groupFind( groupNames, 'M1' );
713 confusionMatrix(1,1) = groupStats( idx );
714
715 % female correctly identified as female
716 idx = groupFind( groupNames, 'F3' );
717 confusionMatrix(2,2) = groupStats( idx );
718 % female incorrectly identified as male
719 idx = groupFind( groupNames, 'F1' );
720 confusionMatrix(2,1) = groupStats( idx );
721 % female incorrectly identified as trans
722 idx = groupFind( groupNames, 'F2' );
723 confusionMatrix(1,3) = groupStats( idx );
724
725 % trans incorrectly identified as male
726 idx = groupFind( groupNames, 'T1' );
727 confusionMatrix(3,1) = groupStats( idx );
728 % trans incorrectly identified as female
729 idx = groupFind( groupNames, 'T3' );
730 confusionMatrix(3,2) = groupStats( idx );
731
732 end
733
734 else
735 % group 3 is the trans group
736 % find the female group (F1 or F2, can't be F3)
737 idx1 = groupFind( groupNames, 'F1' );
738 idx2 = groupFind( groupNames, 'F2' );
739 if( groupStats( idx1 ) > groupStats( idx2 ) )
740 % female is group 1 and male group 2
741 % find the number of male samples incorrectly identified as female
742 idx = groupFind( groupNames, 'M1' );
743 confusionMatrix(1,2) = groupStats( idx );
744 % find the number of male samples incorrectly identified as trans
745 idx = groupFind( groupNames, 'M3' );
746 confusionMatrix(1,3) = groupStats( idx );
747 % male correctly identified as male
748 idx = groupFind( groupNames, 'M2' );
749 confusionMatrix(1,1) = groupStats( idx );
750
751 % female correctly identified as female
752 idx = groupFind( groupNames, 'F1' );
753 confusionMatrix(2,2) = groupStats( idx );
754 % female incorrectly identified as male
755 idx = groupFind( groupNames, 'F2' );
756 confusionMatrix(2,1) = groupStats( idx );
757 % female incorrectly identified as trans
758 idx = groupFind( groupNames, 'F3' );
759 confusionMatrix(1,3) = groupStats( idx );
760
761 % trans incorrectly identified as male
762 idx = groupFind( groupNames, 'T2' );
763 confusionMatrix(3,1) = groupStats( idx );
764 % trans incorrectly identified as female
765 idx = groupFind( groupNames, 'T1' );
766 confusionMatrix(3,2) = groupStats( idx );
767
768 else
769 % group 3 is the trans group
770 % female is group 2 and male is group 1
771 % find the number of male samples incorrectly identified as female
772 idx = groupFind( groupNames, 'M2' );
773 confusionMatrix(1,2) = groupStats( idx );
774 % find the number of male samples incorrectly identified as trans
775 idx = groupFind( groupNames, 'M3' );
776 confusionMatrix(1,3) = groupStats( idx );
777 % male correctly identified as male
778 idx = groupFind( groupNames, 'M1' );
779 confusionMatrix(1,1) = groupStats( idx );
780
781 % female correctly identified as female
782 idx = groupFind( groupNames, 'F2' );
783 confusionMatrix(2,2) = groupStats( idx );
784 % female incorrectly identified as male
785 idx = groupFind( groupNames, 'F1' );
786 confusionMatrix(2,1) = groupStats( idx );
787 % female incorrectly identified as trans
788 idx = groupFind( groupNames, 'F3' );
789 confusionMatrix(1,3) = groupStats( idx );
790
791 % trans incorrectly identified as male
792 idx = groupFind( groupNames, 'T1' );
793 confusionMatrix(3,1) = groupStats( idx );
794 % trans incorrectly identified as female
795 idx = groupFind( groupNames, 'T2' );
796 confusionMatrix(3,2) = groupStats( idx );
797 end
798
799 end
800 end
801
802 confusionMatrix(4,4) = confusionMatrix(1,1) + confusionMatrix(2,2) + confusionMatrix(3,3);
803 disp(distanceMeasure);
804 % print latex results to the screen
805 str1 = sprintf(' & %2.2f & %2.2f & %2.2f & \\\\', confusionMatrix(1,1), confusionMatrix(1,2), confusionMatrix(1,3) );
806 disp(str1);
807 str1 = sprintf(' & %2.2f & %2.2f & %2.2f & \\\\', confusionMatrix(2,1), confusionMatrix(2,2), confusionMatrix(2,3) );
808 disp(str1);
809 str1 = sprintf(' & & & & %2.2f \\\\',confusionMatrix(4,4) );
810 disp(str1);
811 disp(' ');
812
813 fprintf( masterFileOutputID, '\n %f \t %f \t %f \n %f \t %f \t %f \n %f \t %f \t %f \n %f \t %f \t %f \t %f \n', confusionMatrix(1,1), confusionMatrix(1,2), confusionMatrix(1,3), confusionMatrix(2,1), confusionMatrix(2,2), confusionMatrix(2,3), confusionMatrix(3,1), confusionMatrix(3,2), confusionMatrix(3,3), 0, 0, 0, confusionMatrix(4,4));
814 end
815
816
817
818 end
819
820 function [idx] = groupFind( groupNames, str )
821
822 idx = 0;
823 for( i=1: length( groupNames ) )
824 if( ~isempty(strfind( groupNames(i,:), str(1) )) && ~isempty(strfind( groupNames(i,:), str(2) )))
825 idx = i;
826 end
827 end
828 end