Linear Layer

Overview

A linear layer, also known as a fully connected layer, is a fundamental component of neural networks. In this type of layer, each neuron in one layer is connected to every neuron in the subsequent layer. This connectivity is represented by a weight matrix, which encapsulates all the connections between the layers. Linear layers are integral to the architecture of multilayer perceptrons (MLPs), where they serve as the simplest type of layer, ensuring full connectivity between neurons across layers.

Mathematical Representation

Linear layers can be mathematically expressed as matrix-vector multiplication. The weight matrix, which contains the weights of all connections from one layer to the next, is multiplied by the input vector. This operation results in the output of the layer. Typically, a nonlinear function, such as the sigmoid function, is applied to this output to introduce nonlinearity into the model, which is crucial for learning complex patterns.

Visual Representation

The concept of a linear layer can be visualized in the context of a neural network. In Figure 8.6, the linear layer is depicted as outputting layer ( l ) from layer ( (l - 1) ). The figure highlights the weights belonging to row 1 of the weight matrix, which originate from all the input neurons in layer ( (l - 1) ) and sum together to form output neuron 1.

Figure 8.6 Linear layer outputting layer l from layer (l − 1). The weights belonging to row 1 of the weight matrix (coming from all the input neurons, layer (l − 1), which sum together to form output neuron 1) are shown in bold. Figure 8.6 Linear layer outputting layer l from layer (l − 1). The weights belonging to row 1 of the weight matrix (coming from all the input neurons, layer (l − 1), which sum together to form output neuron 1) are shown in bold.

Application in Multilayer Perceptrons

In multilayer perceptrons (MLPs), linear layers are crucial as they form the backbone of the network's architecture. Each perceptron in the ( l )th layer receives inputs from the previous ( (l - 1) )th layer, as illustrated in the context of a perceptron. This structure allows for the construction of deep neural networks, where multiple linear layers are stacked to form a complete network, as shown in Figure 8.7.

Figure 8.7 Multilayered neural networks: This is a complete deep neural network, a slice of which is shown in figure 8.6. Figure 8.7 Multilayered neural networks: This is a complete deep neural network, a slice of which is shown in figure 8.6.