cs444 nathan sprague james madison universityneurons neurons communicate using discrete electrical...

14
Linear Regression, Neural Networks, etc. CS444 Nathan Sprague James Madison University

Upload: others

Post on 05-Oct-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Linear Regression, Neural Networks, etc.

CS444Nathan Sprague

James Madison University

Page 2: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Neurons● Neurons communicate using

discrete electrical signals called “spikes” (or action potentials).– Spikes travel along axons.– Reach axon terminals.– Terminals release

neurotransmitters.– Postsynaptic neurons

respond by allowing current to flow in (or out).

– If voltage crosses a threshold a spike is created

Creative Commons by­nc­sa 3.0 

Beginning Psychology (v. 1.0).

http://2012books.lardbucket.org/books/beginning­psychology/

Page 3: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Multivariate Linear Regression

● Multi-dimensional input vectors:

● Or:

h(x)

xn

w1

1

w0

h(x1 , x2 , ... , x n)=w0+w1 x1+...+wn x n

h (x)=wT x

x1

wn

...

Page 4: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Linear Regression – The Neural View

● input = x, desired output = y, weight = w.● h(x) = wx

● We are given a set of inputs, and a corresponding set of outputs, and we need to choose w.

● What's going on geometrically?

h(x)

x

w

Page 5: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Lines

x

y

● h(x) = wx is the equation of a line with a y intercept of 0.

● What is the best value of w? ● How do we find it?

Page 6: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Bias Weights

● We need to use the general equation for a line: h(x) = w

1x + w

0

● This corresponds to a new neural network with one additional weight, and an input fixed at 1.

h(x)

x

w1

1

w0

Page 7: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Error Metric

● Sum squared error (y is the desired output):

● The goal is to find a w that minimizes E. How?

ErrorE=∑e∈E

12(ye−h(xe))

2

Page 8: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Gradient Descent

http://en.wikipedia.org/wiki/File:Glacier_park1.jpg

Attribution-Share Alike 3.0 Unported

Page 9: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Gradient Descent

● One possible approach (maximization):1)take the derivative of the function: f'(w)2)guess a value of w : 3)move a little bit according to the derivative:

4)goto 3, repeat.

w← w+η f ' (w)

ww

Page 10: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Partial Derivatives

● Derivative of a function of multiple variables, with all but the variable of interest held constant.

f x , y =x2xy2

fx x , y=2xy2

∂ f x , y

∂ x=2xy2

fy x , y =2xy

∂ f x , y

∂ y=2xy

OROR

Page 11: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Gradient

● The gradient is just the generalization of the derivative to multiple dimensions.

● Gradient descent update:

∇ f w=[∂ f w

∂w1

∂ f w

∂w2

∂ f w

∂ wn

]w← w−η∇ f (w)

Page 12: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Gradient Descent for MVLR

● Error for the multi-dimensional case:

● The new update rule:

● Vector version:

∂ Error E (w)

∂ wi

=∑e∈E

(ye−wT xe)(−xe , i)

=−∑e∈E

(ye−wT x) xe , i

ErrorE (w)=∑e∈E

12( ye−wT xe)

2

wi←wi+η∑e∈E

(ye−wT x) xe , i

w←w+η∑e∈E

(ye−wT x) xe

Page 13: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Analytical Solution

● Where X is a matrix with one input per row, y the vector of target values.

w=(X T X )−1 XT y

Page 14: CS444 Nathan Sprague James Madison UniversityNeurons Neurons communicate using discrete electrical signals called “spikes” (or action potentials). – Spikes travel along axons

Notice that we get Polynomial Regression for Free

y=w1 x2+w2 x+w0