%mnistdeepauto.m
% Version 1.000
%
% Code provided by Ruslan Salakhutdinov and Geoff Hinton
%
% Permission is granted for anyone to copy, use, modify, or distribute this
% program and accompanying programs and documents for any purpose, provided
% this copyright notice is retained and prominently displayed, along with
% a note saying that the original programs are available from our
% web page.
% The programs and documents are distributed without any warranty, express or
% implied. As the programs were written for research purposes only, they have
% not been tested to the degree that would be advisable in any important
% application. All use of these programs is entirely at the user's own risk.
% This program pretrains a deep autoencoder for MNIST dataset
% You can set the maximum number of epochs for pretraining each layer
% and you can set the architecture of the multilayer net.
clear all
close all
maxepoch=1; %In the Science paper we use maxepoch=50, but it works just fine. maxepoch=10
numhid=1000; numpen=500; numpen2=250; numopen=30;
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;
[numcases numdims numbatches]=size(batchdata); %100x784x600
fprintf(1,'Pretraining Layer 1 with RBM: %d-%d \n',numdims,numhid); %784, 1000
restart=1;
rbm;
hidrecbiases=hidbiases; % 1x1000
save mnistvh vishid hidrecbiases visbiases; %784x1000 1x1000 1x784
fprintf(1,'\nPretraining Layer 2 with RBM: %d-%d \n',numhid,numpen); % 1000, 500
batchdata=batchposhidprobs; %100x1000x600
numhid=numpen; % 500
restart=1;
rbm;
hidpen=vishid; penrecbiases=hidbiases; hidgenbiases=visbiases;
save mnisthp hidpen penrecbiases hidgenbiases; % 1000x500 1x500 1x1000
fprintf(1,'\nPretraining Layer 3 with RBM: %d-%d \n',numpen,numpen2); % 500, 250
batchdata=batchposhidprobs; %100x500x600
numhid=numpen2; % 250
restart=1;
rbm;
hidpen2=vishid; penrecbiases2=hidbiases; hidgenbiases2=visbiases;
save mnisthp2 hidpen2 penrecbiases2 hidgenbiases2; % 500x250 1x250 1x500
fprintf(1,'\nPretraining Layer 4 with RBM: %d-%d \n',numpen2,numopen); %250, 30
batchdata=batchposhidprobs; %100x250x600
numhid=numopen; % 30
restart=1;
rbmhidlinear;
hidtop=vishid; toprecbiases=hidbiases; topgenbiases=visbiases;
save mnistpo hidtop toprecbiases topgenbiases; % 250x30 1x30 1x250
backprop;