clear all
close all
%% 1:参数设置
maxepoch=10; %In the
Science paper we use maxepoch=
50, but it works just fine.
numhid=
1000; numpen=
500; numpen2=
250; numopen=
30;
%% 2:数据准备
fprintf(1,'Converting Raw files into Matlab format \n');
converter;
fprintf(1,'Pretraining a deep autoencoder. \n');
fprintf(1,'The Science paper used 50 epochs. This uses %3i \n
', maxepoch);
makebatches;
% batchdata,第二个维度上的像素值,是 0-1 之间;
[numcases, numdims, numbatches]=size(batchdata);
% [100*784*600],100*600 ==> 60000,也恰是训练样本的数目,也即batchdata存储的全部是训练样本(不包括 targets);
% numcases:行数(batch_size,块内样本的数目),样本数目,numdims:维度数目,列数,
% numbatches:块的数目
%% 3:逐层训练
% 第一层: numdims ⇒ numhid(784 ⇒ 1000)
fprintf(1,'Pretraining Layer 1 with
RBM: %d-%d \n
',numdims,numhid);
restart=1;
rbm;
hidrecbiases=hidbiases;
save mnistvh vishid hidrecbiases visbiases;
% 第二层:numhid ⇒ numen (1000 ==> 500)
fprintf(1,'\nPretraining
Layer 2 with
RBM: %d-%d \n
',numhid,numpen);
batchdata = batchposhidprobs; % 第二层的输入
numhid=numpen;
restart=1;
rbm;
hidpen=vishid; penrecbiases=hidbiases; hidgenbiases=visbiases;
save mnisthp hidpen penrecbiases hidgenbiases;
% 第三层:numen ⇒ numen(500 ⇒ 250)
fprintf(1,'\nPretraining
Layer 3 with
RBM: %d-%d \n
',numpen,numpen2);
batchdata=batchposhidprobs;
numhid=numpen2;
restart=1;
rbm;
hidpen2=vishid; penrecbiases2=hidbiases; hidgenbiases2=visbiases;
save mnisthp2 hidpen2 penrecbiases2 hidgenbiases2;
% 第四层:numen2 ⇒ numopen(250 ==> 30)
fprintf(1,'\nPretraining
Layer 4 with
RBM: %d-%d \n
',numpen2,numopen);
batchdata=batchposhidprobs;
numhid=numopen;
restart=1;
rbmhidlinear;
hidtop=vishid; toprecbiases=hidbiases; topgenbiases=visbiases;
save mnistpo hidtop toprecbiases topgenbiases;
backprop;
转载请注明原文地址: https://ju.6miu.com/read-7.html