If w11+b1>0 and w21+b2>0, both neurons in the hidden layer activate.
Hidden layer of the two-layer XOR.
Second Layer Computation (Output Layer):
Using Step Function:
y=step(w31h1+w32h2+b3)
Here, h1 and h2 are outputs from the hidden layer. The step function outputs 1 if input ≥ 0, and 0 otherwise.
Output layer of the two-layer XOR.
Final Output:
The step function directly produces the binary output 0 or 1.
Example Weights and Biases (XOR Solution)
Let’s consider some weights and biases that solve XOR:
First Layer:
w11=1,w12=1,b1=−0.5w21=1,w22=1,b2=−1.5
These weights create two linear regions in the hidden layer:
h1 activates when x1+x2>0.5.
h2 activates when x1+x2>1.5.
Second Layer:
w31=1,w32=−3,b3=−0.25
These corrected output weights and bias give XOR outputs 0,1,1,0 for inputs (0,0),(1,0),(0,1),(1,1) under the stated step-function convention. Use the values here when working through the recorded example.
As we can see, our neural network was able to model the XOR problem!
Multi-Layer Neural Networks
The generalized mathematical representation of a multi-layer neural network is pretty abstract, so let’s keep it simple for now with an example that we can easily imagine generalizing to bigger nodes and more layers.
Example: Forward Propagation for a Multi-layer Neural Network
We’ll consider a multi-layer network for binary classification as follows:
Input Layer: 5-dimensional input vector.
Hidden Layer: 1: 4-dimensional, activation is ReLU.
Hidden Layer: 2: 7-dimensional, activation is ReLU.
Output Layer: 2-dimensional, activation is Step function.
Multi-layer neural network architecture diagram for our binary classification example.
Output layer of our example neural network architecture.
Finally, we do forward propagation one more time, from layer 2 (the second hidden layer), in order to get layer 3, a 2-dimensional vector denoted as a[3]:
Having passed through the layer 3 activation function (a step function), we get the final outputy, which in our case contains binary values (0 or 1), representing the binary classification decision.
Generalized Forward Propagation
Having seen this example, the generalized expressions for forward propagation will be easy to understand:
For a neural network with L layers, the generalized forward propagation equations are:
For the first layer(l=1):
z[1]=W[1]x+b[1]a[1]=f[1](z[1])
For subsequent layers(l=2,…,L):
z[l]=W[l]a[l−1]+b[l]a[l]=f[l](z[l])
Where:
W[l] is the weight matrix for layer l
b[l] is the bias vector for layer l
z[l] is the pre-activation output for layer l
a[l] is the post-activation output for layer l
f[l] is the activation function for layer l
x is the input vector
a[L] is the final output of the network
Conclusion
When I was drafting this lesson, I started with the generalized formulas for expressing a multi-layer neural network, and quickly realized how difficult they were to understand without explicitly walking through an example.
I love learning through examples. In fact, I need them. I usually can’t grasp abstract concepts otherwise.
Key Takeaways
🧠 Single-layer neural networks can only model linearly separable data.
❌ The XOR problem demonstrates the limitations of single-layer networks.
🔄 Multi-layer networks with non-linear activation functions can model complex non-linear relationships.
➡️ Forward propagation involves matrix multiplication and activation functions at each layer.
🔍 Each layer transforms the data into new representations that help solve the problem.
📏 The dimensions of weight matrices must match the dimensions of the connected layers.
⚡ ReLU and step functions are examples of non-linear activation functions used in neural networks.
Next: Backpropagation
We’ll carry the example from this lesson forward into the next one, as we continue to learn about the architecture of a multi-layer neural network.
Next up: backpropagation.
Footnotes
I made significant changes to the “Modeling Non-Linear Data” section (August 2025), removing a confusing example of a single-layer neural network with no activation (i.e., a single layer of perceptrons that collectively output a vector). The audio may still reflect the prior version. ↩︎
Comments (0)
No comments yet.