SlideShare uma empresa Scribd logo
1 de 40
An Analysis of RBM.m of Hinton’s
mnistdeepauto example
by Ali Riza SARAL
References:
Hinton’s «Lecture 12C _ Restricted Boltzmann Machines»
Hugo Larochelle’s «Neural networks [5.2] _ Restricted Boltzmann machine – inference»
Hugo Larochelle’s «Neural networks [5.4] _ Restricted Boltzmann machine - contrastive divergence»
Mnistdeepauto mechanism for calling
RBM
• RBM is called 4 times from mnistdeepauto.m
• Mnistdeepauto.m passes batchdata and numhid
to rbm.
• It controls rbm to run for 1000, 500, 250, 30
numhid 4 layers.
• Each of these layers return vishid hidrecbiases
visbiases (in their own names)
• Mnistdeepauto saves these for backprop to use
• save mnistvh vishid hidrecbiases visbiases;
How RBM works
• RBM.m is a single epoch loop. It repeats the
same processing with its updated data to
approach a better solution.
• for epoch = epoch:maxepoch, % 1 : 10
• ...
• fprintf(1, 'epoch %4i error %6.1f n', epoch,
errsum);
• end;
Data update of RBM epoch loops
• %%%%%%%%% UPDATE WEIGHTS AND BIASES
• vishidinc = momentum*vishidinc + ... % 784x1000
• epsilonw*( (posprods-negprods)/numcases - weightcost*vishid);
% 784x 1000
•
• visbiasinc = momentum*visbiasinc + (epsilonvb/numcases)*(posvisact-
negvisact); % 1x784 + 1x784 - 1x784
• hidbiasinc = momentum*hidbiasinc + (epsilonhb/numcases)*(poshidact-
neghidact); % 1x1000 + 1x1000 - 1x1000
• vishid = vishid + vishidinc; % 784x1000 + 784x1000
• visbiases = visbiases + visbiasinc; % 1x784 + x784
• hidbiases = hidbiases + hidbiasinc; % 1x1000 + 1x1000
• %%%%%%%%%%%%%%%% END OF UPDATES
Data update at the bottom of epoche
loop
• Vishid, visbiases, hidbiases are calculated at
the bottom of the RBM epoch loop and they
are going to be used at the next loop.
• The new values of Vishid, visbiases, hidbiases
are calculated by adding vishidinc, visbiasinc,
hidbiasinc.
• RBM epoch loop basically calculates vishidinc,
visbiasinc, hidbiasinc.
RBM constants initialization
• vishidinc, visbiasinc, hidbiasinc use some
constants.
• epsilonw = 0.1; % Learning rate for weights
• epsilonvb = 0.1; % Learning rate for biases of
visible units
• epsilonhb = 0.1; % Learning rate for biases of
hidden units
• weightcost = 0.0002;
• initialmomentum = 0.5;
• finalmomentum = 0.9;
RBM variables’ definition and init
mechanism
• İnit mechanism depends on the restart variable.
• Mnistdeepauto has:
• restart=1;
• rbm;
• ...
• Rbm.m has :
• if restart ==1,
• restart=0;
• epoch=1;% Initializing symmetric weights and biases.
• ...
• End
• This mechanism disables the initialization at the further epoches
than 0
RBM variables definition and init
• % Initializing symmetric weights and biases.
• vishid = 0.1*randn(numdims, numhid); %784x1000
• hidbiases = zeros(1,numhid); % 1x1000
• visbiases = zeros(1,numdims); % 1x784
•
• poshidprobs = zeros(numcases,numhid); %100x1000
• neghidprobs = zeros(numcases,numhid); %100x1000
• posprods = zeros(numdims,numhid); %784x1000
• negprods = zeros(numdims,numhid); %784x1000
• vishidinc = zeros(numdims,numhid); %784x1000
• hidbiasinc = zeros(1,numhid); %1x1000
• visbiasinc = zeros(1,numdims); %1x784
• batchposhidprobs=zeros(numcases,numhid,numbatches); %100x1000x600
• The values of these variables change according to the current epoch.
Batches loop
• Each repetition of epoches loop is executed for all
the batches (600 of them)
• for epoch = epoch:maxepoch, % 1 : 10
• fprintf(1,'epoch %dn',epoch);
• errsum=0;
• for batch = 1:numbatches,
• fprintf(1,'epoch %d batch %dn',epoch,batch);
Accumulating the errsum per epoch
• for epoch = epoch:maxepoch, % 1 : 10
• errsum=0;
• %Errsum is initiated before batch processing begins in each epoch
• ...
• %After the END OF NEGATIVE PHASE
• err= sum(sum( (data-negdata).^2 )); %1x1
• errsum = err + errsum;
•
• %Error is calculated based on the difference of data and negdata
and accumulated from all the batches using the errsum variable
based on the current epoch.
• The data/negdata concept comes from contrastive divergence.
Varying momentum
• Before passing to the next batch it resets the
momentum variable that effects the rate of changes
• if epoch>5,
• momentum=finalmomentum;
• else momentum=initialmomentum;
• end;
• A varying momentum maybe necessary to catch a
• converging point quickly and then approach it slowly or
otherwise.
The pith of Rbm.m
• The pith of rbm.m is composed of two sections (and the middle of
them):
• %%%%%%%%% START POSITIVE PHASE
• data = batchdata(:,:,batch); % 100x784
• ...
• %%%%%%%%% END OF POSITIVE PHASE
• poshidstates = poshidprobs > rand(numcases,numhid); %100x1000 >
100x1000 = 100 x 1000
• %%%%%%%%% START NEGATIVE PHASE
• negdata = ...
• %%%%%%%%% END OF NEGATIVE PHASE
Positive phase depends on the input x(t) while negative
phase depends on the system - Hugo Larochelle
Gibbs sampling and calculation of x(t) x(1) ...
X(k) corresponds to the epoches loop
Epoches and Gibbs repetition
• for epoch = epoch:maxepoch, % 1 : 10
• errsum=0;
• for batch = 1:numbatches,
• %%%%%%%%% START POSITIVE PHASE
• data = batchdata(:,:,batch); % 100x784
• ...
• %%%%%%%%% END OF POSITIVE PHASE
• poshidstates = poshidprobs > rand(numcases,numhid); %100x1000 > 100x1000 = 100 x 1000
• %%%%%%%%% START NEGATIVE PHASE
• ...
• %%%%%%%%% END OF NEGATIVE PHASE
• err= sum(sum( (data-negdata).^2 )); %1x1
• errsum = err + errsum;
• if epoch>5,
• momentum=finalmomentum;
• else
• momentum=initialmomentum;
• end;
• %%%%%%%%% UPDATE WEIGHTS AND BIASES
• ...
• %%%%%%%%%%%%%%%% END OF UPDATES
• end %of batch
• fprintf(1, 'epoch %4i error %6.1f n', epoch, errsum);
• end; %of epoch
Positive Phase
• %%%%%%%%% START POSITIVE PHASE
• data = batchdata(:,:,batch); % 100x784
•
• poshidprobs = 1./(1 + exp(-data*vishid -
repmat(hidbiases,numcases,1)));
• %100x784 * 784x1000 - 1x1000repmat->100x1000 = 100x1000
• batchposhidprobs(:,:,batch)=poshidprobs; %100x1000<-batch(600)
• posprods = data' * poshidprobs; %784x100 * 100x1000 = 784x1000
• poshidact = sum(poshidprobs); % 1x1000
• posvisact = sum(data); % 1x784
• %%%%%%%%% END OF POSITIVE PHASE
Calculation of positive hidden
probabilities
• %%%%%%%%% START POSITIVE PHASE
• data = batchdata(:,:,batch); % 100x784
• % This section uses a different batch from batcchdata for each loop value of the variable batch.
• %Batchdata is %100x784x600 and numbatches = 600.
• %for batch = 1:numbatches, loop executes this section 600 times for each epoche.
• poshidprobs = 1./(1 + exp(-data*vishid -
repmat(hidbiases,numcases,1)));
• %100x784 * 784x1000 - 1x1000repmat->100x1000 = 100x1000
• Poshidprobs calculates the possibility of hidden values given the data and vistohid
• Weight vectors. It also adds the hidden biases with repmat.
• batchposhidprobs(:,:,batch)=poshidprobs; %100x1000<-batch(600)
• After calculating the poshidprobs for the current batch it saves these values to the
batchposhidprobs with the batch loops counter named batch.
• ...
• %%%%%%%%% END OF POSITIVE PHASE
Example
• octave:6> h=1:10
• h =
• 1 2 3 4 5 6 7 8 9 10
• octave:7> n=2
• n = 2
• octave:8> repmat(h,n,1)
• ans =
• 1 2 3 4 5 6 7 8 9 10
• 1 2 3 4 5 6 7 8 9 10
The possibility of h given x is p(h|x) and the
possibility of x given h is p(x|h)
Positive phase continued...
• %%%%%%%%% START POSITIVE PHASE
• data = batchdata(:,:,batch); % 100x784
• poshidprobs = 1./(1 + exp(-data*vishid -
repmat(hidbiases,numcases,1)));
• %100x784 * 784x1000 - 1x1000repmat->100x1000 =
100x1000
• batchposhidprobs(:,:,batch)=poshidprobs; %100x1000<-batch(600)
• posprods = data' * poshidprobs; %784x100 * 100x1000 = 784x1000
• poshidact = sum(poshidprobs); % 1x1000
• posvisact = sum(data); % 1x784
• %%%%%%%%% END OF POSITIVE PHASE
Positive Phase Product calculation
• %%%%%%%%% START POSITIVE PHASE
• ...
• posprods = data' * poshidprobs; %784x100 *
100x1000 = 784x1000
• poshidact = sum(poshidprobs); % 1x1000
• posvisact = sum(data); % 1x784
• %%%%%%%%% END OF POSITIVE PHASE
Where does product term comes
from?
The pith of Rbm.m
• The pith of rbm.m is composed of two sections (and the middle of them):
• %%%%%%%%% START POSITIVE PHASE
• data = batchdata(:,:,batch); % 100x784
• ...
• %%%%%%%%% END OF POSITIVE PHASE
• poshidstates = poshidprobs > rand(numcases,numhid);
• %100x1000 > 100x1000 = 100 x 1000
• %%%%%%%%% START NEGATIVE PHASE
• negdata = ...
• %%%%%%%%% END OF NEGATIVE PHASE
• debug> size(batchposhidprobs)
• ans =
• 100 1000 600
• debug> size(poshidprobs)
• ans = 100 1000
• debug> poshidprobs(1:10)
• ans = 0.64384 0.40320 0.43777 0.50833 0.53826 0.67048 0.20901
0.53981 0.41825 0.48169
• debug> poshidstates(1:10)
• ans =
• 1 0 0 1 1 1 0 1 0 0
• octave:15> clear all
• octave:16> a=rand(2,3)
• a =
• 0.77448 0.25583 0.51168
• 0.82385 0.54641 0.86008
• octave:17> r=rand(2,3)
• r =
• 0.55236 0.47071 0.49259
• 0.64676 0.21294 0.63988
• octave:18> a>r
• ans =
• 1 0 1
• 1 1 1
Poshidprobs to poshidstates
conversion
• poshidstates = poshidprobs > rand(numcases,numhid);
• Positive phase hidden probabilities are taken
as input and used to calculate the input of x(1)
• visual values. The possibility that the hidden
values are right is taken into account by
comparing them with a random generated
number group.
Negative Phase
• %%%%%%%%% START NEGATIVE PHASE
• negdata = 1./(1 + exp(-poshidstates*vishid' -
repmat(visbiases,numcases,1)));
• % 100x1000 * 1000x784 - 1x784repmat->100x784 = 100 x 784
• neghidprobs = 1./(1 + exp(-negdata*vishid -
repmat(hidbiases,numcases,1)));
• % 100x784 * 784x1000 - 1x1000repmat->100x1000 = 100x1000
• negprods = negdata'*neghidprobs;
• % 784x100 * 100x1000
• neghidact = sum(neghidprobs); % 1x1000
• negvisact = sum(negdata); % 1x784
• %%%%%%%%% END OF NEGATIVE PHASE
Negative Phase 2
• %%%%%%%%% START NEGATIVE PHASE
• negdata = 1./(1 + exp(-poshidstates*vishid' -
repmat(visbiases,numcases,1)));
• % 100x1000 * 1000x784 - 1x784repmat->100x784 = 100 x 784
• neghidprobs = 1./(1 + exp(-negdata*vishid -
repmat(hidbiases,numcases,1)));
• % 100x784 * 784x1000 - 1x1000repmat->100x1000 = 100x1000
• ...
• %%%%%%%%% END OF NEGATIVE PHASE
The Product Term
• %%%%%%%%% START NEGATIVE PHASE
• ...
• negprods = negdata'*neghidprobs;
• % 784x100 * 100x1000
• neghidact = sum(neghidprobs); % 1x1000
• negvisact = sum(negdata); % 1x784
• %%%%%%%%% END OF NEGATIVE PHASE
Where does product term comes
from?
Data update of RBM epoch loops
• %%%%%%%%% UPDATE WEIGHTS AND BIASES
• vishidinc = momentum*vishidinc + ... % 784x1000
• epsilonw*( (posprods-negprods)/numcases - weightcost*vishid);
% 784x 1000
•
• visbiasinc = momentum*visbiasinc + (epsilonvb/numcases)*(posvisact-
negvisact); % 1x784 + 1x784 - 1x784
• hidbiasinc = momentum*hidbiasinc + (epsilonhb/numcases)*(poshidact-
neghidact); % 1x1000 + 1x1000 - 1x1000
• vishid = vishid + vishidinc; % 784x1000 + 784x1000
• visbiases = visbiases + visbiasinc; % 1x784 + x784
• hidbiases = hidbiases + hidbiasinc; % 1x1000 + 1x1000
• %%%%%%%%%%%%%%%% END OF UPDATES
HINTON Lecture 12C _ Restricted
Boltzmann Machines
HINTON Lecture 12C _ Restricted
Boltzmann Machines

Mais conteúdo relacionado

Semelhante a Mnistauto 2

Repetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesRepetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesJason J Pulikkottil
 
Gradient descent method
Gradient descent methodGradient descent method
Gradient descent methodSanghyuk Chun
 
ant colony optimization.pptx
ant colony optimization.pptxant colony optimization.pptx
ant colony optimization.pptxGrishma Sharma
 
[01] Quantum Error Correction for Beginners
[01] Quantum Error Correction for Beginners [01] Quantum Error Correction for Beginners
[01] Quantum Error Correction for Beginners Shin Nishio
 
EGUE Technikrom Final_8_12_13
EGUE Technikrom Final_8_12_13EGUE Technikrom Final_8_12_13
EGUE Technikrom Final_8_12_13Paul Brodbeck
 
Loops in matlab
Loops in matlabLoops in matlab
Loops in matlabTUOS-Sam
 
Chapter 3 -Built-in Matlab Functions
Chapter 3 -Built-in Matlab FunctionsChapter 3 -Built-in Matlab Functions
Chapter 3 -Built-in Matlab FunctionsSiva Gopal
 
Change Point Analysis
Change Point AnalysisChange Point Analysis
Change Point AnalysisMark Conway
 
Joker 2015 - Валеев Тагир - Что же мы измеряем?
Joker 2015 - Валеев Тагир - Что же мы измеряем?Joker 2015 - Валеев Тагир - Что же мы измеряем?
Joker 2015 - Валеев Тагир - Что же мы измеряем?tvaleev
 
Regression vs Neural Net
Regression vs Neural NetRegression vs Neural Net
Regression vs Neural NetRatul Alahy
 
Robust and Tuneable Family of Gossiping Algorithms
Robust and Tuneable Family of Gossiping AlgorithmsRobust and Tuneable Family of Gossiping Algorithms
Robust and Tuneable Family of Gossiping AlgorithmsVincenzo De Florio
 
arithmaticpipline-170310085040.pptx
arithmaticpipline-170310085040.pptxarithmaticpipline-170310085040.pptx
arithmaticpipline-170310085040.pptxAshokRachapalli1
 
RapidMiner Linear Regression Tutorial ProcessesPPT.pdf
RapidMiner Linear Regression Tutorial ProcessesPPT.pdfRapidMiner Linear Regression Tutorial ProcessesPPT.pdf
RapidMiner Linear Regression Tutorial ProcessesPPT.pdfssuser2cfd2b
 
Firefly exact MCMC for Big Data
Firefly exact MCMC for Big DataFirefly exact MCMC for Big Data
Firefly exact MCMC for Big DataGianvito Siciliano
 

Semelhante a Mnistauto 2 (20)

Repetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesRepetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniques
 
Chapter06.PPT
Chapter06.PPTChapter06.PPT
Chapter06.PPT
 
Gradient descent method
Gradient descent methodGradient descent method
Gradient descent method
 
ant colony optimization.pptx
ant colony optimization.pptxant colony optimization.pptx
ant colony optimization.pptx
 
Mit6 094 iap10_lec03
Mit6 094 iap10_lec03Mit6 094 iap10_lec03
Mit6 094 iap10_lec03
 
L06
L06L06
L06
 
[01] Quantum Error Correction for Beginners
[01] Quantum Error Correction for Beginners [01] Quantum Error Correction for Beginners
[01] Quantum Error Correction for Beginners
 
EGUE Technikrom Final_8_12_13
EGUE Technikrom Final_8_12_13EGUE Technikrom Final_8_12_13
EGUE Technikrom Final_8_12_13
 
Loops in matlab
Loops in matlabLoops in matlab
Loops in matlab
 
Chapter 3 -Built-in Matlab Functions
Chapter 3 -Built-in Matlab FunctionsChapter 3 -Built-in Matlab Functions
Chapter 3 -Built-in Matlab Functions
 
Change Point Analysis
Change Point AnalysisChange Point Analysis
Change Point Analysis
 
Joker 2015 - Валеев Тагир - Что же мы измеряем?
Joker 2015 - Валеев Тагир - Что же мы измеряем?Joker 2015 - Валеев Тагир - Что же мы измеряем?
Joker 2015 - Валеев Тагир - Что же мы измеряем?
 
Regression vs Neural Net
Regression vs Neural NetRegression vs Neural Net
Regression vs Neural Net
 
Robust and Tuneable Family of Gossiping Algorithms
Robust and Tuneable Family of Gossiping AlgorithmsRobust and Tuneable Family of Gossiping Algorithms
Robust and Tuneable Family of Gossiping Algorithms
 
Me314 week 06-07-Time Response
Me314 week 06-07-Time ResponseMe314 week 06-07-Time Response
Me314 week 06-07-Time Response
 
Matlab
MatlabMatlab
Matlab
 
arithmaticpipline-170310085040.pptx
arithmaticpipline-170310085040.pptxarithmaticpipline-170310085040.pptx
arithmaticpipline-170310085040.pptx
 
Approximation Algorithms TSP
Approximation Algorithms   TSPApproximation Algorithms   TSP
Approximation Algorithms TSP
 
RapidMiner Linear Regression Tutorial ProcessesPPT.pdf
RapidMiner Linear Regression Tutorial ProcessesPPT.pdfRapidMiner Linear Regression Tutorial ProcessesPPT.pdf
RapidMiner Linear Regression Tutorial ProcessesPPT.pdf
 
Firefly exact MCMC for Big Data
Firefly exact MCMC for Big DataFirefly exact MCMC for Big Data
Firefly exact MCMC for Big Data
 

Mais de Ali Rıza SARAL

On the Role of Design in Creativity.pptx
On the Role of Design in Creativity.pptxOn the Role of Design in Creativity.pptx
On the Role of Design in Creativity.pptxAli Rıza SARAL
 
Human assisted computer creativity
Human assisted computer creativityHuman assisted computer creativity
Human assisted computer creativityAli Rıza SARAL
 
20160308 ars writing large music works
20160308 ars writing large music works20160308 ars writing large music works
20160308 ars writing large music worksAli Rıza SARAL
 
AR+S The Role Of Abstraction In Human Computer Interaction
AR+S   The Role Of Abstraction In Human Computer InteractionAR+S   The Role Of Abstraction In Human Computer Interaction
AR+S The Role Of Abstraction In Human Computer InteractionAli Rıza SARAL
 

Mais de Ali Rıza SARAL (7)

On the Role of Design in Creativity.pptx
On the Role of Design in Creativity.pptxOn the Role of Design in Creativity.pptx
On the Role of Design in Creativity.pptx
 
Mnistauto 4
Mnistauto 4Mnistauto 4
Mnistauto 4
 
Mnistauto 1
Mnistauto 1Mnistauto 1
Mnistauto 1
 
Human assisted computer creativity
Human assisted computer creativityHuman assisted computer creativity
Human assisted computer creativity
 
20160308 ars writing large music works
20160308 ars writing large music works20160308 ars writing large music works
20160308 ars writing large music works
 
Komut satırı JAVA
Komut satırı JAVAKomut satırı JAVA
Komut satırı JAVA
 
AR+S The Role Of Abstraction In Human Computer Interaction
AR+S   The Role Of Abstraction In Human Computer InteractionAR+S   The Role Of Abstraction In Human Computer Interaction
AR+S The Role Of Abstraction In Human Computer Interaction
 

Último

DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 

Último (20)

DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 

Mnistauto 2

  • 1. An Analysis of RBM.m of Hinton’s mnistdeepauto example by Ali Riza SARAL References: Hinton’s «Lecture 12C _ Restricted Boltzmann Machines» Hugo Larochelle’s «Neural networks [5.2] _ Restricted Boltzmann machine – inference» Hugo Larochelle’s «Neural networks [5.4] _ Restricted Boltzmann machine - contrastive divergence»
  • 2. Mnistdeepauto mechanism for calling RBM • RBM is called 4 times from mnistdeepauto.m • Mnistdeepauto.m passes batchdata and numhid to rbm. • It controls rbm to run for 1000, 500, 250, 30 numhid 4 layers. • Each of these layers return vishid hidrecbiases visbiases (in their own names) • Mnistdeepauto saves these for backprop to use • save mnistvh vishid hidrecbiases visbiases;
  • 3. How RBM works • RBM.m is a single epoch loop. It repeats the same processing with its updated data to approach a better solution. • for epoch = epoch:maxepoch, % 1 : 10 • ... • fprintf(1, 'epoch %4i error %6.1f n', epoch, errsum); • end;
  • 4. Data update of RBM epoch loops • %%%%%%%%% UPDATE WEIGHTS AND BIASES • vishidinc = momentum*vishidinc + ... % 784x1000 • epsilonw*( (posprods-negprods)/numcases - weightcost*vishid); % 784x 1000 • • visbiasinc = momentum*visbiasinc + (epsilonvb/numcases)*(posvisact- negvisact); % 1x784 + 1x784 - 1x784 • hidbiasinc = momentum*hidbiasinc + (epsilonhb/numcases)*(poshidact- neghidact); % 1x1000 + 1x1000 - 1x1000 • vishid = vishid + vishidinc; % 784x1000 + 784x1000 • visbiases = visbiases + visbiasinc; % 1x784 + x784 • hidbiases = hidbiases + hidbiasinc; % 1x1000 + 1x1000 • %%%%%%%%%%%%%%%% END OF UPDATES
  • 5. Data update at the bottom of epoche loop • Vishid, visbiases, hidbiases are calculated at the bottom of the RBM epoch loop and they are going to be used at the next loop. • The new values of Vishid, visbiases, hidbiases are calculated by adding vishidinc, visbiasinc, hidbiasinc. • RBM epoch loop basically calculates vishidinc, visbiasinc, hidbiasinc.
  • 6. RBM constants initialization • vishidinc, visbiasinc, hidbiasinc use some constants. • epsilonw = 0.1; % Learning rate for weights • epsilonvb = 0.1; % Learning rate for biases of visible units • epsilonhb = 0.1; % Learning rate for biases of hidden units • weightcost = 0.0002; • initialmomentum = 0.5; • finalmomentum = 0.9;
  • 7. RBM variables’ definition and init mechanism • İnit mechanism depends on the restart variable. • Mnistdeepauto has: • restart=1; • rbm; • ... • Rbm.m has : • if restart ==1, • restart=0; • epoch=1;% Initializing symmetric weights and biases. • ... • End • This mechanism disables the initialization at the further epoches than 0
  • 8. RBM variables definition and init • % Initializing symmetric weights and biases. • vishid = 0.1*randn(numdims, numhid); %784x1000 • hidbiases = zeros(1,numhid); % 1x1000 • visbiases = zeros(1,numdims); % 1x784 • • poshidprobs = zeros(numcases,numhid); %100x1000 • neghidprobs = zeros(numcases,numhid); %100x1000 • posprods = zeros(numdims,numhid); %784x1000 • negprods = zeros(numdims,numhid); %784x1000 • vishidinc = zeros(numdims,numhid); %784x1000 • hidbiasinc = zeros(1,numhid); %1x1000 • visbiasinc = zeros(1,numdims); %1x784 • batchposhidprobs=zeros(numcases,numhid,numbatches); %100x1000x600 • The values of these variables change according to the current epoch.
  • 9. Batches loop • Each repetition of epoches loop is executed for all the batches (600 of them) • for epoch = epoch:maxepoch, % 1 : 10 • fprintf(1,'epoch %dn',epoch); • errsum=0; • for batch = 1:numbatches, • fprintf(1,'epoch %d batch %dn',epoch,batch);
  • 10. Accumulating the errsum per epoch • for epoch = epoch:maxepoch, % 1 : 10 • errsum=0; • %Errsum is initiated before batch processing begins in each epoch • ... • %After the END OF NEGATIVE PHASE • err= sum(sum( (data-negdata).^2 )); %1x1 • errsum = err + errsum; • • %Error is calculated based on the difference of data and negdata and accumulated from all the batches using the errsum variable based on the current epoch. • The data/negdata concept comes from contrastive divergence.
  • 11. Varying momentum • Before passing to the next batch it resets the momentum variable that effects the rate of changes • if epoch>5, • momentum=finalmomentum; • else momentum=initialmomentum; • end; • A varying momentum maybe necessary to catch a • converging point quickly and then approach it slowly or otherwise.
  • 12. The pith of Rbm.m • The pith of rbm.m is composed of two sections (and the middle of them): • %%%%%%%%% START POSITIVE PHASE • data = batchdata(:,:,batch); % 100x784 • ... • %%%%%%%%% END OF POSITIVE PHASE • poshidstates = poshidprobs > rand(numcases,numhid); %100x1000 > 100x1000 = 100 x 1000 • %%%%%%%%% START NEGATIVE PHASE • negdata = ... • %%%%%%%%% END OF NEGATIVE PHASE
  • 13. Positive phase depends on the input x(t) while negative phase depends on the system - Hugo Larochelle
  • 14. Gibbs sampling and calculation of x(t) x(1) ... X(k) corresponds to the epoches loop
  • 15. Epoches and Gibbs repetition • for epoch = epoch:maxepoch, % 1 : 10 • errsum=0; • for batch = 1:numbatches, • %%%%%%%%% START POSITIVE PHASE • data = batchdata(:,:,batch); % 100x784 • ... • %%%%%%%%% END OF POSITIVE PHASE • poshidstates = poshidprobs > rand(numcases,numhid); %100x1000 > 100x1000 = 100 x 1000 • %%%%%%%%% START NEGATIVE PHASE • ... • %%%%%%%%% END OF NEGATIVE PHASE • err= sum(sum( (data-negdata).^2 )); %1x1 • errsum = err + errsum; • if epoch>5, • momentum=finalmomentum; • else • momentum=initialmomentum; • end; • %%%%%%%%% UPDATE WEIGHTS AND BIASES • ... • %%%%%%%%%%%%%%%% END OF UPDATES • end %of batch • fprintf(1, 'epoch %4i error %6.1f n', epoch, errsum); • end; %of epoch
  • 16. Positive Phase • %%%%%%%%% START POSITIVE PHASE • data = batchdata(:,:,batch); % 100x784 • • poshidprobs = 1./(1 + exp(-data*vishid - repmat(hidbiases,numcases,1))); • %100x784 * 784x1000 - 1x1000repmat->100x1000 = 100x1000 • batchposhidprobs(:,:,batch)=poshidprobs; %100x1000<-batch(600) • posprods = data' * poshidprobs; %784x100 * 100x1000 = 784x1000 • poshidact = sum(poshidprobs); % 1x1000 • posvisact = sum(data); % 1x784 • %%%%%%%%% END OF POSITIVE PHASE
  • 17. Calculation of positive hidden probabilities • %%%%%%%%% START POSITIVE PHASE • data = batchdata(:,:,batch); % 100x784 • % This section uses a different batch from batcchdata for each loop value of the variable batch. • %Batchdata is %100x784x600 and numbatches = 600. • %for batch = 1:numbatches, loop executes this section 600 times for each epoche. • poshidprobs = 1./(1 + exp(-data*vishid - repmat(hidbiases,numcases,1))); • %100x784 * 784x1000 - 1x1000repmat->100x1000 = 100x1000 • Poshidprobs calculates the possibility of hidden values given the data and vistohid • Weight vectors. It also adds the hidden biases with repmat. • batchposhidprobs(:,:,batch)=poshidprobs; %100x1000<-batch(600) • After calculating the poshidprobs for the current batch it saves these values to the batchposhidprobs with the batch loops counter named batch. • ... • %%%%%%%%% END OF POSITIVE PHASE
  • 18. Example • octave:6> h=1:10 • h = • 1 2 3 4 5 6 7 8 9 10 • octave:7> n=2 • n = 2 • octave:8> repmat(h,n,1) • ans = • 1 2 3 4 5 6 7 8 9 10 • 1 2 3 4 5 6 7 8 9 10
  • 19. The possibility of h given x is p(h|x) and the possibility of x given h is p(x|h)
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25. Positive phase continued... • %%%%%%%%% START POSITIVE PHASE • data = batchdata(:,:,batch); % 100x784 • poshidprobs = 1./(1 + exp(-data*vishid - repmat(hidbiases,numcases,1))); • %100x784 * 784x1000 - 1x1000repmat->100x1000 = 100x1000 • batchposhidprobs(:,:,batch)=poshidprobs; %100x1000<-batch(600) • posprods = data' * poshidprobs; %784x100 * 100x1000 = 784x1000 • poshidact = sum(poshidprobs); % 1x1000 • posvisact = sum(data); % 1x784 • %%%%%%%%% END OF POSITIVE PHASE
  • 26. Positive Phase Product calculation • %%%%%%%%% START POSITIVE PHASE • ... • posprods = data' * poshidprobs; %784x100 * 100x1000 = 784x1000 • poshidact = sum(poshidprobs); % 1x1000 • posvisact = sum(data); % 1x784 • %%%%%%%%% END OF POSITIVE PHASE
  • 27.
  • 28. Where does product term comes from?
  • 29. The pith of Rbm.m • The pith of rbm.m is composed of two sections (and the middle of them): • %%%%%%%%% START POSITIVE PHASE • data = batchdata(:,:,batch); % 100x784 • ... • %%%%%%%%% END OF POSITIVE PHASE • poshidstates = poshidprobs > rand(numcases,numhid); • %100x1000 > 100x1000 = 100 x 1000 • %%%%%%%%% START NEGATIVE PHASE • negdata = ... • %%%%%%%%% END OF NEGATIVE PHASE
  • 30. • debug> size(batchposhidprobs) • ans = • 100 1000 600 • debug> size(poshidprobs) • ans = 100 1000 • debug> poshidprobs(1:10) • ans = 0.64384 0.40320 0.43777 0.50833 0.53826 0.67048 0.20901 0.53981 0.41825 0.48169 • debug> poshidstates(1:10) • ans = • 1 0 0 1 1 1 0 1 0 0
  • 31. • octave:15> clear all • octave:16> a=rand(2,3) • a = • 0.77448 0.25583 0.51168 • 0.82385 0.54641 0.86008 • octave:17> r=rand(2,3) • r = • 0.55236 0.47071 0.49259 • 0.64676 0.21294 0.63988 • octave:18> a>r • ans = • 1 0 1 • 1 1 1
  • 32. Poshidprobs to poshidstates conversion • poshidstates = poshidprobs > rand(numcases,numhid); • Positive phase hidden probabilities are taken as input and used to calculate the input of x(1) • visual values. The possibility that the hidden values are right is taken into account by comparing them with a random generated number group.
  • 33.
  • 34. Negative Phase • %%%%%%%%% START NEGATIVE PHASE • negdata = 1./(1 + exp(-poshidstates*vishid' - repmat(visbiases,numcases,1))); • % 100x1000 * 1000x784 - 1x784repmat->100x784 = 100 x 784 • neghidprobs = 1./(1 + exp(-negdata*vishid - repmat(hidbiases,numcases,1))); • % 100x784 * 784x1000 - 1x1000repmat->100x1000 = 100x1000 • negprods = negdata'*neghidprobs; • % 784x100 * 100x1000 • neghidact = sum(neghidprobs); % 1x1000 • negvisact = sum(negdata); % 1x784 • %%%%%%%%% END OF NEGATIVE PHASE
  • 35. Negative Phase 2 • %%%%%%%%% START NEGATIVE PHASE • negdata = 1./(1 + exp(-poshidstates*vishid' - repmat(visbiases,numcases,1))); • % 100x1000 * 1000x784 - 1x784repmat->100x784 = 100 x 784 • neghidprobs = 1./(1 + exp(-negdata*vishid - repmat(hidbiases,numcases,1))); • % 100x784 * 784x1000 - 1x1000repmat->100x1000 = 100x1000 • ... • %%%%%%%%% END OF NEGATIVE PHASE
  • 36. The Product Term • %%%%%%%%% START NEGATIVE PHASE • ... • negprods = negdata'*neghidprobs; • % 784x100 * 100x1000 • neghidact = sum(neghidprobs); % 1x1000 • negvisact = sum(negdata); % 1x784 • %%%%%%%%% END OF NEGATIVE PHASE
  • 37. Where does product term comes from?
  • 38. Data update of RBM epoch loops • %%%%%%%%% UPDATE WEIGHTS AND BIASES • vishidinc = momentum*vishidinc + ... % 784x1000 • epsilonw*( (posprods-negprods)/numcases - weightcost*vishid); % 784x 1000 • • visbiasinc = momentum*visbiasinc + (epsilonvb/numcases)*(posvisact- negvisact); % 1x784 + 1x784 - 1x784 • hidbiasinc = momentum*hidbiasinc + (epsilonhb/numcases)*(poshidact- neghidact); % 1x1000 + 1x1000 - 1x1000 • vishid = vishid + vishidinc; % 784x1000 + 784x1000 • visbiases = visbiases + visbiasinc; % 1x784 + x784 • hidbiases = hidbiases + hidbiasinc; % 1x1000 + 1x1000 • %%%%%%%%%%%%%%%% END OF UPDATES
  • 39. HINTON Lecture 12C _ Restricted Boltzmann Machines
  • 40. HINTON Lecture 12C _ Restricted Boltzmann Machines