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