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

In order to perform the forward pass of a fully connected layer with a weight matrix of shape 5x5, bias vector of shape 1x25, the input should be of shape 25x2. Here's how you can perform the operation in Matlab:

main.m
% weight matrix of shape 5x5
W = randn(5,5);
% bias vector of shape 1x25
b = randn(1,25);
% input of shape 25x2 and batch size of 2
input = randn(25,2);

% perform fully connected layer operation
output = W'*input + b';

% output shape will be 1x2
248 chars
12 lines

Note that in Matlab, the * operator performs matrix multiplication while the .' operator performs matrix transpose.

related categories

gistlibby LogSnag