wolffd@0
|
1 function [count total] = gen_classify(W, visB, hidB,mW,test_file,test_label);
|
wolffd@0
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
3 % RBM for generative classification %
|
wolffd@0
|
4 % conf: training setting %
|
wolffd@0
|
5 % WW = [W visB hidB] %
|
wolffd@0
|
6 % mW: mask of connections %
|
wolffd@0
|
7 % -*-sontran2012-*- %
|
wolffd@0
|
8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
9 %% Loading data & label
|
wolffd@0
|
10 vars = whos('-file', test_file);
|
wolffd@0
|
11 A = load(test_file,vars(1).name);
|
wolffd@0
|
12 data = A.(vars(1).name);
|
wolffd@0
|
13 vars = whos('-file', test_label);
|
wolffd@0
|
14 A = load(test_label,vars(1).name);
|
wolffd@0
|
15 label = A.(vars(1).name);
|
wolffd@0
|
16 assert(size(data,1) == size(label,1),'[KRBM-GEN] Number of data and label mismatch');
|
wolffd@0
|
17 Classes = unique(label)';
|
wolffd@0
|
18 lNum = size(Classes,2);
|
wolffd@0
|
19 %% Loading structure
|
wolffd@0
|
20 [total visNum]= size(data);
|
wolffd@0
|
21 sNum = 500; % fix
|
wolffd@0
|
22 bNum = floor(total/sNum); % divide the testing samples to batches of sNum
|
wolffd@0
|
23 %% Classifying
|
wolffd@0
|
24 count = 0;
|
wolffd@0
|
25 for i=1:bNum
|
wolffd@0
|
26 % Find the position of softmax unit which make lowest free energy
|
wolffd@0
|
27 L = lowest_fenergy(data((i-1)*sNum + 1:i*sNum,:),W, visB, hidB,Classes);
|
wolffd@0
|
28 count = count + sum(L==label((i-1)*sNum + 1:i*sNum));
|
wolffd@0
|
29 end
|
wolffd@0
|
30 L = lowest_fenergy(data(bNum*sNum + 1:total,:),W, visB, hidB,Classes);
|
wolffd@0
|
31 count = count + sum(L==label(bNum*sNum + 1:total));
|
wolffd@0
|
32 fprintf('Correct rate: %f (%d/%d)\n',count/total,count,total);
|
wolffd@0
|
33 clear A vars data lNum sNum bNum out;
|
wolffd@0
|
34 end
|
wolffd@0
|
35
|