Chapter 2
Supervised Learning (Perceptron)
Linear relationship and linear separability, linear regression, key ANN terms, activation functions, and the 4-step perceptron learning algorithm.
From: Chapter 2_Supervised Learning (Perceptron).pptx
Linear relationship vs linear separability (slides 4–9)
- Linear relationship: a straight-line relationship with a constant rate of change. Taxi fare: RM5 base + RM2 per km. It is about how variables combine.
- Linear separability: a single straight line (or plane, or hyperplane) can perfectly separate the classes. It is about whether classes can be split by a straight line.
- 2-D needs a line; 3-D needs a plane; higher dimensions need a hyperplane.
- Linearly separable patterns can be learned by a single-layer neural network.
- Applies to binary classification (e.g. positive vs negative).
- If no straight line can separate the data (a non-linear problem), use a non-linear algorithm/model. XOR is the classic example.
Linear regression (slides 11–16)
Regression predicts a continuous outcome (dependent variable) from input features (independent variables). Linear regression is the simplest form: the relationship is a straight line. It finds the best-fitting line that minimises the error, usually by least squares.
y = m·x + b
m = slope (rate of change), b = intercept (baseline value when x = 0)
House price (slides 13–14)
- Data: 50 m² → RM150,000; 70 → 200,000; 100 → 280,000; 120 → 330,000.
- Slope m = 2,500: each extra 1 m² adds RM2,500.
- For 90 m², the slides' model predicts RM275,000.
- Gradient descent starts with random m and b, computes the error (cost function), and adjusts the parameters step by step toward the minimum error.
- Why use it: simple, interpretable, a good starting point when the relationship is linear.
- Limitation: poor when the relationship is non-linear or features interact in complex ways.
Terms and jargon (slide 18)
| Term | Meaning |
|---|---|
| Activation function | Transforms a neuron's net input into its activation (also: transfer / output function). Adds non-linearity |
| Learning rate (α) | Controls how much the weights change in training. Constant (standard backpropagation) or reduced over time for stability (Kohonen) |
| Momentum | Weight change = current adjustment + previous step's change. Speeds up and stabilises gradient descent |
| Epoch | One presentation of each training pattern (one pass through the training set) |
| Binary / Bipolar | Binary = 0 or 1. Bipolar = −1 or 1 |
| Architecture | Arrangement of nodes and their connection links |
| Learning algorithm | Procedure for modifying the weights (training algorithm, learning rule) |
| Bias | Extra parameter that makes the model more flexible; shifts the output even when the input is 0 |
Activation functions (slides 19–22)
| Function | Output | Formula |
|---|---|---|
| Identity | Same as input | f(x) = x |
| Binary step (step / threshold) | 0 or 1 | Y = 1 if X ≥ 0, else 0 |
| Bipolar step (sign) | −1 or +1 | Y = +1 if X ≥ 0, else −1 |
| Step with threshold t | 1 or −1 | f(x) = 1 if x ≥ t, −1 if x < t |
| Binary sigmoid (logistic) | Between 0 and 1 | Y = 1 / (1 + e^(−X)) |
| Bipolar sigmoid | Between −1 and 1 | Y = (1 − e^(−X)) / (1 + e^(−X)) |
- Step and sign are threshold-based: X is the weighted sum, output = f(X).
- Sigmoid is continuous and differentiable (S-shaped). Smooth gradient, no jumps; output bounded 0–1. For X above 2 or below −2 the output is pushed close to 1 or 0, giving clear predictions.
The perceptron (slides 24–28)
- Developed by Frank Rosenblatt in 1958. Uses a step activation; training continues until no error occurs.
- Perceptron convergence theorem: if weights exist that let the net respond correctly to all training patterns, the learning rule will find them.
The 4 steps
- Step 1, Initialisation: set weights w1…wn and threshold θ to random numbers in [−0.5, 0.5]. Set a low learning rate α (e.g. 0.1).
- Step 2, Activation: apply inputs x1…xn and desired output Yd. Compute the actual output Y(p) = step[ Σ xi(p)·wi(p) − θ ].
- Step 3, Weight training: error e = Yd − Ya. If e = 0, weights stay the same. Otherwise Δwi = α · xi · e, and wi(p+1) = wi(p) + Δwi.
- Step 4, Iteration: go back to Step 2 with the new weights. Stop when there is zero error for all input–output pairs.
Y(p) = step[ Σ xᵢ(p)·wᵢ(p) − θ ]
e = Yd − Ya Δwᵢ = α · xᵢ · e wᵢ(p+1) = wᵢ(p) + Δwᵢ
AND function, binary inputs, bipolar targets, α = 1, θ = 0.2 (slides 29–31)
- Start with w1 = w2 = b = 0. Bias input is always 1, so Δb = α · e.
- Pattern (1, 1), target 1: y_in = 0 + 0 + 0 = 0 and the slide takes ya = −1, so e = 1 − (−1) = 2.
- Δw1 = α·e·x1 = 2, Δw2 = 2, Δb = 2, so the new weights are w1 = 2, w2 = 2, b = 2.
- Keep presenting (1,0), (0,1), (0,0) with target −1 and updating whenever y ≠ t.
- Presenting all four patterns once = 1 epoch. Repeat epochs until no weights change.
Exam habit: always write e = Yd − Ya first. If e = 0, write “no weight change” and move on.