wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: % Experiment code templat % wolffd@0: % Project: sub-euclidean distance for music similarity % wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: %% Load features wolffd@0: feature_file = 'rel_music_raw_features.mat'; wolffd@0: vars = whos('-file', feature_file); wolffd@0: A = load(feature_file,vars(1).name,vars(2).name,vars(3).name,vars(4).name); wolffd@0: raw_features = A.(vars(1).name); wolffd@0: indices = A.(vars(2).name); wolffd@0: tst_inx = A.(vars(3).name); wolffd@0: trn_inx = A.(vars(4).name); wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: % Define directory to save parameters & results wolffd@0: % dir = '/home/funzi/Documents/'; wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: dmr = [0 5 10 20 30 50]; % dimension reduction by PCA wolffd@0: ws = [0 5 10 20 30 50 70]; % window size wolffd@0: % parameters of rbm (if it is used for extraction) wolffd@0: hidNum = [30 50 100 500]; wolffd@0: lr_1 = [0.01 0.05 0.1 0.5]; wolffd@0: lr_2 = [0.05 0.1 0.5 0.7]; wolffd@0: mmt = [0.02 0.05 0.1 0.5]; wolffd@0: cost = [0.00002 0.01 0.1]; wolffd@0: wolffd@0: %% Select parameters (if grid-search is not applied) wolffd@0: di = 1; wolffd@0: wi = 1; wolffd@0: hi = 4; wolffd@0: l1i = 1; wolffd@0: l2i = 1; wolffd@0: mi = 4; wolffd@0: ci = 1; wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: % If grid search is define wolffd@0: % log_file = strcat(dir,'exp_.mat'); wolffd@0: % inx = resume_from_grid(log_file,8); wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: %% Feature extraction wolffd@0: EXT_TYPE = 2; wolffd@0: switch (EXT_TYPE) wolffd@0: case 1 % Using PCA wolffd@0: assert(~exist('OCTAVE_VERSION'),'This script cannot run in octave'); wolffd@0: coeff = princomp(raw_features); wolffd@0: coeff = coeff(:,1:end-dmr(di)); % Change value of dmr(di) to reduce the dimensionality wolffd@0: features = raw_features*coeff; wolffd@0: % normalizing wolffd@0: mm = minmax(features')'; wolffd@0: inn= (find(mm(1,:)~=mm(2,:))); wolffd@0: mm = mm(:,inn); wolffd@0: features = features(:,inn); wolffd@0: features = (features-repmat(mm(1,:),size(features,1),1))./(repmat(mm(2,:),size(features,1),1)-repmat(mm(1,:),size(features,1),1)); wolffd@0: wolffd@0: % describe config wolffd@0: s_conf = xml_format(dmr(di)); wolffd@0: case 2 % Using rbm wolffd@0: conf.hidNum = hidNum(hi); wolffd@0: conf.eNum = 100; wolffd@0: conf.sNum = size(raw_features,1); wolffd@0: conf.bNum = 1; wolffd@0: conf.gNum = 1; wolffd@0: conf.params = [lr_1(l1i) lr_2(l2i) mmt(mi) cost(ci)]; wolffd@0: conf.N = 50; wolffd@0: conf.MAX_INC = 10; wolffd@0: W1 = zeros(0,0); wolffd@0: [W1 vB1 hB1] = training_rbm_(conf,W1,raw_features); wolffd@0: features = logistic(raw_features*W1 + repmat(hB1,conf.sNum,1)); wolffd@0: wolffd@0: % describe config wolffd@0: s_conf = xml_format(conf); wolffd@0: end wolffd@0: wolffd@0: correct = 0; % correct rate wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: %% CODE HERE %% wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: nfvec = features'; wolffd@0: feature_file = 'son_out_files.mat'; wolffd@0: save(feature_file,'nfvec'); wolffd@0: wolffd@0: wolffd@0: % the calling of daniels script wolffd@0: ftype = 'MTTMixedFeatureSon'; wolffd@0: global sonfeatbase; wolffd@0: sonfeatbase = []; wolffd@0: wolffd@0: global db_MTTMixedFeatureSon wolffd@0: db_MTTMixedFeatureSon.reset wolffd@0: wolffd@0: global globalvars; wolffd@0: globalvars.debug = 2 wolffd@0: wolffd@0: fparams_all.son_conf = {s_conf}; wolffd@0: fparams_all.son_filename = {feature_file}; wolffd@0: wolffd@0: % --- wolffd@0: % vary parameters for svmlight wolffd@0: % --- wolffd@0: wolffd@0: trainparams_all = struct(... wolffd@0: 'C', [0.05 0.1 3 10 100], ... %you just want to try this parameter approx (0.01..........1000) (3-100 is nice for daniel) wolffd@0: ... wolffd@0: 'weighted', [0], ... wolffd@0: 'dataset',{{'comp_partBinData_cupaper_01'}}, ... wolffd@0: 'inctrain', 0, ... wolffd@0: 'deltafun', {{'conv_subspace_delta'}}, ... wolffd@0: 'deltafun_params', {{{[0],[1]},{[5],[1]},{[20],[1]},{[40],[1]}}} ... % normalisation improves results wolffd@0: ); wolffd@0: wolffd@0: % set training function wolffd@0: trainfun = @svmlight_wrapper; wolffd@0: wolffd@0: wolffd@0: % create test dirxectory wolffd@0: akt_dir = migrate_to_test_dir(); wolffd@0: wolffd@0: % call eval wolffd@0: result = test_generic_features_parameters_crossval... wolffd@0: (fparams_all, trainparams_all, trainfun, ftype); wolffd@0: wolffd@0: % correct = result.mean_ok_test(1,1); wolffd@0: % fprintf('Correct = %f\n',correct); wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: % Using the logging function to save paramters wolffd@0: % and the result for plotting or in grid search wolffd@0: % logging(log_file,[i1 i2 i3 i4 i5 correct]); wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: wolffd@0: