Neural Networks: Regression & Classification
Neural Networks: Regression & Classification
Classification with
Neural Networks
Note to other teachers and users of
these slides. Andrew would be
Andrew W. Moore
Professor
delighted if you found this source
material useful in giving your own
lectures. Feel free to use these
slides verbatim, or to modify them
to fit your own needs. PowerPoint School of Computer Science
originals are available. If you make
inputs outputs
x1 = 1 y1 = 1
x2 = 3 y2 = 2.2
w x3 = 2 y3 = 2
1
x4 = 1.5 y4 = 1.9
x5 = 4 y5 = 3.1
where…
• the noise signals are independent
• variance σ2
Estimation
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 4
Maximum likelihood estimation
of w
P( y
i 1
i w, xi ) maximized?
P( y
i 1
i w, xi ) maximized?
For what w is
2
n
1 yi wxi
i 1
2
maximized?
For what w is 2
n
y
i 1
i wxi minimized?
The maximum
likelihood w is
the one that E(w)
w
minimizes
yi wxi
2
sum-of-
squares of i
residuals yi 2 xi yi w
2
x w i
2 2
i
We want to minimize a quadratic function of
w.
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 7
Linear Regression
Easy to show the sum
of squares is
minimized when
w
xy i i
x
2
i
w
xy i i w
x
2
i Note: In Bayesian stats you’d
Out x wx
w
model is
And predictions would have given a
prob dist of expected output
We can use it for
Often useful to know your
prediction
confidence. Max likelihood can
.4
6.
2-d input
.
5 example
.8
x2 .
10
x1
Dataset has form
x1 y1
x2 y2
x3 y3
.: :
IMPORTANT
(there are R datapoints. Each inputEXERCISE:
has m PROVE
components) IT !!!!!
R
XTY is an m-element vector: i’th elt x
k 1
ki k y
Statisticians and
Neural Net Folks all
agree on a simple
obvious hack.
½ ½ 4 y=
2 =1/2
1 1 1
y= =
2 1 1/4 1 1
=1/2
=
2 3 4 y=
2
0x= x= x= x=
3 2 1/4 0 1 2 3
th e
Assume yi ~ N ( wxi , ) i
2
W h
ML ?
at’s timate
E es
of w
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 16
MLE estimation with varying
noise
argmax log p ( y1 , y 2 ,..., y R | x 1 , x 2 ,..., x R , 2
1 , 2
2 ,..., 2
R , w)
R xi yi Trivial algebra
2
i 1 i
R xi2
2
i 1 i
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 17
This is Weighted Regression
• We are asking to minimize the weighted
sum of squares
y=
3 =
R
( yi wxi ) 2 2
argmin 2 y=
i 1 i 2 =1/2
w
y= =
1 1
=1/2
=
2
y=
0x= x= x= x=
0 1 2 3
1
where weight for i’th datapoint 2
i
is
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 18
Regression
R xki xkj
(WXTWX) is an m x m matrix: i,j’th elt is k 1 2
i
R
(WXTWY) is an m-element vector: i’th elt xki yk
k 1 2
i
½ ½ y=
2
1 2.5
y=
2 3 1
3 2 y=
0x= x= x= x=
3 3 0 1 2 3
h e
yi ~ N ( w xi , ) 2 t
h at’s timate
Assume W es
E
ML ?
of w
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 20
Non-linear MLE estimation
argmax log p( y , y ,..., y 1 2 R | x1 , x2 ,..., xR , , w)
w Assuming i.i.d. and
then plugging in
argmin y
R 2
equation for
i w xi Gaussian and
i 1 simplifying.
w
Setting
R
yi w xi dLL/dw equal
w such that 0 to zero
w x
i 1 i
argmin y
R 2
equation for
i w xi Gaussian and
i 1 simplifying.
w
Setting
R
yi w xi dLL/dw equal
w such that 0 to zero
w x
i 1 i
We’re down
the algebraic
toilet
u e ss
g
So hat we
w
Copyright © 2001, 2003, Andrew W. Moore do
Neural
?
Networks: Slide 22
Non-linear MLE estimation
argmax log p( y , y ,..., y 1 2 R | x1 , x2 ,..., xR , , w)
w Assuming i.i.d. and
then plugging in
argmin
R
Common (but not only) approach: 2
equation for
Numerical Solutions:
yi w xi Gaussian and
i 1 simplifying.
• Line Search w
• Simulated Annealing R Setting
yi w xi dLL/dw equal
w such that
• Gradient Descent
w xi
0 to zero
• Conjugate Gradient i 1
• Levenberg Marquart
• Newton’s Method We’re down
the algebraic
Also, special purpose statistical- toilet
optimization-specific tricks such ss
g u e
So hat we
as E.M. (See Gaussian Mixtures
lecture for introduction) w
Copyright © 2001, 2003, Andrew W. Moore do
Neural
?
Networks: Slide 23
GRADIENT DESCENT
f(w) :
Suppose we have a scalar function
Out(x) = wTx
Outxk yk
2
w xk yk 2
Gradient descent
tells us we should
update w thusly if we
wish to minimize E:
E
wj wj - η
w j
E
So what’s ?
w j
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 29
Rule
R
E R
E ( yk w T x k ) 2 ( yk w T x k ) 2
k 1
w j k 1 w j
Gradient descent
R
2( yk w T x k ) ( yk w T x k )
tells us we should k 1 w j
update w thusly if we T
R
wish to minimize E: 2 δk w xk
k 1 w j
E …where…
wj wj - η δk y k w T x k
w j R
m
2 δk w x i ki
k 1 w j i 1
E
So what’s ? R
w j 2 δk xkj
k 1
Gradient descent
tells us we should
update w thusly if we
wish to minimize E:
E R
wj wj - η
…where…
w j w j w j 2η δk xkj
k 1
E R
2 δk xkj
w j k 1
We frequently neglect the 2
(meaning we halve the learning
rate)
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 31
algorithm
1) Randomly initialize weights w1 w2 … wm
3) for i = 1 to R i : yi w xi
for j = 1 to m w w R x
4)
j j i ij i 1
ru le
ule H off
MS
R
i d row
L e W
The T h
The delta
rule
Th
ea
da
lin
er
Classical ule
conditioning
observe (x,y)
y w x
j w j w j η δ x j
or
or
Blue =
We can do a linear fit. Out(x)
Our prediction is 0 if out(x)≤½
1 if out(x)>½
WHAT’S THE BIG PROBLEM WITH THIS???
or
Blue =
We can do a linear fit. Out(x)
Green =
Our prediction is 0 if out(x)≤½
Classification
1 if out(x)>½
i.e. g(h)=1-g(-h)
R R
y Out ( x i ) yi g ( w x i )
2 2
i
i 1 i 1
X1
X2
• Can learn the function x1 x2 .
X1
• Can learn any conjunction of literals, e.g.
x1 ~x2 ~x3 x4 x5
QUESTION: WHY?
Use a wider
representation !
Out(x) g W j g w jk x jk This is a nonlinear function
j k
Of a linear combination
Of non linear functions
Of linear combinations of inputs
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 51
A 1-HIDDEN LAYER NET
NINPUTS = 2 NHIDDEN = 3
N INS
w11
v1 g w1k xk
k 1 w1
x1 w21
w31
N INS
v2 g w2 k xk w2 N HID
Out g Wk vk
w12 k 1 k 1
w22
x2 w3
w32
N INS
v3 g w3k xk
k 1
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 52
OTHER NEURAL NETS
1
x1
x2
x3
2-Hidden layers + Constant Term
“JUMP” CONNECTIONS
x1
x2 N INS N HID
Out g w0 k xk Wk vk
k 1 k 1
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 53
Backpropagation
Out(x) g W j g w jk xk
j k
Find a set of weights {W j },{w jk }
to minimize
y Outx
2
i i
i
by gradient descent.
That’s
That’s it!
it!
That’s
That’s the
the
backpropagation
backpropagation
algorithm.
algorithm.
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 54
Convergence
Convergence to a global minimum is not
guaranteed.
•In practice, this is not a problem, apparently.
IfBwe neglect
UT (a the O(h 3
) terms, this is a quadratic
form nd it’s
That a bi g
seco but)… 2 E 1 E
expe nd d
nsive erivwa w 2
and t i ve m w w
If w e fiddl atrix
’re n y to co can b
boThis o
wl, wshouldt alrsend e
mputo the global
e’ll g e a us
dy i n directly t e. minimum
o nu is trulythquadratic.
if the function e qu
ts. adra
tic
And it might get us close if it’s locally quadraticish
Copyright © 2001, 2003, Andrew W. Moore Neural Networks: Slide 62
Improving Simple Gradient
Descent
Conjugate Gradient
Another method which attempts to exploit the
“local quadratic bowl” assumption
E
But does so while only needing to use
w
2
and not E
w 2
• Multilayer nets
The idea behind back prop
Awareness of better minimization methods