Wednesday 5 December 2018

testDNN analysis 11

% GetOnInd: get indexes which are used (not dropped) nodes
%
% OnInd = GetOnInd( dbn, DropOutRate, strbm )
%
%
%Output parameters:
% OnInd: indexes which are used (not dropped) nodes
%
%
%Input parameters:
% dbn: the Original Deep Belief Nets (DBN) model
% DropOutRate: 0 < DropOutRate < 1
% strbm (optional): started rbm layer to dropout (Default: 1)
%
%
%Reference:
%for details of the dropout
% Hinton et al, Improving neural networks by preventing co-adaptation of feature detectors, 2012.
%
%
%Version: 20130821

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Deep Neural Network:                                     %
%                                                          %
% Copyright (C) 2013 Masayuki Tanaka. All rights reserved. %
%                    mtanaka@ctrl.titech.ac.jp             %
%                                                          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function OnInd = GetOnInd( dbn, DropOutRate, strbm ) % ... , 3 x 1, 1

if( ~exist('strbm', 'var') || isempty(strbm) )
strbm = 1;
end

OnInd = cell(numel(dbn.rbm),1); % 3, 1

for n=1:numel(dbn.rbm) % 1:3
    dimV = size(dbn.rbm{n}.W,1); % 32->16->8
    if( n >= strbm )
        OnNum = round(dimV*DropOutRate(n)); % 16->8->4 DropOutRate 0.7 would cause OnNum=22 -->22 x 32 as OnInd{1}
        OnInd{n} = sort(randperm(dimV, OnNum)); % OnNum integers btw 1 and dimV -->randperm(32 x 16, 16 x 8, 8 x 4) = 16 x 32, 8 x 16, 4 x 8
    else
        OnInd{n} = 1:dimV; %1 2 3 4 5 6 7 8
    end
end

%{
randperm (n)
randperm (n, m)
Return a row vector containing a random permutation of 1:n.
If m is supplied, return m permutations, one in each row of an MxN matrix

octave:1> randperm(8,4)
ans =

   1   6   2   8   4   5   3   7
   3   1   6   2   5   4   7   8
   4   6   8   7   5   1   2   3
   2   8   5   7   1   6   4   3

octave:2> sort(randperm(8,4))
ans =

   1   3   2   4   1   6   1   2
   2   3   5   5   2   6   1   4
   5   3   8   6   3   7   4   4
   8   6   8   7   7   7   8   5

%}
%{
debug> aa=[1,2,3,4;5,6,7,8;9,10,11,12]
debug> aa
aa =

    1    2    3    4
    5    6    7    8
    9   10   11   12

debug> bb
bb =

   1   1
   2   2
   3   3
   4   4

debug> cc
cc =

   1
   1

debug> aa(cc,bb)
ans =

   1   2   3   4   1   2   3   4
   1   2   3   4   1   2   3   4

debug> aa
aa = 3 x 4

    1    2    3    4
    5    6    7    8
    9   10   11   12

debug> aa(bb)
ans =

   1   1
   5   5
   9   9
   2   2
debug> bb
bb =  2 x 4

   1   1
   2   2
   3   3
   4   4

debug> dd
dd = 1 x 2

   1
   2

debug> aa(dd,bb) 2 x 8
ans =

   1   2   3   4   1   2   3   4
   5   6   7   8   5   6   7   8

%}