The forward pass of a fully connected layer multiplies the input with the weight matrix, adds the bias vector, and applies the activation function. In MATLAB, this can be done as:
main.m155 chars13 lines
Here, the weight matrix W
has dimensions 5x5
, the bias vector b
has dimensions 25x1
, and the input matrix X
has dimensions 25x2
.
The forward pass matrix multiplication X*W
will result in a matrix with dimensions 25x5
, which when added to the bias vector b'
(transpose of b
) of dimensions 1x25
, results in a matrix with dimensions 25x25
. Applying the sigmoid activation function element-wise to this matrix results in the output matrix A
with dimensions 25x25
.
Note that the sigmoid function needs to be defined separately in MATLAB as:
main.m84 chars5 lines
This can be put in a separate file and called within the main code.
gistlibby LogSnag