-
Notifications
You must be signed in to change notification settings - Fork 1
/
computeRBM4_v2.m
executable file
·74 lines (58 loc) · 2.64 KB
/
computeRBM4_v2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
% Version 1.000
% initmaxepoch
% This program pretrains the final layer of a deep autoencoder for MNIST dataset
% given the pre-trained lower-layer weights
% load the batchdata first if you have the batchdata generated, otherwise, call:
% makesinglebatch_v2 (for a single batch)
% or
% makebatches_MNIST (for mini batches)
load batchdata_MNIST;
%load USPS_digit_yzn;
NUMOPEN = 1
initmaxepoch = 50; numhid=500; numpen=500; numpen2=2000; numopen=30;
NUMHID = numhid;
load(['mnistvh' '_' int2str(NUMHID) '_' int2str(numpen) '_' int2str(numpen2) '_' int2str(numopen) 'ep' '_' int2str(initmaxepoch)])
load(['mnisthp' '_' int2str(NUMHID) '_' int2str(numpen) '_' int2str(numpen2) '_' int2str(numopen) 'ep' '_' int2str(initmaxepoch)])
load(['mnisthp2' '_' int2str(NUMHID) '_' int2str(numpen) '_' int2str(numpen2) '_' int2str(numopen) 'ep' '_' int2str(initmaxepoch)])
%batchdata = AllxTr;
[numcases numdims numbatches]=size(batchdata);
numopen = NUMOPEN;
% layer 1
hidbiases=hidrecbiases;
for batch=1:numbatches
data = batchdata(:,:,batch); % Calculating probability of hidden transition
poshidprobs = 1./(1 + exp(-data*vishid - repmat(hidbiases,numcases,1))); % Does all cases at once, store in rows
clear batchposhidprobs;
batchposhidprobs(:,:,batch)=poshidprobs;
end
clear data;
% layer 2
batchdata=batchposhidprobs;
clear batchposhidprobs;
vishid=hidpen; hidbiases=penrecbiases; visbiases=hidgenbiases;
for batch=1:numbatches
data = batchdata(:,:,batch); % Calculating probability of hidden transition
poshidprobs = 1./(1 + exp(-data*vishid - repmat(hidbiases,numcases,1))); % Does all cases at once, store in rows
batchposhidprobs(:,:,batch)=poshidprobs;
end
clear data;
% for layer 3
batchdata=batchposhidprobs;
clear batchposhidprobs;
vishid=hidpen2; hidbiases=penrecbiases2; visbiases=hidgenbiases2;
for batch=1:numbatches
data = batchdata(:,:,batch); % Calculating probability of hidden transition
poshidprobs = 1./(1 + exp(-data*vishid - repmat(hidbiases,numcases,1))); % Does all cases at once, store in rows
batchposhidprobs(:,:,batch)=poshidprobs;
end
clear data;
fprintf(1,'\nPretraining Layer 4 with RBM: %d-%d \n',numpen2,numopen);
batchdata=batchposhidprobs;
numhid=numopen;
restart=1;
maxepoch = initmaxepoch;
rbmhidlinear;
hidtop=vishid; toprecbiases=hidbiases; topgenbiases=visbiases;
save(['mnistpo' '_' int2str(NUMHID) '_' int2str(numpen) '_' int2str(numpen2) '_' int2str(numopen) 'ep' '_' int2str(initmaxepoch)], ...
'hidtop', 'toprecbiases', 'topgenbiases');
%backprop_DNetkNN;