Convention used throughout. Vectors are bold and are column vectors (w, x). w holds weights and b is the bias. A single input is x. For a whole data set the samples are the rows of X. ln and log mean the natural logarithm. η>0 is the learning rate. ∥⋅∥ is the Euclidean norm.
A perceptron computes a weighted sum of its inputs plus a bias, called the net input z, and passes it through a step function. Geometrically, w⊤x+b=0 is a hyperplane (a line in 2-D). The perceptron answers 1 on one side of it and 0 on the other. The weight vector w is perpendicular to the hyperplane and points towards the side where the output is 1. The bias shifts the hyperplane away from the origin: its distance from the origin is ∣b∣/∥w∥, and the signed distance of a point x from it is (w⊤x+b)/∥w∥.
PERCEPTRON LEARNING RULE
w←w+η(t−y^)x,b←b+η(t−y^)
Applied sample by sample, where t is the target. If the sample is classified correctly, t - y is 0 and nothing changes. A missed class-1 sample pulls w towards x, and a missed class-0 sample pushes w away from x.
Convergence. For a finite data set and any η>0: if the two classes are linearly separable, the perceptron rule reaches a separating hyperplane after a finite number of updates, whatever the starting weights. If they are not separable, mistakes keep occurring and the weights never settle.
BOUND ON THE NUMBER OF PERCEPTRON MISTAKES
number of updates≤(γR)2,R=imax∥xi∥,γ=imintiu⊤xi>0
Assumptions: targets are -1 and +1, the bias is absorbed by appending a constant 1 to every x, the weights start at zero, and u is a unit-length vector that separates the data with margin gamma. A larger margin or smaller inputs mean fewer updates.
XOR. The points (0,0) and (1,1) belong to class 0 and (0,1) and (1,0) to class 1. No single line separates them, so no single perceptron computes XOR. AND, OR, NAND and NOR are all linearly separable. XOR can be computed by one hidden layer of two step units feeding one output unit, as (x1 OR x2) AND (x1 NAND x2). One choice of weights: h1=step(x1+x2−0.5) (OR), h2=step(1.5−x1−x2) (NAND), y=step(h1+h2−1.5) (AND). Check: (0,0) gives h=(0,1), y=0; (0,1) and (1,0) give h=(1,1), y=1; (1,1) gives h=(1,0), y=0.