Here is an example code for a fully connected layer forward pass with a 5x5 weight matrix, 25x1 bias vector, and 25x2 input size in MATLAB:
main.m291 chars13 lines
Explanation:
We define an input matrix of size 25x2, which represents 25 input examples each with 2 features. The specific values of the input matrix are not important for this example.
We define a weight matrix of size 5x25, representing the connections between the input layer and the fully connected layer. We also define a bias vector of size 5x1, which is added to each output node of the layer.
We compute the output of the fully connected layer using the matrix multiplication between the weight matrix and the input matrix, and adding the bias vector. To do this, we first transpose the input matrix (using the ' operator) to match the expected dimensions of the weight matrix (25x2 -> 2x25). The result of this multiplication is a 5x25 matrix, which represents the activations of the 5 nodes in the fully connected layer for each of the 25 input examples.
Finally, we transpose the output matrix (using the ' operator again) to match the desired dimensions of 25x5, where each row represents the activations of the 5 nodes for a specific input example.
gistlibby LogSnag