function [hconf,sconf]=rap_to_confusion_hard(namerap,labs,L,nsent) %function [conf,sconf]=rap_to_confusion_hard(namerap,labs,L,nsent) %namerap - name of the rap file. %lab - vector w/ correct labels (its length must be the same as the len of % rap file. %L - size of label set - 29 for Numbers. %nsent(optional) - nb of sentences to stop after - priors will not be correct % %hconf - the 'hard' confusion matrix (based on max) %sconf - the 'soft' confusion matrix (based on all LLs. if (nargin == 3) nsent = inf; end % init matrices. hconf = zeros(L,L); sconf = zeros(L,L); % compute priors priors = zeros(1,L); N = length(labs); for ii=0:(L-1) priors(ii+1) = length(find(labs == ii)); end disp (priors); disp(sum(priors)); % go ahead END_OF_SENTENCE =-1; ff1=fopen(namerap,'r','b'); % big endian files perframe = fread(ff1,1,'int'); sent=0; frame=0; % init empty matrices w/ probas X1=[]; ii = 1; % index to label file while (1) [sentid,success] = fread(ff1,1,'int'); if (success==0) break end % if end of sentence, do not do anything , just print what's happening if (sentid == END_OF_SENTENCE) if (mod(sent,500) == 0) % some logging disp([sent frame ii]); end % make other necessary things at the end of a sentence X1=[]; frame = 0; sent=sent+1; if (sent == nsent) break; end else % ok, read the data x = fread(ff1,[1 perframe],'float'); X1 = [X1; x]; frame = frame +1; %%% process HARD - find the max and increment corresp. entry of hconf mat. [dummy,imax] = max (x); hconf(labs(ii)+1,imax) = hconf(labs(ii)+1,imax) + 1; %%% process SOFT - just add the LL's to the corresponding line in the conf %%% matrix sconf(labs(ii)+1,:) = sconf(labs(ii)+1,:) + x; ii = ii + 1; end end fclose (ff1); % post-process conf - division by priors. for ii=1:L hconf(ii,:) = hconf(ii,:) / priors(ii); sconf(ii,:) = sconf(ii,:) / priors(ii); end