CS 4700 Foundations of Artificial Intelligence Prof Carla

  • Slides: 40
Download presentation
CS 4700: Foundations of Artificial Intelligence Prof. Carla P. Gomes gomes@cs. cornell. edu Module:

CS 4700: Foundations of Artificial Intelligence Prof. Carla P. Gomes gomes@cs. cornell. edu Module: Perceptron Learning (Reading: Chapter 20. 5) Carla P. Gomes CS 4700

Perceptron Cornell Aeronautical Laboratory Perceptron – Invented by Frank Rosenblatt in 1957 in an

Perceptron Cornell Aeronautical Laboratory Perceptron – Invented by Frank Rosenblatt in 1957 in an attempt to understand human memory, learning, and cognitive processes. – The first neural network model by computation, with a remarkable learning algorithm: • If function can be represented by perceptron, the learning algorithm is guaranteed to quickly converge to the hidden function! Rosenblatt & Mark I Perceptron: the first machine that could "learn" to recognize and identify optical patterns. – Became the foundation of pattern recognition research One of the earliest and most influential neural networks: An important milestone in AI. Carla P. Gomes CS 4700

Perceptron ROSENBLATT, Frank. (Cornell Aeronautical Laboratory at Cornell University ) The Perceptron: A Probabilistic

Perceptron ROSENBLATT, Frank. (Cornell Aeronautical Laboratory at Cornell University ) The Perceptron: A Probabilistic Model for Information Storage and Organization in the Brain. In, Psychological Review, Vol. 65, No. 6, pp. 386408, November, 1958. Carla P. Gomes CS 4700

Single Layer Feed-forward Neural Networks Perceptrons Single-layer neural network (perceptron network) A network with

Single Layer Feed-forward Neural Networks Perceptrons Single-layer neural network (perceptron network) A network with all the inputs connected directly to the outputs –Output units all operate separately: no shared weights Since each output unit is independent of the others, we can limit our study to single output perceptrons. Carla P. Gomes CS 4700

Perceptron to Learn to Identify Digits (From Pat. Winston, MIT) Digit x 0 x

Perceptron to Learn to Identify Digits (From Pat. Winston, MIT) Digit x 0 x 1 x 2 x 3 x 4 x 5 x 6 0 0 1 1 1 9 1 1 1 0 Seven line segments 8 are enough to produce 7 all 10 digits 1 1 1 1 0 0 6 1 1 1 0 1 1 1 5 1 1 1 0 4 1 1 0 0 3 1 0 1 1 0 2 1 0 1 1 1 0 0 0 1 1 0 0 3 1 2 4 6 0 5 Carla P. Gomes CS 4700

Perceptron to Learn to Identify Digits (From Pat. Winston, MIT) Seven line segments are

Perceptron to Learn to Identify Digits (From Pat. Winston, MIT) Seven line segments are enough to produce all 10 digits 3 1 2 4 6 0 5 A vision system reports which of the seven segments in the display are on, therefore producing the inputs Carla P. Gomes for the perceptron. CS 4700

Perceptron to Learn to Identify Digit 0 Digit x 0 x 1 x 2

Perceptron to Learn to Identify Digit 0 Digit x 0 x 1 x 2 x 3 x 4 x 5 x 6 X 7 (fixed input) 0 Seven line segments are enough to produce all 10 digits 3 1 2 4 6 1 1 -1 0 0 0 1 1 1 When the input digit is 0, what’s the value of sum? Sum>0 output=1 Else output=0 0 5 0 A vision system reports which of the seven segments in the display are on, therefore producing the inputs for the perceptron.

Single Layer Feed-forward Neural Networks Perceptrons Two input perceptron unit with a sigmoid (logistics)

Single Layer Feed-forward Neural Networks Perceptrons Two input perceptron unit with a sigmoid (logistics) activation function: adjusting weights moves the location, orientation, and steepness of cliff Carla P. Gomes CS 4700

Perceptron Learning: Intuition Weight Update Input Ij (j=1, 2, …, n) Single output O:

Perceptron Learning: Intuition Weight Update Input Ij (j=1, 2, …, n) Single output O: target output, T. Consider some initial weights Define example error: Err = T – O Now just move weights in right direction! If the error is positive, then we need to increase O. Err >0 need to increase O; Err <0 need to decrease O; Each input unit j, contributes Wj Ij to total input: if Ij is positive, increasing Wj tends to increase O; if Ij is negative, decreasing Wj tends to increase O; So, use: is the learning Wj + Ij Err Perceptron Learning Rule (Rosenblatt 1960) rate.

Perceptron Learning: Simple Example Let’s consider an example (adapted from Patrick Wintson book, MIT)

Perceptron Learning: Simple Example Let’s consider an example (adapted from Patrick Wintson book, MIT) Framework and notation: 0/1 signals Input vector: Weight vector: x 0 = 1 and 0=-w 0, simulate threshold. O is output (0 or 1) (single output). Learning rate = 1. Threshold function: Carla P. Gomes CS 4700

Err = T – O Wj + Ij Err Set of examples, each example

Err = T – O Wj + Ij Err Set of examples, each example is a pair i. e. , an input vector and a label y (0 or 1). Perceptron Learning: Simple Example This procedure provably converges (polynomial number of steps) if the function is represented by a perceptron (i. e. , linearly separable) Learning procedure, called the “error correcting method” • Start with all zero weight vector. • Cycle (repeatedly) through examples and for each example do: – If perceptron is 0 while it should be 1, Intuitively correct, (e. g. , if output is 0 add the input vector to the weight vector but it should be 1, – If perceptron is 1 while it should be 0, the weights are subtract the input vector to the weight vector increased) ! Carla P. Gomes – Otherwise do nothing. CS 4700

Perceptron Learning: Simple Example Consider learning the logical OR function. Our examples are: Sample

Perceptron Learning: Simple Example Consider learning the logical OR function. Our examples are: Sample 1 2 3 4 x 0 1 1 x 1 0 0 1 1 x 2 0 1 label 0 1 1 1 Activation Function Carla P. Gomes CS 4700

Error correcting method If perceptron is 0 while it should be 1, add the

Error correcting method If perceptron is 0 while it should be 1, add the input vector to the weight vector If perceptron is 1 while it should be 0, subtract the input vector to the weight vector Otherwise do nothing. Perceptron Learning: Simple Example We’ll use a single perceptron with three inputs. We’ll start with all weights 0 W= <0, 0, 0> Example 1 I= < 1 0 0> label=0 W= <0, 0, 0> Perceptron (1 0+ 0 0 =0, S=0) output 0 it classifies it as 0, so correct, do nothing 1 I 0 w 0 I 1 w O 1 I 2 w 2 Example 2 I=<1 0 1> label=1 W= <0, 0, 0> Perceptron (1 0+ 0 0+ 1 0 = 0) output 0 it classifies it as 0, while it should be 1, so we add input to weights W = <0, 0, 0> + <1, 0, 1>= <1, 0, 1> Carla P. Gomes CS 4700

Example 3 I=<1 1 0> label=1 W= <1, 0, 1> Perceptron (1 0+ 0

Example 3 I=<1 1 0> label=1 W= <1, 0, 1> Perceptron (1 0+ 0 0 > 0) output = 1 it classifies it as 1, correct, do nothing W = <1, 0, 1> 1 I 0 w 0 I 1 w O 1 I 2 w 2 Example 4 I=<1 1 1> label=1 W= <1, 0, 1> Perceptron (1 0+ 1 0 > 0) output = 1 it classifies it as 1, correct, do nothing W = <1, 0, 1> Carla P. Gomes CS 4700

Error correcting method Perceptron Learning: Simple Example If perceptron is 0 while it should

Error correcting method Perceptron Learning: Simple Example If perceptron is 0 while it should be 1, add the input vector to the weight vector If perceptron is 1 while it should be 0, subtract the input vector from the weight vector Otherwise do nothing. Epoch 2, through the examples, W = <1, 0, 1>. 1 I 0 w 0 I 1 w O 1 Example 1 I = <1, 0, 0> label=0 W = <1, 0, 1> Perceptron (1 1+ 0 0+ 0 1 >0) output 1 I 2 w 2 it classifies it as 1, while it should be 0, so subtract input from weights W = <1, 0, 1> - <1, 0, 0> = <0, 0, 1> Example 2 I=<1 0 1> label=1 W= <0, 0, 1> Perceptron (1 0+ 0 0+ 1 1 > 0) output 1 it classifies it as 1, so correct, do nothing Carla P. Gomes CS 4700

Example 3 I=<1 1 0> label=1 W= <0, 0, 1> Perceptron (1 0+ 0

Example 3 I=<1 1 0> label=1 W= <0, 0, 1> Perceptron (1 0+ 0 1 > 0) output = 0 it classifies it as 0, while it should be 1, so add input to weights W = <0, 0, 1> + W = <1, 1, 0> = <1, 1, 1> Example 4 I=<1 1 1> label=1 W= <1, 1, 1> Perceptron (1 1+ 1 1 > 0) output = 1 it classifies it as 1, correct, do nothing W = <1, 1, 1> Carla P. Gomes CS 4700

Perceptron Learning: Simple Example Epoch 3, through the examples, W = <1, 1, 1>.

Perceptron Learning: Simple Example Epoch 3, through the examples, W = <1, 1, 1>. 1 I 0 w 0 I 1 w O 1 Example 1 I=<1, 0, 0> label=0 W = <1, 1, 1> Perceptron (1 1+ 0 1 >0) output 1 I 2 w 2 it classifies it as 1, while it should be 0, so subtract input from weights W = <1, 1, 1> - W = <1, 0, 0> = <0, 1, 1> Example 2 I=<1 0 1> label=1 W= <0, 1, 1> Perceptron (1 0+ 0 1+ 1 1 > 0) output 1 it classifies it as 1, so correct, do nothing Carla P. Gomes CS 4700

Example 3 I=<1 1 0> label=1 W= <0, 1, 1> Perceptron (1 0+ 1

Example 3 I=<1 1 0> label=1 W= <0, 1, 1> Perceptron (1 0+ 1 1+ 0 1 > 0) output = 1 it classifies it as 1, correct, do nothing Example 4 I=<1 1 1> label=1 W= <0, 1, 1> Perceptron (1 0+ 1 1 > 0) output = 1 it classifies it as 1, correct, do nothing W = <1, 1, 1> Carla P. Gomes CS 4700

Perceptron Learning: Simple Example Epoch 4, through the examples, W= <0, 1, 1>. Example

Perceptron Learning: Simple Example Epoch 4, through the examples, W= <0, 1, 1>. Example 1 I= <1, 0, 0> label=0 W = <0, 1, 1> Perceptron (1 0+ 0 1 = 0) output 0 it classifies it as 0, so correct, do nothing So the final weight vector W= <0, 1, 1> classifies all examples correctly, and the perceptron has learned the function! Aside: in more realistic cases the bias (W 0) will not be 0. (This was just a toy example!) Also, in general, many more inputs (100 to 1000) 1 I 0 W 0 =0 I 1 W 1=1 O I 2 W 2=1 OR Carla P. Gomes CS 4700

Epoch x 1 x 2 Desired Target w 0 w 1 w 2 Output

Epoch x 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 1 example 1 1 0 0 0 1 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 0 1 1 -1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 -1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 1 2 3 4 x 0

Epoch x 1 x 2 Desired Target w 0 w 1 w 2 Output

Epoch x 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 0 0 0 1 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 0 1 1 -1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 -1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 1 x 0 1 example 1 1 example 2 2 3 4

Epoch x 0 1 example 1 1 2 3 4 x 1 x 2

Epoch x 0 1 example 1 1 2 3 4 x 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 0 0 0 example 2 1 0 1 1 0 1 example 3 1 1 0 1 1 0 1 1 0 0 0 1 1 -1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 -1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 1

Epoch x 0 1 example 1 1 2 3 4 x 1 x 2

Epoch x 0 1 example 1 1 2 3 4 x 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 0 0 0 example 2 1 0 1 1 0 1 example 3 1 1 0 1 example 4 1 1 1 0 0 0 1 1 -1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 -1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 1

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 0 0 0 example 2 1 0 1 1 0 1 example 3 1 1 0 1 example 4 1 1 1 0 1 0 1 2 example 1 1 0 0 0 1 1 -1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 -1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 1 3 4

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 0 0 0 example 2 1 0 1 1 0 1 example 3 1 1 0 1 example 4 1 1 1 0 1 0 1 2 example 1 1 0 0 0 1 1 -1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 -1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 1 example 2 3 4

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 0 0 0 example 2 1 0 1 1 0 1 example 3 1 1 0 1 example 4 1 1 1 0 1 0 1 2 example 1 1 0 0 0 1 1 -1 0 0 1 3 4 example 2 1 0 1 1 0 0 0 1 example 3 1 1 0 0 1 1 1 1 0 1 1 0 0 0 1 1 -1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 1

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 0 0 0 example 2 1 0 1 1 0 1 example 3 1 1 0 1 example 4 1 1 1 0 1 0 1 2 example 1 1 0 0 0 1 1 -1 0 0 1 3 4 example 2 1 0 1 1 0 0 0 1 example 3 1 1 0 0 1 1 1 1 example 4 1 1 1 1 0 0 0 1 1 -1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 1

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 0 0 0 example 2 1 0 1 1 0 1 example 3 1 1 0 1 example 4 1 1 1 0 1 0 1 2 example 1 1 0 0 0 1 1 -1 0 0 1 example 2 1 0 1 1 0 0 0 1 example 3 1 1 0 0 1 1 1 1 example 4 1 1 1 1 0 1 1 1 3 example 1 1 0 0 0 1 1 -1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 1 4

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 0 0 0 example 2 1 0 1 1 0 1 example 3 1 1 0 1 example 4 1 1 1 0 1 0 1 2 example 1 1 0 0 0 1 1 -1 0 0 1 example 2 1 0 1 1 0 0 0 1 example 3 1 1 0 0 1 1 1 1 example 4 1 1 1 1 0 1 1 1 3 example 1 1 0 0 0 1 1 -1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 0 0 1 1 example 2 4

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 0 0 0 example 2 1 0 1 1 0 1 example 3 1 1 0 1 example 4 1 1 1 0 1 0 1 2 example 1 1 0 0 0 1 1 -1 0 0 1 example 2 1 0 1 1 0 0 0 1 example 3 1 1 0 0 1 1 1 1 example 4 1 1 1 1 0 1 1 1 3 example 1 1 0 0 0 1 1 -1 0 1 1 1 0 0 1 1 example 3 1 1 0 1 1 1 0 1 1 1 0 0 0 0 1 1 4 example 2

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 0 0 0 example 2 1 0 1 1 0 1 example 3 1 1 0 1 example 4 1 1 1 0 1 0 1 2 example 1 1 0 0 0 1 1 -1 0 0 1 example 2 1 0 1 1 0 0 0 1 example 3 1 1 0 0 1 1 1 1 example 4 1 1 1 1 0 1 1 1 3 example 1 1 0 0 0 1 1 -1 0 1 1 example 2 1 0 1 1 1 0 0 1 1 example 3 1 1 0 1 1 1 0 0 1 1 example 4 1 1 0 1 1 1 0 0 0 0 1 1 4

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w

Epoch x 0 1 example 1 1 x 2 Desired Target w 0 w 1 w 2 Output Error New w 0 New w 1 New w 2 0 0 0 example 2 1 0 1 1 0 1 example 3 1 1 0 1 example 4 1 1 1 0 1 0 1 2 example 1 1 0 0 0 1 1 -1 0 0 1 example 2 1 0 1 1 0 0 0 1 example 3 1 1 0 0 1 1 1 1 example 4 1 1 1 1 0 1 1 1 3 example 1 1 0 0 0 1 1 -1 0 1 1 example 2 1 0 1 1 1 0 0 1 1 example 3 1 1 0 1 1 1 0 0 1 1 example 4 1 1 0 1 1 1 0 0 1 1 4 example 1 1 0 0 0 1 1

Derivation of a learning rule for Perceptrons Minimizing Squared Errors Threshold perceptrons have some

Derivation of a learning rule for Perceptrons Minimizing Squared Errors Threshold perceptrons have some advantages , in particular Simple learning algorithm that fits a threshold perceptron to any linearly separable training set. Key idea: Learn by adjusting weights to reduce error on training set. update weights repeatedly (epochs) for each example. We’ll use: Sum of squared errors (e. g. , used in linear regression), classical error measure Learning is an optimization search problem in weight space. Carla P. Gomes CS 4700

Derivation of a learning rule for Perceptrons Minimizing Squared Errors Let S = {(xi,

Derivation of a learning rule for Perceptrons Minimizing Squared Errors Let S = {(xi, yi): i = 1, 2, . . . , m} be a training set. (Note, x is a vector of inputs, and y is the vector of the true outputs. ) Let hw be the perceptron classifier represented by the weight vector w. Definition: Carla P. Gomes CS 4700

Derivation of a learning rule for Perceptrons Minimizing Squared Errors The squared error for

Derivation of a learning rule for Perceptrons Minimizing Squared Errors The squared error for a single training example with input x and true output y is: Where hw (x) is the output of the perceptron on the example and y is the true output value. We can use the gradient descent to reduce the squared error by calculating the partial derivatives of E with respect to each weight. Note: g’(in) derivative of the activation function. For sigmoid g’=g(1 -g). For threshold perceptrons, Carla P. Gomes Where g’(n) is undefined, the original perceptron rule simply omitted it. CS 4700

Gradient descent algorithm we want to reduce , E, for each weight wi ,

Gradient descent algorithm we want to reduce , E, for each weight wi , change weight in direction of steepest descent: learning rate Wj + Ij Err Intuitively: Err = y – h. W(x) positive output is too small weights are increased for positive inputs and decreased for negative inputs. Err = y – h. W(x) negative opposite Carla P. Gomes CS 4700

Perceptron Learning: Intuition Rule is intuitively correct! Greedy Search: Gradient descent through weight space!

Perceptron Learning: Intuition Rule is intuitively correct! Greedy Search: Gradient descent through weight space! Surprising proof of convergence: Weight space has no local minima! With enough examples, it will find the target function! (provide not too large) Carla P. Gomes CS 4700

Gradient descent in weight space From T. M. Mitchell, Machine Learning Carla P. Gomes

Gradient descent in weight space From T. M. Mitchell, Machine Learning Carla P. Gomes CS 4700

Perceptron learning rule: 1. Start with random weights, w = (w 1, w 2,

Perceptron learning rule: 1. Start with random weights, w = (w 1, w 2, . . . , wn). Wj + Ij Err Select a training example (x, y) S. 3. Run the perceptron with input x and weights w to obtain g 4. Let be the training rate (a user-set parameter). 5. Go to 2. Epochs are repeated until some stopping criterion is reached— typically, that the weight changes have become very small. The stochastic gradient method selects examples randomly from the training set rather than cycling through them. Epoch cycle through the examples 2.

Perceptron Learning: Gradient Descent Learning Algorithm Carla P. Gomes CS 4700

Perceptron Learning: Gradient Descent Learning Algorithm Carla P. Gomes CS 4700