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