Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Explore the biological inspiration and mathematical formulation of the Perceptron, the atomic building block of deep learning.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Sensory or feature signals | ||
| Synaptic weights | Learned amplification or inhibition factors | |
| Threshold offset | ||
| Firing function |
Inputs [1, 0] with weights [3.0, 2.0] and bias -1.5.
Result: Neuron fires: Output = 1
Incoming numerical values x1, x2, ... xn are ingested via input channels.
Each input xi is scaled by its corresponding connection weight wi.
All weighted products are summed together with the scalar bias b.
The aggregate sum z is passed through activation function f(z) to yield final output a.
Problem: Implementing AND / OR gates using pure numerical weights.
Solution: A single perceptron can compute AND by setting w1=1, w2=1, bias=-1.5.
Problem: Approving or denying credit applications in financial workflows.
Solution: A single artificial neuron weights income, credit score, and debt ratio.
Interactive activity component
Implement a perceptron learning rule that learns the logical OR gate.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install numpy1 import numpy as np
import numpy as np β NumPy for vector math
1 # Logical OR truth table: inputs X, target y 2 X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]]) 3 y = np.array([0, 1, 1, 1]) # OR gate output 4 5 w = np.zeros(2) # Initial weights [0, 0] 6 b = 0.0 # Initial bias 7 lr = 0.1 # Learning rate 8 9 for epoch in range(20): 10 for i in range(len(X)): 11 z = np.dot(X[i], w) + b 12 y_pred = 1 if z >= 0 else 0 # Step function 13 error = y[i] - y_pred 14 w += lr * error * X[i] # Rosenblatt weight update 15 b += lr * error # Update bias 16 17 print("Learned Weights:", w.round(2), "Bias:", round(b, 2)) 18 for sample in X: 19 pred = 1 if (np.dot(sample, w) + b) >= 0 else 0 20 print(f"Input {sample} -> Output: {pred}")
# Logical OR truth table: inputs X, target y
Truth table
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
All 4 input pairs
y = np.array([0, 1, 1, 1]) # OR gate output
OR targets
w = np.zeros(2) # Initial weights [0, 0]
Weights
b = 0.0 # Initial bias
Bias
lr = 0.1 # Learning rate
Step size
for epoch in range(20):
Train 20 iterations
for i in range(len(X)):
Loop over samples
z = np.dot(X[i], w) + b
Linear sum
y_pred = 1 if z >= 0 else 0 # Step function
Activation
error = y[i] - y_pred
Perceptron error
w += lr * error * X[i] # Rosenblatt weight update
Update weights
b += lr * error # Update bias
Update bias
print("Learned Weights:", w.round(2), "Bias:", round(b, 2))
Print parameters
for sample in X:
Verify on all inputs
pred = 1 if (np.dot(sample, w) + b) >= 0 else 0
Inference
print(f"Input {sample} -> Output: {pred}")
Display result
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Building a Perceptron from Scratch in Python 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install numpy 8 9 # Step 2: Import libraries 10 import numpy as np 11 12 # Step 3: Run Demonstration 13 # Logical OR truth table: inputs X, target y 14 X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]]) 15 y = np.array([0, 1, 1, 1]) # OR gate output 16 17 w = np.zeros(2) # Initial weights [0, 0] 18 b = 0.0 # Initial bias 19 lr = 0.1 # Learning rate 20 21 for epoch in range(20): 22 for i in range(len(X)): 23 z = np.dot(X[i], w) + b 24 y_pred = 1 if z >= 0 else 0 # Step function 25 error = y[i] - y_pred 26 w += lr * error * X[i] # Rosenblatt weight update 27 b += lr * error # Update bias 28 29 print("Learned Weights:", w.round(2), "Bias:", round(b, 2)) 30 for sample in X: 31 pred = 1 if (np.dot(sample, w) + b) >= 0 else 0 32 print(f"Input {sample} -> Output: {pred}")
When prediction is wrong, weights are adjusted directly in the direction of the error.
Within 10 epochs, learns positive weights (~0.2, ~0.2) and negative bias (~ -0.1), perfectly solving the OR gate.
4 Boolean input pairs for logical OR
Learned Weights: [0.2 0.2] Bias: -0.1 Input [0 0] -> Output: 0 Input [0 1] -> Output: 1 Input [1 0] -> Output: 1 Input [1 1] -> Output: 1
The perceptron converged on linear parameters that flawlessly separate 0 from 1 in the Boolean plane.
CNN, MNIST dataset, backpropagation, loss functions, and optimization.
Test your understanding with these questions. Remember, this is for learning, not examination!