1 machine learning neural networks tomorrow no lesson! (will recover on wednesday 11, weka !!)

61
1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

Upload: shawn-hawkins

Post on 19-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

1

Machine LearningNeural Networks

Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

Page 2: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

2

Neural Networks

• Analogy to biological neural systems, the most robust learning systems we know.

• Attempt to understand natural biological systems through computational modeling.

• Massive parallelism allows for computational efficiency.

• Help understand “distributed” nature of neural representations (rather than “localist” representation) that allow robustness and graceful degradation.

• Intelligent behavior as an “emergent” property of large number of simple units rather than from explicitly encoded symbolic rules and algorithms.

Page 3: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

3

Neural Speed Constraints

• Neurons have a “switching time” on the order of a few milliseconds, compared to nanoseconds for current computing hardware.

• However, neural systems can perform complex cognitive tasks (vision, speech understanding) in tenths of a second.

• Only time for performing 100 serial steps in this time frame, compared to orders of magnitude more for current computers.

• Must be exploiting “massive parallelism.”• Human brain has about 1011 neurons with an

average of 104 connections each.

Page 4: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

4

Neural Network Learning

• Learning approach based on modeling adaptation in biological neural systems.

• Perceptron: Initial algorithm for learning simple neural networks (single layer) developed in the 1950’s.

• Backpropagation: More complex algorithm for learning multi-layer neural networks developed in the 1980’s.

Page 5: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

5

Real Neurons

• Cell structures– Cell body– Dendrites– Axon– Synaptic terminals

Page 6: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

6

Neural Communication

• Electrical potential across cell membrane exhibits spikes called action potentials.

• Spike originates in cell body, travels down axon, and causes synaptic terminals to release neurotransmitters.• Chemical diffuses across synapse to dendrites of other neurons.• Neurotransmitters can be excititory or inhibitory.• If net input of neurotransmitters to a neuron from other

neurons is excititory and exceeds some threshold, it fires an action potential.

Page 7: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

7

Real Neural Learning

• Synapses change size and strength with experience.

• Hebbian learning: When two connected neurons are firing at the same time, the strength of the synapse between them increases.

• “Neurons that fire together, wire together.”

Page 8: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

8

Artificial Neuron Model

• Model network as a graph with cells as nodes and synaptic connections as weighted edges from node i to node j, wji

• Model net input to cell as

• Cell output is:

1

32 54 6

w12

w13w14

w15

w16

ii

jij ownet

(Tj is threshold for unit j)

ji

jjj Tnet

Tneto

if 1

if 0

netj

oj

Tj

0

1

Page 9: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

Perceptron schema

9

o1

o2

on

ThresholdTj∑

netj

w1j

wnjoj

ji

jjj Tnet

Tneto

if 1

if 0

Perceptron training phase= estimating edge weights and threshold

Page 10: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

10

Perceptron Training

• Assume supervised training examples giving the desired output for a unit given a set of known input activations.

• Learn synaptic weights so that unit produces the correct output for each example.

• Perceptron uses iterative update algorithm to learn a correct set of weights.

Page 11: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

11

Perceptron Learning Rule

• Update weights by:

where η is a constant named the “learning rate”

tj is the teacher specified output for unit j, (tj -oj) is the error in iteration t

• Equivalent to rules:– If output is correct do nothing.– If output is “high”, lower weights on active inputs– If output is “low”, increase weights on active inputs

• Also adjust threshold to compensate:

ji

jjj Tnet

Tneto

if 1

if 0

Page 12: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

12

Perceptron Learning Algorithm

• Iteratively update weights until convergence.

• Each execution of the outer loop is typically called an epoch.

Initialize weights to random valuesUntil outputs of all training examples are correct For each training pair, Ej <xj(o1,o2,on),tj>, do: Compute current output oj for Ej given its inputs Compare current output to target value, tj , for Ej Update synaptic weights and threshold using learning rule

Page 13: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

13

Perceptron as a Linear Separator

• Since perceptron uses linear threshold function, it is searching for a linear separator that discriminates the classes.

1313212 Towow

13

12

13

123 w

To

w

wo

o3

o2

??

Or hyperplane in n-dimensional space

w12 w13

1

32

Page 14: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

14

Concept Perceptron Cannot Learn

• Cannot learn exclusive-or, or parity function in general (not linearly separable!).

o3

o2

??+1

01

+–

Page 15: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

15

Perceptron Limits

• System obviously cannot learn concepts it cannot represent.

• Minksy and Papert (1969) wrote a book analyzing the perceptron and demonstrating many functions it could not learn.

• These results discouraged further research on neural nets; and symbolic AI became the dominate paradigm.

Page 16: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

16

Perceptron Convergence and Cycling Theorems

• Perceptron convergence theorem: If the data is linearly separable and therefore a set of weights exist that are consistent with the data, then the Perceptron algorithm will eventually converge to a consistent set of weights.

• Perceptron cycling theorem: If the data is not linearly separable, the Perceptron algorithm will eventually repeat a set of weights and threshold at the end of some epoch and therefore enter an infinite loop.– By checking for repeated weights+threshold, one can

guarantee termination with either a positive or negative result.

Page 17: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

17

Perceptron as Hill Climbing

• The hypothesis space being search is a set of weights and a threshold.

• Objective is to minimize classification error on the training set.

• Perceptron effectively does hill-climbing (gradient descent) in this space, changing the weights a small amount at each point to decrease training set error.

• For a single model neuron, the space is well behaved with a single minima.

weights0

trainingerror

Page 18: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

Example: Learn a NOR function

18

Page 19: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

19

Page 20: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

20

Page 21: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

21

Page 22: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

22

Page 23: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

23

Page 24: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

After 20 iterations

24

Page 25: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

25

Perceptron Performance

• In practice, converges fairly quickly for linearly separable data.

• Can effectively use even incompletely converged results when only a few outliers are misclassified.

• Experimentally, Perceptron does quite well on many benchmark data sets.

Page 26: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

26

Multi-Layer Networks

• Multi-layer networks can represent arbitrary functions• A typical multi-layer network consists of an input, hidden

and output layer, each fully connected to the next, with activation feeding forward.

• The weights determine the function computed. • Given an arbitrary number of hidden units, any boolean

function can be computed with a single hidden layer.

output

hidden

input

activation

Page 27: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

27

Hill-Climbing in Multi-Layer Nets

• Since “greed is good” perhaps hill-climbing can be used to learn multi-layer networks in practice although its theoretical limits are clear.

• However, to do gradient descent with multiple neurons, we need the output of a unit to be a differentiable function of its input and weights.

• Standard linear threshold function is not differentiable at the threshold.

netj

oi

Tj

0

1

trainingerror

weights

Page 28: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

28

Differentiable Output Function

• Need non-linear output function to move beyond linear functions.

– Standard solution is to use the non-linear, differentiable sigmoidal “logistic” function:

netjTj

0

1)(1

1jj Tnetj

eo

Can also use tanh or Gaussian output function

ii

jij ownet

Page 29: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

29

• Structure of a node:

Thresholding function limits node output (Tj=0 in the example):

thresholdthreshold

Page 30: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

30

Feeding data through the net

(1 0.25) + (0.5 (-1.5)) = 0.25 + (-0.75) = - 0.5

0.37751

15.0

ethresholding:

Page 31: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

31

Gradient Descent

• The objective is to minimize error:

where D is the set of training examples, K is the set of output units, tkd and okd are, respectively, the teacher and current output for unit k for example d.

• The derivative of a sigmoid unit with respect to net input is:

• Learning rule to change weights to minimize error is:

2)()( kdDd Kk

kd otWE

)1( jjj

j oonet

o

jiji w

Ew

)(1

1jj Tnetj

eo

Page 32: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

32

Backpropagation Learning Rule

• Each weight changed by:

where η is a constant called the learning rate

tj is the correct “teacher” output for unit j

δj is the error measure for unit j

ijji ow

unithidden a is if )1( jwook

kjkjjj

i joioj

wij

Page 33: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

Example for net1=w1x1+w2x2

x1 x2ji

ji w

Ew

33Se x1 è l’output del nodo precedente, cioè oi, abbiamo: ijji ow

Page 34: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

Example

nj

h2h1

oj

wj1wj2

n1 nj nN

……. …..…...Step 1: feed with first example

and compute all oj

x1: x11 x12…x1N

Page 35: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

Example (cont’d)

oj

wj1wj2

……. …..…...

Compute the error on the output node, and backpropagatecomputation on hidden nodes

Page 36: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

Example (cont’d)oj

wj1wj2

……. …..…...wh1n1 wh2n1

…and on input nodes

Page 37: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

Example (cont’d)

•Update all weights•Consider the second example

•Compute input and output in all nodes•Compute errors on outpus and on all nodes

•Re-update weights•Untill all examples have been considered (Epoch)

•Repeat for n Epochs, until convergence

Page 38: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

Another example (weight updates)

• Training set – ((0.1, 0.1), 0.1)

– ((0.1, 0.9), 0.9)

– ((0.9, 0.1), 0.9)

– ((0.9, 0.9), 0.1)

0,1

0,1

-0,1

-0,1-0,1

0,1

1

2

3

Initial weights

Page 39: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

1. Compute output and error on output node

First example:

((0.1, 0.1), 0.1)0,1

0,1

0,1

0,5

0,5

0,5

1

2

3

0,1

-0,1 -0,1

0,1

-0,1

0,1

Page 40: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

2. Backpropagate error

0,1

0,1

0,1

0,5

0,5

0,5

1

2

3

-0,1

-0,025

0,025

Page 41: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

3. Update weights

0,1

0,1

0,1

0,5

0,5

0,5

1

2

3

-0,1

-0,025

0,025

0,1

-0,1

-0,1

0,1

-0,1

0,1

Page 42: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

Read second input from D

2. ((0,1,0,9), 0,9)

0,1005

0,0995

-0,1005

-0,0995-0,11

0,09

1

2

3

0,1

0,9

0,90,48

0,52

0,501

..etc!!

Page 43: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

43

Yet another example

• First calculate error of output units and use this to change the top layer of weights.

output

hidden

input

Current output: oj=0.2Correct output: tj=1.0Error δj = oj(1–oj)(tj–oj) 0.2(1–0.2)(1–0.2)=0.128

Update weights into j

ijji ow

Page 44: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

44

Error Backpropagation

• Next calculate error for hidden units based on errors on the output units it feeds into.

output

hidden

input

k

kjkjjj woo )1(

Page 45: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

45

Error Backpropagation

• Finally update bottom layer of weights based on errors calculated for hidden units.

output

hidden

input

k

kjkjjj woo )1(

Update weights into j

ijji ow

Page 46: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

Example: Voice Recognition

• Task: Learn to discriminate between two different voices saying “Hello”

• Data – Sources

• Steve Simpson

• David Raubenheimer

– Format• Frequency distribution (60 bins)

• Analogy: cochlea

Page 47: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

• Network architecture– Feed forward network

• 60 input (one for each frequency bin)

• 6 hidden

• 2 output (0-1 for “Steve”, 1-0 for “David”)

Page 48: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

• Presenting the dataSteve

David

Page 49: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

• Presenting the data (untrained network)Steve

David

0.43

0.26

0.73

0.55

Page 50: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

• Calculate errorSteve

David

0.43 – 0 = 0.43

0.26 –1 = 0.74

0.73 – 1 = 0.27

0.55 – 0 = 0.55

Page 51: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

• Backprop error and adjust weightsSteve

David

0.43 – 0 = 0.43

0.26 – 1 = 0.74

0.73 – 1 = 0.27

0.55 – 0 = 0.55

1.17

0.82

Page 52: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

• Repeat process (sweep) for all training pairs– Present data– Calculate error– Backpropagate error– Adjust weights

• Repeat process multiple times

Page 53: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

• Presenting the data (trained network)Steve

David

0.01

0.99

0.99

0.01

Page 54: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

54

Backpropagation Training Algorithm

Create the 3-layer network with H hidden units with full connectivity between layers. Set weights to small random real values.Until all training examples produce the correct value (within ε), or mean squared error ceases to decrease, or other termination criteria: Begin epoch For each training example, d, do: Calculate network output for d’s input values Compute error between current output and correct output for d Update weights by backpropagating error and using learning rule End epoch

Page 55: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

55

Comments on Training Algorithm

• Not guaranteed to converge to zero training error, may converge to local optima or oscillate indefinitely.

• However, in practice, does converge to low error for many large networks on real data.

• Many epochs (thousands) may be required, hours or days of training for large networks.

• To avoid local-minima problems, run several trials starting with different random weights (random restarts).– Take results of trial with lowest training set error.– Build a committee of results from multiple trials

(possibly weighting votes by training set accuracy).

Page 56: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

56

Representational Power

• Boolean functions: Any boolean function can be represented by a two-layer network with sufficient hidden units.

• Continuous functions: Any bounded continuous function can be approximated with arbitrarily small error by a two-layer network.– Sigmoid functions can act as a set of basis functions for

composing more complex functions, like sine waves in Fourier analysis.

• Arbitrary function: Any function can be approximated to arbitrary accuracy by a three-layer network.

Page 57: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

57

Over-Training Prevention

• Running too many epochs can result in over-fitting.

• Keep a hold-out validation set and test accuracy on it after every epoch. Stop training when additional epochs actually increase validation error.

• To avoid losing training data for validation:– Use internal 10-fold CV on the training set to compute the average

number of epochs that maximizes generalization accuracy.– Train final network on complete training set for this many epochs.

erro

r

on training data

on test data

0 # training epochs

Page 58: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

58

Determining the Best Number of Hidden Units

• Too few hidden units prevents the network from adequately fitting the data.

• Too many hidden units can result in over-fitting.

• Use internal cross-validation to empirically determine an optimal number of hidden units.

erro

r

on training data

on test data

0 # hidden units

Page 59: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

59

Successful Applications

• Text to Speech (NetTalk)• Fraud detection• Financial Applications

– HNC (eventually bought by Fair Isaac)

• Chemical Plant Control– Pavillion Technologies

• Automated Vehicles• Game Playing

– Neurogammon

• Handwriting recognition

Page 60: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

60

Issues in Neural Nets

• More efficient training methods:– Quickprop– Conjugate gradient (exploits 2nd derivative)

• Learning the proper network architecture:– Grow network until able to fit data

• Cascade Correlation• Upstart

– Shrink large network until unable to fit data• Optimal Brain Damage

• Recurrent networks that use feedback and can learn finite state machines with “backpropagation through time.”

Page 61: 1 Machine Learning Neural Networks Tomorrow no lesson! (will recover on Wednesday 11, WEKA !!)

61

Issues in Neural Nets (cont.)

• More biologically plausible learning algorithms based on Hebbian learning.

• Unsupervised Learning– Self-Organizing Feature Maps (SOMs)

• Reinforcement Learning – Frequently used as function approximators for

learning value functions.

• Neuroevolution