MAT6007 Session5 Perceptron Algorithm
MAT6007 Session5 Perceptron Algorithm
end
Perceptron Algorithm
Algorithm:
Perceptron Learning Algorithm
P ← inputs with label 1;
N ← inputs with label 0;
Initialize w randomly;
while !convergence do
Pick random x ∈ P ∪ N ;
if x ∈ P and
w = w + x;
end
end
Perceptron Algorithm
Algorithm:
Perceptron Learning Algorithm
P ← inputs with label 1;
N ← inputs with label 0;
Initialize w randomly;
while !convergence do
Pick random x ∈ P ∪ N ;
if x ∈ P and
w = w + x;
end
if x ∈ N and
w = w - x;
end
end
Perceptron Algorithm
Algorithm:
Perceptron Learning Algorithm
P ← inputs with label 1;
N ← inputs with label 0;
Initialize w randomly;
while !convergence do
Pick random x ∈ P ∪ N ;
if x ∈ P and
w = w + x;
end
We are interested in finding the line
if x ∈ N and
wTx = 0 which divides the input space
w = w - x; into two halves
end
end Every point (x) on this line
satisfies the equation wTx = 0
What can you tell about the angle (α) between w and any point (x) which lies
on this line ?
Perceptron Algorithm
Consider some points (vectors) which lie in the
Algorithm:
Perceptron Learning Algorithm
positive half space of this line (i.e., wTx ≥ 0)
P ← inputs with label 1;
N ← inputs with label 0; What will be the angle between any such
Initialize w randomly; vector and w ?
while !convergence do Obviously, less than 90°
Pick random x ∈ P ∪ N ; What about points (vectors) which lie in the
if x ∈ P and
w = w + x;
negative half space of this line (i.e., wTx < 0)
end What will be the angle
if x ∈ N and between any such vector
w = w - x;
end
and w ?
end
Obviously, greater than 90°
Perceptron Algorithm For x ∈ P if w.x < 0 then it means
that the angle (α) between this x
Algorithm:
Perceptron Learning Algorithm
and the current w is greater than
P ← inputs with label 1;
N ← inputs with label 0; 90° (but we want α to be less than
Initialize w randomly; 90°)
while !convergence do What happens to the new angle
Pick random x ∈ P ∪ N ; (αnew) when wnew = w + x
if x ∈ P and
w = w + x;
end
if x ∈ N and
w = w - x;
end
end
Perceptron Algorithm
For x ∈ N if w.x ≥ 0 then it means
Algorithm:
Perceptron Learning Algorithm that the angle (α) between this x
P ← inputs with label 1; and the current w is less than 90°
N ← inputs with label 0; (but we want α to be greater than
Initialize w randomly; 90°)
while !convergence do
Pick random x ∈ P ∪ N ; What happens to the new angle
if x ∈ P and (αnew) when wnew = w − x
w = w + x;
end
if x ∈ N and
w = w - x;
end
end
Perceptron Algorithm
Do we always need to hand code the threshold? No, we can learn the threshold
Are all inputs equal? What if we want to assign more weight (importance) to some
inputs? A perceptron allows weights to be assigned to inputs
https://www.cse.iitm.ac.in/~miteshk/CS6910.html#schedule
https://machinelearningmastery.com/perceptron-algorithm-for-cla
ssification-in-python
/ Prakash VIT Chennai
Thanks