Here's the code to compute the forward propagation of a fully connected layer for a batch size of 2 in Matlab:
main.m318 chars14 lines
Explanation:
input_size and output_size represent the number of neurons in the input and output layer respectively.batch_size represents the number of inputs processed in parallel.weights is a matrix of size input_size x output_size which contains the weights connecting the input layer to the output layer.bias is a vector of size 1 x output_size which contains the bias values for each neuron in the output layer.input is a matrix of size batch_size x input_size which contains the input values for each neuron in the input layer.activations is a matrix of size batch_size x output_size which contains the output values for each neuron in the output layer. The activations are computed by multiplying the input matrix with the weights matrix and adding the bias vector. This operation can be achieved using matrix multiplication and broadcasting the bias to match the same shape as the input matrix.gistlibby LogSnag