Artificial Intelligence and modern Deep Learning rest upon a humble atomic building block: the Perceptron. Invented by Frank Rosenblatt in 1958, a Single-Layer Perceptron learns a linear hyperplane that separates two distinct classes of data.
1. Summary & Key Takeaways
- The Linear Equation: A Perceptron calculates a weighted sum of its inputs plus a bias term:
- Step Activation Function: If , the output is (Cyan Class); otherwise, the output is (Pink Class).
- Linear Separability: Single-layer perceptrons can only classify datasets that are linearly separable (meaning a single straight line can divide the classes).
- Perceptron Learning Rule: Weight updates occur only when a misclassification occurs:
2. Interactive Perceptron Playground
Use the interactive 2D plane below to add data points (Class A vs Class B), adjust weights manually with the sliders, or click “Train 1 Epoch” to watch the perceptron learn the optimal decision boundary line!
Click anywhere on the 2D black canvas grid to drop new custom data points. Watch how training adjusts the decision line’s slope and position!
Single-Layer PerceptronBinary Classification
Click on the 2D plane to add training points. Train the decision boundary w₁x₁ + w₂x₂ + b = 0 in real-time.
import numpy as np
class Perceptron:
def __init__(self, num_inputs, learning_rate=0.1):
self.weights = np.zeros(num_inputs)
self.bias = 0.0
self.lr = learning_rate
def predict(self, inputs):
summation = np.dot(inputs, self.weights) + self.bias
return 1 if summation >= 0 else -1
def train(self, inputs, target):
prediction = self.predict(inputs)
error = target - prediction
if error != 0:
self.weights += self.lr * error * inputs
self.bias += self.lr * error3. Mathematical Foundations
The Perceptron computes a linear decision boundary separating two classes in 2D space:
Where:
- dictates the slope along the axis.
- dictates the slope along the axis.
- (bias) shifts the boundary line away from the origin .
- (learning rate) controls the magnitude of weight updates per epoch step.
If a dataset is not linearly separable (for example, the XOR problem), a single-layer perceptron will fail to reach accuracy—which led to the development of Multi-Layer Perceptrons (MLPs) and Backpropagation!