1 / 61

Classification with Perceptrons Reading:

This reading covers the basics of perceptrons and multilayer neural networks, focusing on Chapters 1-3 of Michael Nielsen's online book on neural networks. Learn about the structure of perceptrons, their activation functions, decision surfaces, and the Perceptron Learning algorithm.

timothyg
Download Presentation

Classification with Perceptrons Reading:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Classification with PerceptronsReading: Chapters 1-3 of Michael Nielsen's online book on neural networks covers the basics of perceptrons and multilayer neural networks.We will cover material in Chapters 1-2 only, but you’re encouraged to read Chapter 3 (and the rest of the book!) as well.

  2. Perceptrons as simplified “neurons” Inputs from connecting neurons Axon (output) Cell body Sum of weighted inputs Weighted inputs Output (0 or 1)

  3. Perceptrons as simplified “neurons” Input is (x1, x2, ... xn) Weights are (w1, w2, ... wn) Output y is 1 (“the neuron fires”) if the sum of the inputs times the weights is greater or equal to the threshold: input x1 x2 xn w1 w2 output . . . y wn

  4. Perceptrons as simplified “neurons” Input is (x1, x2, ... xn) Weights are (w1, w2, ... wn) Output y is 1 (“the neuron fires”) if the sum of the inputs times the weights is greater or equal to the threshold: input x1 x2 xn w1 w2 output . . . y wn

  5. Perceptrons as simplified “neurons” Input is (x1, x2, ... xn) Weights are (w1, w2, ... wn) Output y is 1 (“the neuron fires”) if the sum of the inputs times the weights is greater or equal to the threshold: input x1 x2 xn +1 w1 w0 w2 output . . . y wn

  6. Perceptrons as simplified “neurons” w0 is called the “bias” −w0is called the “threshold” Input is (x1, x2, ... xn) Weights are (w1, w2, ... wn) Output y is 1 (“the neuron fires”) if the sum of the inputs times the weights is greater or equal to the threshold: input x1 x2 xn +1 w1 w0 w2 output . . . y wn

  7. Perceptrons as simplified “neurons” w0 is called the “bias” −w0is called the “threshold” Input is (x1, x2, ... xn) Weights are (w1, w2, ... wn) Output y is 1 (“the neuron fires”) if the sum of the inputs times the weights is greater or equal to the threshold: input x1 x2 xn +1 w1 w0 w2 output . . . y wn

  8. Perceptrons as simplified “neurons” w0 is called the “bias” −w0is called the “threshold” Input is (x1, x2, ... xn) Weights are (w1, w2, ... wn) Output y is 1 (“the neuron fires”) if the sum of the inputs times the weights is greater or equal to the threshold: input x1 x2 xn +1 w1 w0 w2 output . . . y wn

  9. Perceptrons as simplified “neurons” w0 is called the “bias” −w0is called the “threshold” Input is (x1, x2, ... xn) Weights are (w1, w2, ... wn) Output y is 1 (“the neuron fires”) if the sum of the inputs times the weights is greater or equal to the threshold: input x0 x1 x2 xn +1 w1 w0 w2 output . . . y wn

  10. Perceptrons as simplified “neurons” w0 is called the “bias” −w0is called the “threshold” Input is (x1, x2, ... xn) Weights are (w1, w2, ... wn) Output y is 1 (“the neuron fires”) if the sum of the inputs times the weights is greater or equal to the threshold: input x0 x1 x2 xn +1 w1 w0 w2 output . . . y wn

  11. Perceptrons as simplified “neurons” w0 is called the “bias” −w0is called the “threshold” Input is (x1, x2, ... xn) Weights are (w1, w2, ... wn) Output y is 1 (“the neuron fires”) if the sum of the inputs times the weights is greater or equal to the threshold: input x0 x1 x2 xn +1 w1 w0 w2 output . . . y wn

  12. Perceptrons as simplified “neurons” w0 is called the “bias” −w0is called the “threshold” Input is (x1, x2, ... xn) Weights are (w1, w2, ... wn) Output y is 1 (“the neuron fires”) if the sum of the inputs times the weights is greater or equal to the threshold: input x0 x1 x2 xn +1 w1 w0 w2 output . . . y wn a is called an “activation function”

  13. Decision Surfaces • Assume data can be separated into two classes, positive and negative, by a linear decision surface. • Assuming data is n-dimensional, a perception represents a (n−1)-dimensional hyperplane that separates the data into two classes, positive (1) and negative (0).

  14. Feature 1 Feature 2

  15. Feature 2 Feature 1

  16. Feature 1 Feature 2

  17. Example where line won’t work? Feature 1 Feature 2

  18. Example • What is the output y? 1 −1 +1 .4 −.1 −.4 y

  19. Hyperplane Geometry of the perceptron In 2D: Feature 1 Feature 2

  20. Frank Rosenblatt https://blogs.umass.edu/comphon/2017/06/15/did-frank-rosenblatt-invent-deep-learning-in-1962/ The Mark I Perceptron

  21. “The Navy revealed the embryo of an electronic computer today that it expects will be able to walk, talk, see, write, reproduce itself, and be conscious of its existence.” — New York Times, July, 1958 Frank Rosenblatt https://blogs.umass.edu/comphon/2017/06/15/did-frank-rosenblatt-invent-deep-learning-in-1962/ The Mark I Perceptron

  22. input Perceptron Learning x0 +1 w0 x1 x2 xn w1 output w2 . . . y wn

  23. input Perceptron Learning x0 +1 w0 x1 x2 xn w1 output w2 . . . y Input instance: xk = (x1, x2, ... xn), with target class wn

  24. input Perceptron Learning x0 Goal is to use the training data to learn a set of weights that will: (1) correctly classify the training data (2) generalize to unseen data +1 w0 x1 x2 xn w1 output w2 . . . y Input instance: xk = (x1, x2, ... xn), with target class wn

  25. Perceptron Learning • Learning is often framed as an optimization problem: • Find wthat minimizes average “loss”: • where M is number of training examples and L is a “loss” function. • One part of the “art” of ML is to define a good loss function. • Here, define the loss function as follows:

  26. Example .4 +1 −.1 y Training set: ((0, 0), 1) (1, 1), 0) (1, 0), 0) What is the average loss for this training set, using the squared loss function? .2 x1 x2

  27. Perceptron Learning Goal of learning is to minimize J(w). How to solve this minimization problem? Gradient descent.

  28. “Batch” gradient descent J(w) • One epoch = one iteration through the training data. • After each epoch, compute average loss over the training set: • Change the weights to move in direction of steepest descent in the average-loss surface: w1 w2 From T. M. Mitchell, Machine Learning

  29. Gradient descent • To find direction of steepest descent, take the derivative of J(w) with respect to w. • A vector derivative is called a “gradient”: J(w)

  30. Here is how we change each weight: For i= 0 to n: and  is the learning rate (i.e., size of step to take downhill).

  31. Problem with true gradient descent: Training process is slow. Training process can land in local optimum. • Common approach to this: use stochastic gradient descent: • Instead of doing weight update after all training examples have been processed, do weight update after each training example has been processed (i.e., perceptron output has been calculated). • Stochastic gradient descent approximates true gradient descent increasingly well as  1/.

  32. Derivation of perceptron learning rule (stochastic gradient descent) 1 0 0 This is called the “perceptron learning rule”

  33. Perceptron Learning Algorithm Start with small random weights, w = (w0, w1, w2, ... , wn), e.g., . Repeat until accuracy on the training data stops increasing or for a maximum number of epochs (iterations through training set): For k = 1 to M (total number in training set): • Select next training example (xk, tk). • Run the perceptron with input xkand weights w to obtain y. • If y ≠tk , update weights: for i = 0, ..., n: ; Note that bias weight w0 is changed just like all other weights! • Go to 1.

  34. Example .4 +1 −.1 y Training set: ((0, 0), 1) (1, 1), 0) (1, 0), 0) Initial weights: {w0, w1,w2} = {0.4, −0.1, 0.2) What is initial accuracy? Apply perceptron learning rule for one epoch with η = 0.1 What is new accuracy? .2 x1 x2

  35. Recognizing Handwritten Digits • MNIST dataset • 60,000 training examples • 10,000 test examples Each example is a 28×28-pixel image, where each pixel is a grayscale value in [0,255]. See csv files. First value in each row is the target class. 28 pixels Label: “2” 28 pixels

  36. Architecture for handwritten digits classification:10 individual perceptrons bias input 1 Fully connected 785 inputs (= 28×28 + 1) Recognize: ‘0’

  37. Architecture for handwritten digits classification:10 individual perceptrons bias input 1 Fully connected 785 inputs (= 28×28 + 1) Recognize: ‘1’

  38. Architecture for handwritten digits classification:10 individual perceptrons bias input 1 Fully connected 785 inputs (= 28×28 + 1) Recognize: ‘2’

  39. Architecture for handwritten digits classification:10 individual perceptrons bias input 1 Fully connected 785 inputs (= 28×28 + 1) Recognize: ‘2’ Etc.

  40. Preprocessing(To keep weights from growing very large) Scale each feature to a fraction between 0 and 1:

  41. Perceptron ‘0’ Processing an input … For each perceptron, compute w‘0’ Perceptron ‘1’ … Input x w‘1’ Perceptron ‘2’ … w‘2’ Etc.

  42. Perceptron ‘0’ Processing an input … For each perceptron, compute w‘0’ Perceptron ‘1’ … Input x w‘1’ Perceptron ‘2’ … w‘2’ Etc.

  43. Perceptron ‘0’ Computing outputs … For each perceptron, if then output y = 1; otherwise y = 0. w‘0’ Perceptron ‘1’ … Input x w‘1’ Perceptron ‘2’ … w‘2’ Etc.

  44. Perceptron ‘0’ Computing outputs … For each perceptron, if then output y = 1; otherwise y = 0. w‘0’ y = 1 Perceptron ‘1’ … Input x w‘1’ y = 1 Perceptron ‘2’ … y = 0 w‘2’ Etc.

  45. Perceptron ‘0’ Computing targets … If input’s class corresponds to perceptron’s class, then target t = 1, otherwise target t = 0. For example, suppose xis a ‘2’. w‘0’ y = 1 Perceptron ‘1’ … Input x w‘1’ y = 1 Perceptron ‘2’ … y = 0 w‘2’ Etc.

  46. Perceptron ‘0’ Computing targets … If input’s class corresponds to perceptron’s class, then target t = 1, otherwise target t = 0. For example, suppose xis a ‘2’. w‘0’ y = 1, t = 0 Perceptron ‘1’ … Input x w‘1’ y = 1, t = 0 Perceptron ‘2’ … y = 0, t = 1 w‘2’ Etc.

  47. Perceptron ‘0’ Learning … Repeat for M epochs: w‘0’ y = 1, t = 0 Perceptron ‘1’ … Input x w‘1’ y = 1, t = 0 Perceptron ‘2’ … y = 0, t = 1 w‘2’ Etc.

  48. Perceptron ‘0’ Learning … Repeat for M epochs: For each training example x: w‘0’ y = 1, t = 0 Perceptron ‘1’ … Input x w‘1’ y = 1, t = 0 Perceptron ‘2’ … y = 0, t = 1 w‘2’ Etc.

  49. Perceptron ‘0’ Learning … Repeat for M epochs: For each training example x: In each perceptron, adjust all weights, including bias weight, according to perceptron learning rule: If t = y, weights do not change. w‘0’ y = 1, t = 0 Perceptron ‘1’ … Input x w‘1’ y = 1, t = 0 Perceptron ‘2’ … y = 0, t = 1 w‘2’ Etc.

  50. Perceptron ‘0’ Learning … Repeat for M epochs: For each training example x: In each perceptron, adjust all weights, including bias weight, according to perceptron learning rule: If t = y, weights do not change. Goal of learning: We want y =1 if perceptron corresponds to input; y = 0 for all other perceptrons. w‘0’ y = 1, t = 0 Perceptron ‘1’ … Input x w‘1’ y = 1, t = 0 Perceptron ‘2’ … y = 0, t = 1 w‘2’ Etc.

More Related