Math Behind Neural Networks
Math of Neural Networks and the Universal Approximation Theorem
Neural networks are computational systems inspired by the biological neural networks that constitute our and animal brains. At their core, these networks consist of layers of nodes, or "neurons," each of which applies a simple computation to its inputs. The Universal Approximation Theorem provides the theoretical foundation for these systems, offering assurance that neural networks have the capacity to model a wide variety of functions given sufficient complexity and proper configuration.
Mathematical Representation of a Neural Network
At the simplest level, a neural network can be thought of as a function where is the dimensionality of the input vector and is the dimensionality of the output vector. A basic feed-forward neural network with one hidden layer can be mathematically represented as:
Where:
- is the input vector.
- and are matrices representing the weights of the first and second layer, respectively.
- and are vectors representing the biases of the first and second layer, respectively.
- represents the activation function applied element-wise. Common choices for include the sigmoid function, ReLU (Rectified Linear Unit), and tanh (hyperbolic tangent).
The Role of the Activation Function
The activation function is a vital component of a neural network. As its name implies, it governs the output, or 'activation,' of a neuron. Its importance lies in its unique ability to introduce non-linearity into the model, which broadens the range and complexity of functions the network can represent.
Consider a simpler scenario where the activation functions are absent from a neural network comprising many layers. In effect, such a network is merely applying a sequence of linear transformations on the input data. But mathematically, regardless of how many times you apply them, a composition of linear transformations merely results in another linear transformation. A neural network without any activation functions, regardless of how many layers it may have, behaves similarly to linear regression. This is because it performs a linear transformation on the input data.
On the flip side, by introducing non-linearity via activation functions, we empower the network to learn from and represent much more complex patterns in the data.
A few common activation functions include:
- Sigmoid function: This function outputs a value between 0 and 1, making it particularly useful for binary classification problems to represent probabilities. However, it suffers from the vanishing gradients problem, limiting its use in deep networks.
- Hyperbolic Tangent (tanh): The tanh function outputs a value between -1 and 1. It's a scaled version of the sigmoid function and, like sigmoid, suffers from the risk of vanishing gradients.
- Rectified Linear Unit (ReLU): This function keeps positive inputs unchanged and outputs 0 for negative inputs. It's simple, computationally efficient, and widely used in many neural networks. However, it may cause dead neurons which never get activated.
Here is a simple Python implementation of these activation functions:
These functions enable the neural network to model a diversity of complex, non-linear phenomena, making them indispensable in the world of deep learning.




