fully connected layer forward pass weight matrix shape 25x25, bias vector shape 1x25, input shape 25x1, batch size=2 in matlab

To compute the forward pass of a fully connected layer in MATLAB, you can use the fullyConnectedLayer function from the Deep Learning Toolbox. Here's an example of how to do it with a weight matrix of shape 25x25, a bias vector of shape 1x25, an input of shape 25x1, and a batch size of 2:

main.m
% create a fully connected layer
layer = fullyConnectedLayer(25);

% set the weights and biases
layer.Weights = randn([25 25]);
layer.Bias = randn([1 25]);

% create an input of shape 25x1
input = randn([25 1]);

% set the batch size
batchSize = 2;

% create a batch of inputs
inputs = repmat(input, [1 1 batchSize]);

% compute the forward pass
output = predict(layer, inputs);
379 chars
19 lines

The repmat function is used to create a batch of inputs by repeating the same input batchSize times along the third dimension. The predict function is used to compute the forward pass of the layer for the batch of inputs. The resulting output is of shape 25x1x2, where the third dimension corresponds to the batch size.

gistlibby LogSnag