%% Specify Initial Weights and Biases in Fully Connected Layer
% To specify the weights and bias initializer functions, use the WeightsInitializer and BiasInitializer properties respectively. To specify the weights and biases directly, use the Weights and Bias properties respectively.
%
%% Specify Initialization Function
% Create a fully connected layer with an output size of 10 and specify the weights initializer to be the He initializer.

outputSize = 10;
layer = fullyConnectedLayer(outputSize,'WeightsInitializer','he')

% Note that the Weights and Bias properties are empty. At training time, the software initializes these properties using the specified initialization functions.
%
%% Specify Custom Initialization Function
% To specify your own initialization function for the weights and biases, set the WeightsInitializer and BiasInitializer properties to a function handle. For these properties, specify function handles that take the size of the weights and biases as input and output the initialized value.
% Create a fully connected layer with output size 10 and specify initializers that sample the weights and biases from a Gaussian distribution with a standard deviation of 0.0001.

outputSize = 10;
weightsInitializationFcn = @(sz) rand(sz) * 0.0001;
biasInitializationFcn = @(sz) rand(sz) * 0.0001;

layer = fullyConnectedLayer(outputSize, ...
    'WeightsInitializer',@(sz) rand(sz) * 0.0001, ...
    'BiasInitializer',@(sz) rand(sz) * 0.0001)

% Again, the Weights and Bias properties are empty. At training time, the software initializes these properties using the specified initialization functions.
%
%% Specify Weights and Bias Directly
% Create a fully connected layer with an output size of 10 and set the weights and bias to W and b in the MAT file FCWeights.mat respectively.

outputSize = 10;
load FCWeights

layer = fullyConnectedLayer(outputSize, ...
    'Weights',W, ...
    'Bias',b)

% Here, the Weights and Bias properties contain the specified values. At training time, if these properties are non-empty, then the software uses the specified values as the initial weights and biases. In this case, the software does not use the initializer functions.
% Copyright 2012 The MathWorks, Inc.