Halfspaces and the Perceptron Algorithm
In questa pagina 4
The first learning algorithm of the course. Hypotheses are halfspaces: the input space is cut by a hyperplane and one side is labelled , the other . The convergence guarantee is in Perceptron Convergence and the Margin BoundThe distance of a point x from the hyperplane w^T x + b = 0 is |w^T x + b| / sqrt(w^T w), obtained by writing x = x_p + gamma with gamma parallel to w. If the data are linearly separable with margin gamma (a unit vector w* with y_i w*^T x_i >= gamma for all i) and every point lies in a ball of radius R, the Perceptron Learning Algorithm makes at most K <= R^2 / gamma^2 updates. Proof: after K updates w_{K+1}^T w* >= K gamma, hence norm of w_{K+1} >= K gamma; and norm of w_{K+1} squared <= K R^2; combine.Perceptron Convergence and the Margin Bound →; the same unit trained by gradient descent is in ADALINE and Gradient DescentADALINE is a perceptron whose activation function is the identity: during training the unit outputs w^T x and the in-sample error E_in = (1/N) sum (y_i - w^T x_i)^2 is minimised by gradient descent, w_new = w_old - eta * grad E_in, with partial derivatives dE_in/dw_j = (2/N) sum (y_i - w^T x_i)(-x_i^j) and matrix form grad E_in proportional to -X^T (Y - X w). The prediction is still the sign of w^T x. Learning rate eta sets the step size and a stopping rule ends the iteration.ADALINE and Gradient Descent →; code in Python Notebooks - Perceptron and ADALINE from ScratchCode of the course notebooks that implement the Perceptron Learning Algorithm first with Python lists, then with plots of the successive lines, then with NumPy arrays (data matrix X with a column of ones, update w + eta * y * x on mistakes, epoch counter), and finally ADALINE: batch gradient descent with delta_w = eta * 2 * X^T (y - X w) / N and the stochastic version that shuffles the data and updates after every example. Differences between the versions (condition for a mistake, learning rate, stopping rule) are pointed out.Python Notebooks - Perceptron and ADALINE from Scratch →.
1. The neuron model
The handwritten page draws a node (cell, neuron) that receives four inputs through four weights and either fires or does not (output ). The hypothesis is
and the rule is
- it fires;
- it does not fire.
Encoding "fires" as and "does not fire" as :
Bias trick. The part and the term are circled in the page and then merged: add a constant input ("bias ") with weight . Then
A point of the plane becomes the vector : the page lifts a point with , into the vector (coordinates ) and draws a third axis for the constant. Every example of the course (and the data matrix of the notebooks) carries this column of ones.
2. The boundary
The decision depends on the sign of : positive side , negative side ; is the boundary. In the plane write a generic line as ; with the course symbols the boundary is
Slope and intercept are the two circled quantities of the page; the notebooks use exactly this to draw the line from the three weights.
3. Perceptron Learning Algorithm (PLA)
Data set: with . We want for every (the page writes , , ). The two ways to be wrong (framed in red) are
- but ;
- but .
Geometry of a mistake. Draw and as vectors from the origin.
- but : the weight vector points "towards" (acute angle) when it should point away. The page draws and rotates towards it.
- but : the angle is obtuse; must be added to so that it turns towards .
Both cases are one formula, the update rule:
Why it moves the right way (computed here): after the update on , . For the value goes up by , for it goes down by the same amount: always towards the correct sign (one update may not be enough, but it improves that point).
Algorithm.
start with w (the notebooks use zeros or random numbers)
repeat
for each example (x, y) of the data set:
if h(x) != y (that is, y * w^T x has the wrong sign):
w = w + y * x
until no example is misclassified (or a maximum number of steps is reached)The page of "the lines" shows the successive separating lines converging between a cloud of points (triangles) and a cloud of points (circles). The question left open at this point, "how many steps do we need to find a solution?", is answered in Perceptron Convergence and the Margin BoundThe distance of a point x from the hyperplane w^T x + b = 0 is |w^T x + b| / sqrt(w^T w), obtained by writing x = x_p + gamma with gamma parallel to w. If the data are linearly separable with margin gamma (a unit vector w* with y_i w*^T x_i >= gamma for all i) and every point lies in a ball of radius R, the Perceptron Learning Algorithm makes at most K <= R^2 / gamma^2 updates. Proof: after K updates w_{K+1}^T w* >= K gamma, hence norm of w_{K+1} >= K gamma; and norm of w_{K+1} squared <= K R^2; combine.Perceptron Convergence and the Margin Bound →. A learning rate multiplying the update () is used in the notebooks.
4. Limits of a single perceptron
Not every data set is separable. The page with the four points (triangles) and (dots) is the exclusive-or pattern: whichever straight line is drawn, one of the points ends on the wrong side. A single halfspace cannot represent it, and PLA, which only stops when all points are correct, would never stop (the notebooks add a maximum number of iterations for this reason).
Two perceptrons. A later page solves the same pattern with two lines and : the points of one class lie between the two lines (region ), the points of the other class lie outside (region above and below ). The sketch next to it is a small network: four inputs , a layer of two perceptrons, and one more perceptron that combines their outputs (connections drawn with signs and ) to produce the final output. It is labelled multilayer neural network, trained with the backpropagation algorithm, and its deep versions "deep learning". The notes only name these; no derivation is given.
Which separating line? When the data are separable there are infinitely many lines that work (the family of black lines in the drawing). The notes sketch a strip of maximal width between the two clouds, with the points that touch its edges circled, and name it Support Vector Machines; again only a pointer.
Versione ripasso
- Neuron: fires () when , else . Bias trick: , , so . Every example carries the column of ones.
- Boundary ; in the plane .
- Data with ; goal . Mistakes: or .
- PLA update on a misclassified point: . Check: , so the value moves towards the correct sign.
- Algorithm: start with ; scan the examples; update on each mistake; repeat until no mistake or a maximum number of steps. Notebooks add a learning rate: .
- Separable data: infinitely many lines work. Steps needed: Perceptron Convergence and the Margin BoundThe distance of a point x from the hyperplane w^T x + b = 0 is |w^T x + b| / sqrt(w^T w), obtained by writing x = x_p + gamma with gamma parallel to w. If the data are linearly separable with margin gamma (a unit vector w* with y_i w*^T x_i >= gamma for all i) and every point lies in a ball of radius R, the Perceptron Learning Algorithm makes at most K <= R^2 / gamma^2 updates. Proof: after K updates w_{K+1}^T w* >= K gamma, hence norm of w_{K+1} >= K gamma; and norm of w_{K+1} squared <= K R^2; combine.Perceptron Convergence and the Margin Bound →.
- Geometry of a mistake: with means the angle is acute, so must turn away from (the sketch draws ); with and the angle is obtuse, so is added.
- Lines of the sketch: successive separating lines converge between a cloud of points and a cloud of points.
- Exclusive-or pattern against : not separable by one line. Two perceptrons plus a combining one give a multilayer network (backpropagation, deep learning: named only). Maximal-margin line: Support Vector Machines (named only).
- Typical errors: forgetting ; updating on correct points; expecting PLA to stop on non-separable data.
- Related: ADALINE and Gradient DescentADALINE is a perceptron whose activation function is the identity: during training the unit outputs w^T x and the in-sample error E_in = (1/N) sum (y_i - w^T x_i)^2 is minimised by gradient descent, w_new = w_old - eta * grad E_in, with partial derivatives dE_in/dw_j = (2/N) sum (y_i - w^T x_i)(-x_i^j) and matrix form grad E_in proportional to -X^T (Y - X w). The prediction is still the sign of w^T x. Learning rate eta sets the step size and a stopping rule ends the iteration.ADALINE and Gradient Descent → (same unit trained by gradient descent).
Teoria collegata
- ADALINE and Gradient Descent
- Classification Metrics - Confusion Matrix, Precision, Recall and F1
- Introduction to Machine Learning - Learning, Data and Tasks
- Introduction to Machine Learning - Program Map
- Linear Regression
- Logistic Regression
- Perceptron Convergence and the Margin Bound
- Python Notebooks - Perceptron and ADALINE from Scratch
- Python Notebooks - scikit-learn Model Comparison and Wilcoxon Test