Artificial Neural Networks (ANNs) are computational models inspired by biological neural networks, structured as layers of interconnected nodes.
The Perceptron
The Perceptron is the simplest ANN architecture, computing a weighted sum of inputs plus a bias, and applying a step function:
A single Perceptron is a linear classifier, meaning it cannot solve non-linearly separable problems (like the XOR problem).
Multilayer Perceptron (MLP)
An MLP consists of an input layer, one or more hidden layers, and an output layer. Hidden layers allow the model to learn non-linear representations.
Forward Propagation
For layer , the activations are computed using the weight matrix and bias vector :
where is the activation function.
Activation Functions
Non-linear activation functions prevent stacked layers from collapsing into a single linear model:
Sigmoid: , squashing outputs to .
Tanh: , squashing to .
ReLU: , preventing vanishing gradients.
ELU: , preventing dying neurons with small negative values.
Backpropagation
Backpropagation trains networks by computing the gradient of the loss function with respect to the weights using the chain rule of calculus, working backward from the output layer:
The error term is computed recursively from the output error using matrix multiplications.
Example: Forward Pass Calculations
The following example demonstrates calculating the forward pass of a single neuron using NumPy:
Interactive Lab
import numpy as np
# Inputs, weights, and bias
x = np.array([1.5, 2.0])
w = np.array([0.8, -0.5])
b = -0.2
# Linear output
z = np.dot(w, x) + b
# ReLU activation
activation = max(0, z)
print(f"Pre-activation z: {z:.2f}")
print(f"Activation output: {activation:.2f}")
Expected output
Pre-activation z: 0.00
Activation output: 0.00
python
Interactive Lab
Compute the forward pass of a single neuron using weights, biases, and a ReLU activation function. Modify the input values to see if the neuron activates.
Step 1
Inspect the idea
Step 2
Edit the program
Step 3
Run and compare
Exercise
Test your understanding of activation functions:
Knowledge Check
Why did the deep learning community transition from Sigmoid activations to ReLU activations in hidden layers?
Answer: Because Sigmoid functions suffer from the vanishing gradient problem, where gradients become close to zero for large inputs, slowing down training.
For very positive or negative inputs, the slope of the Sigmoid function is close to zero. During backpropagation, multiplying by these small gradients causes them to vanish in early layers. ReLU has a constant gradient of 1 for all positive inputs, mitigating this problem.
Why did the deep learning community transition from Sigmoid activations to ReLU activations in hidden layers?