annotate reeval/folds/createFolds.m @ 4:a1f6a08f624c tip

Completed version 0.0.2
author Francisco Rodriguez Algarra <f.rodriguezalgarra@qmul.ac.uk>
date Tue, 03 Nov 2015 21:24:41 +0000
parents b1cd83874633
children
rev   line source
f@2 1 function [train,test] = createFolds(type)
f@2 2
f@2 3 % 'none' to use no filtering
f@2 4 % 'fault' to use filtering
f@2 5
f@2 6 switch type
f@2 7 case 'fault'
f@2 8 testname = 'test_filtered.txt';
f@2 9 trainname = 'train_filtered.txt';
f@2 10 validname = 'valid_filtered.txt';
f@2 11 case 'none'
f@2 12 testname = 'test_stratified.txt';
f@2 13 trainname = 'train_stratified.txt';
f@2 14 validname = 'valid_stratified.txt';
f@2 15 end
f@2 16
f@2 17 genrelabels = {'blues','classical','country','disco','hiphop','jazz','metal','pop','reggae','rock'};
f@2 18
f@2 19 % read in test partition
f@2 20 fid = fopen(testname);
f@2 21 C = textscan(fid,'%s');
f@2 22 testdata = zeros(length(C{:}),1);
f@2 23 for cc=1:length(C{:})
f@2 24 genremult = (find(strncmp(C{1}(cc),genrelabels,3))-1)*100;
f@2 25 exnum = str2num(C{1}{cc}(end-5:end-4));
f@2 26 testdata(cc) = genremult+exnum+1;
f@2 27 end
f@2 28 fclose(fid);
f@2 29
f@2 30 % read in valid partition
f@2 31 fid = fopen(validname);
f@2 32 C = textscan(fid,'%s');
f@2 33 validdata = zeros(length(C{:}),1);
f@2 34 for cc=1:length(C{:})
f@2 35 genremult = (find(strncmp(C{1}(cc),genrelabels,3))-1)*100;
f@2 36 exnum = str2num(C{1}{cc}(end-5:end-4));
f@2 37 validdata(cc) = genremult+exnum+1;
f@2 38 end
f@2 39 fclose(fid);
f@2 40
f@2 41 % read in train partition
f@2 42 fid = fopen(trainname);
f@2 43 C = textscan(fid,'%s');
f@2 44 traindata = zeros(length(C{:}),1);
f@2 45 for cc=1:length(C{:})
f@2 46 genremult = (find(strncmp(C{1}(cc),genrelabels,3))-1)*100;
f@2 47 exnum = str2num(C{1}{cc}(end-5:end-4));
f@2 48 traindata(cc) = genremult+exnum+1;
f@2 49 end
f@2 50 fclose(fid);
f@2 51
f@2 52 testbool = zeros(1000,1); testbool(testdata) = 1;
f@2 53 trainbool = zeros(1000,1); trainbool(validdata) = 1; trainbool(traindata) = 1;
f@2 54
f@2 55 test = logical(testbool);
f@2 56 train = logical(trainbool);