perceptron - courses.cs.vt.educourses.cs.vt.edu/cs5824/fall19/slide_pdfs/4 perceptron.pdf ·...

15
Perceptron Machine Learning CS5824/ECE5424 Bert Huang Virginia Tech

Upload: others

Post on 25-Oct-2019

12 views

Category:

Documents


4 download

TRANSCRIPT

Perceptron

Machine Learning CS5824/ECE5424

Bert Huang Virginia Tech

Plan

• Perceptron

• Multi-class perceptron

Perceptron• AKA single-layer neural network

• linear classifier

• online learner

f (x) = sign

X

i

wixi

!

x1 x2 x3 x4 x5

w1w2 w3w4 w5

y

=

(+1 if

Pi wixi � 0

�1 ifP

i wixi < 0

Online Training

• Get example x and oracle label y

• Try current classifier f(x)

• If f(x) = y, celebrate

• If f(x) ≠ y, fix it

f(x) = sign(w1x1 + w2x2 + w3x4 + … )

if y = +1 and f(x) = -1, w•x is too smallif y = -1 and f(x) = +1, w•x is too big

How to Fix Your Broken Perceptron

Example:w = [2, 1], x = [3, 1], y = -1

f(x) = sign(w1 x1 + w2 x2) = +1

f(x) = sign(2(3) + 1(1))

w ← w - x if f(x) = +1 and y = -1w ← w + x if f(x) = -1 and y = +1w ← w if f(x) = y

w = [-1, 0]

w ← w + yx if f(x) ≠ yUpdate: W1 = 2 - 3W2 = 1 - 1

New f(x) = -1(3) + 0(1)

How to Fix Your Broken Perceptronw ← w - x if f(x) = +1 and y = -1w ← w + x if f(x) = -1 and y = +1w ← w if f(x) = y

w ← w + yx if f(x) ≠ y

y = +1, f(x) = -1w • x (w + x) • x

w • x + x • x

(w - x) • x

w • x - x • x

≥y = -1, f(x) = +1

w • x

Binary Perceptron Learning

w ← w + αyx if f(x) ≠ y α = learning rate

b ← b + αy if f(x) ≠ y

f(x) = sign(w • x)sign(w • x + b) bias

Multiclass Output

+1-1

Multiclass Output

Multiclass Perceptron• Separate weights for each class: w0, w1, w2, w3, w4, w5, w6, …

• Predict according to maximum scoring class:

f(x) = argmax wy'•x• Learning update:

wy ← wy + x wf(x) ← wf(x) - x

y'

Multiclass Perceptron• Learning update:

wy ← wy + x wf(x) ← wf(x) - xx

f(x) = 6

w2 ← w2 + x (make w2 • x greater)y = 2

w6 ← w6 - x (make w6 • x lesser)

Multiclass Perceptron• Learning update:

wy ← wy + x wf(x) ← wf(x) - xx

f(x) = 2

w2 ← w2 + xy = 2

w2 ← w2 - x

Multiclass Perceptron• Learning update:

wy ← wy + x wf(x) ← wf(x) - xx

f(x) = 2 w2 ← w2 + x - xy = 2 = w2

Perceptron Summary• Linear classifier multiplies weights by input features

• Learn by updating when wrong

• If score too low, make score higher

• If score too high, make score lower

• Multiclass: use multiple weight vectors, choose max scoring

• Learn by adjusting score of predicted class and true class