Files
machine-learning-ex4/ex4/randInitializeWeights.m
2017-05-28 06:53:01 +09:00

35 lines
1.0 KiB
Matlab

function W = randInitializeWeights(L_in, L_out)
%RANDINITIALIZEWEIGHTS Randomly initialize the weights of a layer with L_in
%incoming connections and L_out outgoing connections
% W = RANDINITIALIZEWEIGHTS(L_in, L_out) randomly initializes the weights
% of a layer with L_in incoming connections and L_out outgoing
% connections.
%
% Note that W should be set to a matrix of size(L_out, 1 + L_in) as
% the first column of W handles the "bias" terms
%
% You need to return the following variables correctly
W = zeros(L_out, 1 + L_in);
% ====================== YOUR CODE HERE ======================
% Instructions: Initialize W randomly so that we break the symmetry while
% training the neural network.
%
% Note: The first column of W corresponds to the parameters for the bias unit
%
epsilon = sqrt(6)/sqrt(L_in+L_out);
W = rand(L_out, L_in+1)*2*epsilon - epsilon;
%disp('epsilon : ');
%disp(epsilon);
%disp('first W : ');
%disp(W);
% =========================================================================
end