comparison reproduce_AES53rd/rerun_figure3/rbm_fig3.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 function [cr, cr_] = rbm_fig3(preloaded)
2
3 % cr_: training correct
4 % cr : testing correct
5 feature_file = 'rel_music_raw_features+simdata_ISMIR12';
6 vars = whos('-file', feature_file);
7 A = load(feature_file,vars(1).name,vars(2).name,vars(3).name,vars(4).name);
8 raw_features = A.(vars(1).name);
9 indices = A.(vars(2).name);
10 tst_inx = A.(vars(3).name);
11 trn_inx = A.(vars(4).name);
12 %
13 %figure(1); imagesc(raw_features);colorbar;
14
15 % load the RBM, or compute a new one
16 if ischar(preloaded)
17 mod = load(preloaded);
18 else
19 if isstruct(preloaded)
20 mod = preloaded;
21 else
22 % create new RBM
23 mod = new_rbm(preloaded,'grad');
24 end
25 end
26 features = logistic(raw_features*mod.W_max{1} + repmat(mod.hB_max{1},size(raw_features,1),1));
27 %figure(2); imagesc(features);colorbar;
28
29 num_case = size(trn_inx,1);
30 [trnd_12 trnd_13] = subspace_distances(trn_inx,features,indices,1,1);
31 [tstd_12 tstd_13] = subspace_distances(tst_inx,features,indices,1,1);
32 cr_ = 0; % correct rate for training
33 cr = 0; % correct rate for testing
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %% CODE HERE %%
36 %[Ws cr_] = gradient_ascent(trnd_12,trnd_13,0.1,0.1,0.00002); %eNum = 10
37 [Ws cr_] = gradient_ascent(trnd_12,trnd_13,0.05,0.01,0.00002);
38
39 for i = 1:num_case
40 cr = cr + sum((tstd_13{i}-tstd_12{i})*Ws{i}' > 0, 1)/size(tstd_12{i},1);
41 end
42 cr = cr/num_case;
43 %% Check the result
44 fprintf('Gradient RBM Test / Train Result=%f / %f\n',cr*100,cr_*100);
45 %fprintf('Training=%f Testing=%f\n',cr_,cr);
46
47 end