Skip to content

Instantly share code, notes, and snippets.

@justinsalamon
Last active February 15, 2016 17:40
Show Gist options
  • Save justinsalamon/6bb4678db587c23a41df to your computer and use it in GitHub Desktop.
Save justinsalamon/6bb4678db587c23a41df to your computer and use it in GitHub Desktop.
Evaluation code used for MIREX multi-f0 Note Tracking subtask. This is the "old" code that has been used on the "MIREX" dataset for this task (I think...?)
function evalNotes_09(resultsDir,algoDir,ID,gtDirname,delim,FH,FL,th_on)
fresults = [resultsDir ID '.subtask2.results.csv'];
fid = fopen(fresults,'w');
fprintf(fid,'Filename,Nref,Nsys,Ncorr,Precision,Recall,Ave. F-measure,Ave. Overlap\n');
d = dir([gtDirname '*.note.mat'] );
Nrefs=zeros(length(d),1);
Nsyses=zeros(length(d),1);
recalls=zeros(length(d),1);
precs=zeros(length(d),1);
fmeasures=zeros(length(d),1);
mean_overlaps=zeros(length(d),1);
for n=1:length(d)
fprintf(fid,'%s,',d(n).name(1:end-4))
% dtname = [dirname d(n).name(1:end-4) '.f0'] ; %%for
dtname = [algoDir d(n).name(1:end-8) 'task2.txt'] ;
[DT, result]= readtext(dtname, delim);
if ~isempty(strfind(ID,'NPA')) % Becuase NPA messed up the format
DT=DT(2:end,:);
end
dt = cell2mat(DT);
% dt(:,1)=dt(:,1)/441;
% dt(:,2)=dt(:,2)/441;
% % tmp = zeros(size(dt)); % For Graham
% % tmp(:,1) = dt(:,2);
% % tmp(:,2) = dt(:,3);
% % tmp(:,3) = dt(:,1);
% % dt = tmp;
% % tmp = [];
gt=[];
gtname = [gtDirname d(n).name ];
disp(sprintf('processing file %d/%d\t%s',n,length(d),gtname));
load(gtname);
% used = zeros(size(NOTES),1);
TP = 0; FP = 0; overlap = [];recall=0;precision=0;fmeasure=0;
orig_notes = NOTES;
fdebugname = ['verify/verify.' d(n).name '.csv'];
fDebug = fopen(fdebugname','w');
fprintf(fDebug,'GTOnset,GToffset,GTF0,DTOnset,DTOffset,DTF0\n');
for i=1:length(dt)
onset_cands_ind = find( (NOTES(:,1) < dt(i,1) + th_on ) & (NOTES(:,1) > max(0,dt(i,1)- th_on) ) );
cands_ind = find((((NOTES(:,1) < dt(i,1) + th_on ) & (NOTES(:,1) > max(0,dt(i,1)- th_on) ) ) & ( ((NOTES(:,3) / dt(i,3)) < FH ) & ((NOTES(:,3) / dt(i,3)) > FL ))) );
if ~isempty(cands_ind)
tmp_offsets = NOTES(cands_ind,2);
tmp_durs = NOTES(cands_ind,2) - NOTES(cands_ind,1);
tmp_dur_th = tmp_durs * .2;
tmp_dur_th = max(.05, tmp_dur_th);
offset_ind = find( ((tmp_offsets + tmp_dur_th) > dt(i,2)) & ((tmp_offsets - tmp_dur_th) < dt(i,2)) );
if isempty(offset_ind)
FP = FP + 1;
else
cands_ind =cands_ind(offset_ind); %offset thresholded
if length(cands_ind)> 1
tmp = dt(i,3) / NOTES(cands_ind,3) ;
cands_ind=cands_ind(find(tmp ==min(tmp)));
end
TP = TP + 1;
overlap(TP) = (min(NOTES(cands_ind,2),dt(i,2)) - max(NOTES(cands_ind,1),dt(i,1)) ) / (max(NOTES(cands_ind,2),dt(i,2)) - min(NOTES(cands_ind,1),dt(i,1)));
NOTES(cands_ind,:) = 0;
% fprintf(fDebug,'%f,%f,%f,%f,%f,%f\n',orig_notes(cands_ind,1),orig_notes(cands_ind,2),orig_notes(cands_ind,3),dt(i,1),dt(i,2),dt(i,3));
end
else
FP = FP + 1;
end
end
Nref = length(find(orig_notes(:,3)));
Nsys = length(find(dt(:,3))) ;
recall = TP / Nref;
precision = TP / Nsys ;
fmeasure = 2*recall*precision/(recall+precision);
mean_overlap = mean(overlap);
fprintf(fid,'%d,%d,%d,%f,%f,%f,%f\n',Nref,Nsys,TP,precision,recall,fmeasure,mean_overlap);
Nrefs(n)=Nref;
Nsyses(n)=Nsys;
recalls(n)=recall;
precs(n)=precision;
fmeasures(n)=fmeasure;
mean_overlaps(n)=mean_overlap;
fclose(fDebug);
end
fprintf(fid,'\n,,,Ave.,%6.2f,%6.2f,%6.2f,%6.2f',mean(precs),mean(recalls),mean(fmeasures),mean(mean_overlaps));
fprintf(fid,'\n,,,Piano Ave.,%6.2f,%6.2f,%6.2f,%6.2f',mean(precs([13 14 15 16 33 34])),mean(recalls([13 14 15 16 33 34])),mean(fmeasures([13 14 15 16 33 34])),mean(mean_overlaps([13 14 15 16 33 34])));
fclose(fid)
%save([resultsDir ID '.scores.mat'],'precs','accuracies','recalls','Etots','Esubss','Emisses','Efas');
save([resultsDir ID '.task2.scores.mat'],'Nrefs','Nsyses','recalls','precs','fmeasures','mean_overlaps');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment