annotate core/magnatagatune/tests_evals/rbm_subspace/Exp_SVMLight.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 2 % Experiment code templat %
wolffd@0 3 % Project: sub-euclidean distance for music similarity %
wolffd@0 4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 5 %% Load features
wolffd@0 6 feature_file = 'rel_music_raw_features.mat';
wolffd@0 7 vars = whos('-file', feature_file);
wolffd@0 8 A = load(feature_file,vars(1).name,vars(2).name,vars(3).name,vars(4).name);
wolffd@0 9 raw_features = A.(vars(1).name);
wolffd@0 10 indices = A.(vars(2).name);
wolffd@0 11 tst_inx = A.(vars(3).name);
wolffd@0 12 trn_inx = A.(vars(4).name);
wolffd@0 13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 14 % Define directory to save parameters & results
wolffd@0 15 % dir = '/home/funzi/Documents/';
wolffd@0 16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 17 dmr = [0 5 10 20 30 50]; % dimension reduction by PCA
wolffd@0 18 ws = [0 5 10 20 30 50 70]; % window size
wolffd@0 19 % parameters of rbm (if it is used for extraction)
wolffd@0 20 hidNum = [30 50 100 500];
wolffd@0 21 lr_1 = [0.01 0.05 0.1 0.5];
wolffd@0 22 lr_2 = [0.05 0.1 0.5 0.7];
wolffd@0 23 mmt = [0.02 0.05 0.1 0.5];
wolffd@0 24 cost = [0.00002 0.01 0.1];
wolffd@0 25
wolffd@0 26 %% Select parameters (if grid-search is not applied)
wolffd@0 27 di = 1;
wolffd@0 28 wi = 1;
wolffd@0 29 hi = 4;
wolffd@0 30 l1i = 1;
wolffd@0 31 l2i = 1;
wolffd@0 32 mi = 4;
wolffd@0 33 ci = 1;
wolffd@0 34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 35 % If grid search is define
wolffd@0 36 % log_file = strcat(dir,'exp_.mat');
wolffd@0 37 % inx = resume_from_grid(log_file,8);
wolffd@0 38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 39 %% Feature extraction
wolffd@0 40 EXT_TYPE = 2;
wolffd@0 41 switch (EXT_TYPE)
wolffd@0 42 case 1 % Using PCA
wolffd@0 43 assert(~exist('OCTAVE_VERSION'),'This script cannot run in octave');
wolffd@0 44 coeff = princomp(raw_features);
wolffd@0 45 coeff = coeff(:,1:end-dmr(di)); % Change value of dmr(di) to reduce the dimensionality
wolffd@0 46 features = raw_features*coeff;
wolffd@0 47 % normalizing
wolffd@0 48 mm = minmax(features')';
wolffd@0 49 inn= (find(mm(1,:)~=mm(2,:)));
wolffd@0 50 mm = mm(:,inn);
wolffd@0 51 features = features(:,inn);
wolffd@0 52 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 53
wolffd@0 54 % describe config
wolffd@0 55 s_conf = xml_format(dmr(di));
wolffd@0 56 case 2 % Using rbm
wolffd@0 57 conf.hidNum = hidNum(hi);
wolffd@0 58 conf.eNum = 100;
wolffd@0 59 conf.sNum = size(raw_features,1);
wolffd@0 60 conf.bNum = 1;
wolffd@0 61 conf.gNum = 1;
wolffd@0 62 conf.params = [lr_1(l1i) lr_2(l2i) mmt(mi) cost(ci)];
wolffd@0 63 conf.N = 50;
wolffd@0 64 conf.MAX_INC = 10;
wolffd@0 65 W1 = zeros(0,0);
wolffd@0 66 [W1 vB1 hB1] = training_rbm_(conf,W1,raw_features);
wolffd@0 67 features = logistic(raw_features*W1 + repmat(hB1,conf.sNum,1));
wolffd@0 68
wolffd@0 69 % describe config
wolffd@0 70 s_conf = xml_format(conf);
wolffd@0 71 end
wolffd@0 72
wolffd@0 73 correct = 0; % correct rate
wolffd@0 74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 75 %% CODE HERE %%
wolffd@0 76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 77 nfvec = features';
wolffd@0 78 feature_file = 'son_out_files.mat';
wolffd@0 79 save(feature_file,'nfvec');
wolffd@0 80
wolffd@0 81
wolffd@0 82 % the calling of daniels script
wolffd@0 83 ftype = 'MTTMixedFeatureSon';
wolffd@0 84 global sonfeatbase;
wolffd@0 85 sonfeatbase = [];
wolffd@0 86
wolffd@0 87 global db_MTTMixedFeatureSon
wolffd@0 88 db_MTTMixedFeatureSon.reset
wolffd@0 89
wolffd@0 90 global globalvars;
wolffd@0 91 globalvars.debug = 2
wolffd@0 92
wolffd@0 93 fparams_all.son_conf = {s_conf};
wolffd@0 94 fparams_all.son_filename = {feature_file};
wolffd@0 95
wolffd@0 96 % ---
wolffd@0 97 % vary parameters for svmlight
wolffd@0 98 % ---
wolffd@0 99
wolffd@0 100 trainparams_all = struct(...
wolffd@0 101 '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 102 ...
wolffd@0 103 'weighted', [0], ...
wolffd@0 104 'dataset',{{'comp_partBinData_cupaper_01'}}, ...
wolffd@0 105 'inctrain', 0, ...
wolffd@0 106 'deltafun', {{'conv_subspace_delta'}}, ...
wolffd@0 107 'deltafun_params', {{{[0],[1]},{[5],[1]},{[20],[1]},{[40],[1]}}} ... % normalisation improves results
wolffd@0 108 );
wolffd@0 109
wolffd@0 110 % set training function
wolffd@0 111 trainfun = @svmlight_wrapper;
wolffd@0 112
wolffd@0 113
wolffd@0 114 % create test dirxectory
wolffd@0 115 akt_dir = migrate_to_test_dir();
wolffd@0 116
wolffd@0 117 % call eval
wolffd@0 118 result = test_generic_features_parameters_crossval...
wolffd@0 119 (fparams_all, trainparams_all, trainfun, ftype);
wolffd@0 120
wolffd@0 121 % correct = result.mean_ok_test(1,1);
wolffd@0 122 % fprintf('Correct = %f\n',correct);
wolffd@0 123
wolffd@0 124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 125 % Using the logging function to save paramters
wolffd@0 126 % and the result for plotting or in grid search
wolffd@0 127 % logging(log_file,[i1 i2 i3 i4 i5 correct]);
wolffd@0 128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 129
wolffd@0 130
wolffd@0 131