Lecture 5: Logistic Regression. Neural Networks

Similar documents
Lecture 4: Types of errors. Bayesian regression models. Logistic regression

Lecture 5: Linear models for classification. Logistic regression. Gradient Descent. Second-order methods.

Artificial Neural Networks

COMP 551 Applied Machine Learning Lecture 14: Neural Networks

Need for Deep Networks Perceptron. Can only model linear functions. Kernel Machines. Non-linearity provided by kernels

100 inference steps doesn't seem like enough. Many neuron-like threshold switching units. Many weighted interconnections among units

Artificial Neural Networks

Need for Deep Networks Perceptron. Can only model linear functions. Kernel Machines. Non-linearity provided by kernels

Neural networks. Chapter 19, Sections 1 5 1

Artificial Neural Networks

Neural networks. Chapter 20. Chapter 20 1

Neural networks. Chapter 20, Section 5 1

AI Programming CS F-20 Neural Networks

Machine Learning for Large-Scale Data Analysis and Decision Making A. Neural Networks Week #6

Artificial Neural Networks

Machine Learning

Neural Networks. Chapter 18, Section 7. TB Artificial Intelligence. Slides from AIMA 1/ 21

Neural Networks Learning the network: Backprop , Fall 2018 Lecture 4

Logistic Regression Review Fall 2012 Recitation. September 25, 2012 TA: Selen Uguroglu

CSC242: Intro to AI. Lecture 21

Reading Group on Deep Learning Session 1

Machine Learning. Neural Networks. Le Song. CSE6740/CS7641/ISYE6740, Fall Lecture 7, September 11, 2012 Based on slides from Eric Xing, CMU

Neural Networks and Deep Learning

Serious limitations of (single-layer) perceptrons: Cannot learn non-linearly separable tasks. Cannot approximate (learn) non-linear functions

Linear Models for Classification

Data Mining Part 5. Prediction

Lecture 4: Perceptrons and Multilayer Perceptrons

Regression with Numerical Optimization. Logistic

Machine Learning

COMP-4360 Machine Learning Neural Networks

The error-backpropagation algorithm is one of the most important and widely used (and some would say wildly used) learning techniques for neural

Machine Learning. Lecture 04: Logistic and Softmax Regression. Nevin L. Zhang

Feed-forward Networks Network Training Error Backpropagation Applications. Neural Networks. Oliver Schulte - CMPT 726. Bishop PRML Ch.

Neural Networks biological neuron artificial neuron 1

CSC 411 Lecture 10: Neural Networks

Neural Nets Supervised learning

Neural Network Training

Mark Gales October y (x) x 1. x 2 y (x) Inputs. Outputs. x d. y (x) Second Output layer layer. layer.

Feedforward Neural Nets and Backpropagation

18.6 Regression and Classification with Linear Models

Introduction to Machine Learning

Comments. Assignment 3 code released. Thought questions 3 due this week. Mini-project: hopefully you have started. implement classification algorithms

Machine Learning and Data Mining. Multi-layer Perceptrons & Neural Networks: Basics. Prof. Alexander Ihler

Cheng Soon Ong & Christian Walder. Canberra February June 2018

CSC321 Lecture 5: Multilayer Perceptrons

CS:4420 Artificial Intelligence

Neural Networks. Nicholas Ruozzi University of Texas at Dallas

Speaker Representation and Verification Part II. by Vasileios Vasilakakis

Intelligent Systems Discriminative Learning, Neural Networks

Advanced statistical methods for data analysis Lecture 2

Course 395: Machine Learning - Lectures

Artificial Neural Networks. MGS Lecture 2

CSC321 Lecture 8: Optimization

Machine Learning Lecture 10

ARTIFICIAL INTELLIGENCE. Artificial Neural Networks

Learning Deep Architectures for AI. Part I - Vijay Chakilam

Advanced Machine Learning

Neural Networks. Bishop PRML Ch. 5. Alireza Ghane. Feed-forward Networks Network Training Error Backpropagation Applications

4. Multilayer Perceptrons

Back-Propagation Algorithm. Perceptron Gradient Descent Multilayered neural network Back-Propagation More on Back-Propagation Examples

Multiclass Logistic Regression

Midterm Review CS 6375: Machine Learning. Vibhav Gogate The University of Texas at Dallas

> DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE GRAVIS 2016 BASEL. Logistic Regression. Pattern Recognition 2016 Sandro Schönborn University of Basel

A summary of Deep Learning without Poor Local Minima

ECE521 Lectures 9 Fully Connected Neural Networks

Artificial Neural Networks 2

CSE 417T: Introduction to Machine Learning. Final Review. Henry Chai 12/4/18

Statistical Machine Learning (BE4M33SSU) Lecture 5: Artificial Neural Networks

CSCI567 Machine Learning (Fall 2018)

Machine Learning. Linear Models. Fabio Vandin October 10, 2017

Linear Classification. CSE 6363 Machine Learning Vassilis Athitsos Computer Science and Engineering Department University of Texas at Arlington

Midterm Review CS 7301: Advanced Machine Learning. Vibhav Gogate The University of Texas at Dallas

Linear discriminant functions

Neural Networks with Applications to Vision and Language. Feedforward Networks. Marco Kuhlmann

ECE521 Lecture7. Logistic Regression

Machine Learning Lecture 5

Neural Networks and the Back-propagation Algorithm

Computational statistics

Multilayer Perceptron

Logistic Regression & Neural Networks

Machine Learning. Neural Networks

Introduction to Neural Networks

The exam is closed book, closed notes except your one-page cheat sheet.

Machine Learning Basics III

Lecture 10. Neural networks and optimization. Machine Learning and Data Mining November Nando de Freitas UBC. Nonlinear Supervised Learning

Multilayer Neural Networks. (sometimes called Multilayer Perceptrons or MLPs)

MIDTERM: CS 6375 INSTRUCTOR: VIBHAV GOGATE October,

Engineering Part IIB: Module 4F10 Statistical Pattern Processing Lecture 5: Single Layer Perceptrons & Estimating Linear Classifiers

COMPUTATIONAL INTELLIGENCE (INTRODUCTION TO MACHINE LEARNING) SS16

Module 12. Machine Learning. Version 2 CSE IIT, Kharagpur

From perceptrons to word embeddings. Simon Šuster University of Groningen

Artificial Neuron (Perceptron)

Statistical Machine Learning from Data

Day 3 Lecture 3. Optimizing deep networks

Bias-Variance Tradeoff

Iterative Reweighted Least Squares

Case Study 1: Estimating Click Probabilities. Kakade Announcements: Project Proposals: due this Friday!

ARTIFICIAL NEURAL NETWORK PART I HANIEH BORHANAZAD

Midterm, Fall 2003

Transcription:

Lecture 5: Logistic Regression. Neural Networks Logistic regression Comparison with generative models Feed-forward neural networks Backpropagation Tricks for training neural networks COMP-652, Lecture 5 - September 21, 2009 1

Recall: Binary classification We are given a set of data x i, y i with y i {0, 1}. The probability of a given input x to have class y = 1 can be computed as: where P (y = 1 x) = a = ln P (x, y = 1) P (x) = P (x y = 1)P (y = 1) P (x y = 0)P (y = 0) 1 1 + exp( a) = σ(a) σ is the sigmoid function (also called squashing ) function a is the log-odds of the data being class 1 vs. class 0 COMP-652, Lecture 5 - September 21, 2009 2

Recall: Modelling for binary classification P (y = 1 x) = σ ( ln ) P (x y = 1)P (y = 1) P (x y = 0)P (y = 0) One approach is to model P (y) and P (x y), then use the approach above for classification (naive Bayes, Gaussian discriminants) This is called generative learning, because we can actually use the model to generate (i.e. fantasize) data Another idea is to model directly P (y x) This is called discriminative learning, because we only care about discriminating (i.e. separating) examples of the two classes. We focus on this approach today COMP-652, Lecture 5 - September 21, 2009 3

Error function Maximum likelihood classification assumes that we will find the hypothesis that maximizes the (log) likelihood of the training data: arg max h log P ( x i, y i i=1...m h) = arg max h n log P (x i,, y i ) h) i=1 (using the usual i.i.d. assumption) But if we use discriminative learning, we have no model of the input distribution Instead, we want to maximize the conditional probability of the labels, given the inputs: m arg max log P (y i x i, h) h i=1 COMP-652, Lecture 5 - September 21, 2009 4

The cross-entropy error function Suppose we interpret the output of the hypothesis, h(x i ), as the probability that y i = 1 Then the log-likelihood of a hypothesis h is: log L(h) = = m log P (y i x i, h) = i=1 m i=1 { log h(xi ) if y i = 1 log(1 h(x i )) if y i = 0 m y i log h(x i ) + (1 y i ) log(1 h(x i )) i=1 The cross-entropy error function is the opposite quantity: ( m ) J(h) = y i log h(x i ) + (1 y i ) log(1 h(x i )) i=1 COMP-652, Lecture 5 - September 21, 2009 5

Logistic regression Suppose we represent the hypothesis itself as a logistic function of a linear combination of inputs: h(x = 1 1 + exp(w T x) This is also known as a sigmoid neuron Suppose we interpret h(x) as P (y = 1 x) Then the log-odds ratio, ( ) P (y = 1 x) ln = w T x P (y = 0 x) which is linear (nice!) We can find the optimum weight by minimizing cross-entropy (maximizing the conditional likelihood of the data) COMP-652, Lecture 5 - September 21, 2009 6

Cross-entropy error surface for logistic function ( m ) J(h) = y i log σ(w T x i ) + (1 y i ) log(1 σ(w T x i )) i=1 Nice error surface, unique minimum, but cannot solve in closed form COMP-652, Lecture 5 - September 21, 2009 7

Maximization procedure: Gradient ascent First we compute the gradient of log L(w) wrt w: log L(w) = 1 y i h i w (x i ) h w(x i )(1 h w (x i ))x i 1 + (1 y i ) 1 h w (x i ) h w(x i )(1 h w (x i ))x i ( 1) = i x i (y i y i h w (x i ) h w (x i ) + y i h w (x i )) = i (y i h w (x i ))x i The update rule (because we maximize) is: m w w + α log L(w) = w + α (y i h w (x i ))x i where α (0, 1) is a step-size or learning rate parameter This is called logistic regression i=1 COMP-652, Lecture 5 - September 21, 2009 8

Another algorithm for optimization Recall Newton s method for finding the zero of a function g : R R At point w i, approximate the function by a straight line (its tangent) Solve the linear equation for where the tangent equals 0, and move the parameter to this point: w i+1 = w i g(wi ) g (w i ) COMP-652, Lecture 5 - September 21, 2009 9

Application to machine learning Suppose for simplicity that the error function J has only one parameter We want to optimize J, so we can apply Newton s method to find the zeros of J = d dw J We obtain the iteration: w i+1 = w i J (w i ) J (w i ) Note that there is no step size parameter! This is a second-order method, because it requires computing the second derivative But, if our error function is quadratic, this will find the global optimum in one step! COMP-652, Lecture 5 - September 21, 2009 10

Second-order methods: Multivariate setting If we have an error function J that depends on many variables, we can compute the Hessian matrix, which contains the second-order derivatives of J: H ij = 2 J w i w j The inverse of the Hessian gives the optimal learning rates The weights are updated as: w w H 1 w J This is also called Newton-Raphson method COMP-652, Lecture 5 - September 21, 2009 11

Which method is better? Newton s method usually requires significantly fewer iterations than gradient descent Computing the Hessian requires a batch of data, so there is no natural on-line algorithm Inverting the Hessian explicitly is expensive, necessary but almost never Computing the product of a Hessian with a vector can be done in linear time (Schraudolph, 1994) COMP-652, Lecture 5 - September 21, 2009 12

Newton-Raphson for logistic regression Leads to a nice algorithm called recursive least squares The Hessian has the form: H = Φ T RΦ where R is the diagonal matrix of h(x i )(1 h(x i )) The weight update becomes: w (Φ T RΦ) 1 Φ T R(Φw R 1 (Φw y) COMP-652, Lecture 5 - September 21, 2009 13

Logistic vs. Gaussian Discriminant Comprehensive study done by Ng and Jordan (2002) If the Gaussian assumption is correct, as expected, Gaussian discriminant is better If the assumption is violated, Gaussian discriminant suffers from bias (unlike logistic regression) In practice, Gaussian discriminant, tends to converge quicker to a less helpful solution Note that they optimize different error function! COMP-652, Lecture 5 - September 21, 2009 14

From neurons to networks Logistic regression can be used to learn linearly separable problems x 2 + x 2 + + - + - - - x 1 - + x 1 (a) If the instances are not linearly separable, the function cannot be learned correctly (e.g. XOR) One solution is to provide fixed, non-linear basis functions instead of inputs (like we did with linear regression) Today: learn such non-linear functions from data (b) COMP-652, Lecture 5 - September 21, 2009 15

Example: Logical functions of two variables 1.6 1.4 Sigmoid Unit for And Function mse-curve-0.1 mse-curve-0.01 mse-curve-0.5 2 1.8 1.6 xor-no-hidden 1.2 1.4 Mean Square Error 1 0.8 0.6 0.4 Squared Error 1.2 1 0.8 0.6 0.4 0.2 0.2 0 0 100 200 300 400 500 600 700 800 900 1000 Number of Epochs 0 0 2000 4000 6000 8000 10000 Number of epochs One sigmoid neuron can learn the AND function (left) but not the XOR function (right) In order to learn discrimination in data sets that are not linearly separable, we need networks of sigmoid units COMP-652, Lecture 5 - September 21, 2009 16

Example: A network representing the XOR function 1 0 w30 (-3.06) Input 1 1 (6.92) w31 3 w32 (6.91) w41 (4.5) (10.28) w51 w50 (-4.86) 5 Ouput 1 1.4 1.2 Learning Curve for XOR Function with 2-2-1 Architecture mse-curve Input 2 2 4 w42 (4.36) w40 (-6.8) w52 (-10.34) Squared Error 1 0.8 0.6 0.4 Input1 Input2 o3 o4 Ouput 1 0 0 0.04 0.001 0.011 0 1 0.98 0.08 0.99 0.2 0 0 500 1000 1500 2000 2500 3000 Number of Epochs 1 0 1 1 COMP-652, Lecture 5 - September 21, 2009 17

Feed-forward neural networks Hidden Layer 1 1 i Oi=Xji Input Layer Output Layer Wji Input 1 j... Input n... 1 A collection of units (neurons) with sigmoid or sigmoid-like activations, arranged in layers Layers 0 is the input layer, and its units just copy the inputs (by convention) The last layer, K, is called output layer, since its units provide the result of the network Layers 1,... K 1 are usually called hidden layers (their presence cannot be detected from outside the network) 1 COMP-652, Lecture 5 - September 21, 2009 18

Why this name? In feed-forward networks the outputs of units in layer k become inputs for units in layers with index > k There are no cross-connections between units in the same layer There are no backward ( recurrent ) connections from layers downstream Typically, units in layer k provide input only to units in layer k + 1 In fully connected networks, all units in layer k are connected to all units in layer k + 1 COMP-652, Lecture 5 - September 21, 2009 19

Notation Hidden Layer Input Layer 1 i Oi=Xji Wji 1 Output Layer Input 1 j... Input n... 1 1 w j,i is the weight on the connection from unit i to unit j By convention, x j,0 = 1, j The output of unit j, denoted o j, is computed using a sigmoid: o j = σ(w T j x j) where w j is the vector of weights on the connections entering unit j and x j is the vector of inputs to unit j By the definition of the connections, x j,i = o i COMP-652, Lecture 5 - September 21, 2009 20

Computing the output of the network Suppose that we want the network to make a prediction for instance x, y In a feed-forward network, this can be done in one forward pass: For layer k = 1 to K 1. Compute the output of all neurons in layer k: o j σ(w T j x j ), j Layer k 2. Copy these outputs as inputs to the next layer: x j,i o i, i Layer k, j Layer k + 1 COMP-652, Lecture 5 - September 21, 2009 21

Expressiveness of feed-forward neural networks A single sigmoid neuron has the same representational power as a perceptron: Boolean AND, OR, NOT, but not XOR Every Boolean function can be represented by a network with a single hidden layer, but might require a number of hidden units that is exponential in the number of inputs Every bounded continuous function can be approximated with arbitrary precision by a network with one, sufficiently large hidden layer [Cybenko 1989; Hornik et al. 1989] Any function can be approximated to arbitrary accuracy by a network with two hidden layers [Cybenko 1988]. COMP-652, Lecture 5 - September 21, 2009 22

Learning in feed-forward neural networks Usually, the network structure (units and interconnections) is specified by the designer The learning problem is finding a good set of weights The answer: gradient descent, because the form of the hypothesis formed by the network, h w, is Differentiable! Because of the choice of sigmoid units Very complex! Hence, direct computation of the optimal weights is not possible COMP-652, Lecture 5 - September 21, 2009 23

Backpropagation algorithm Just gradient descent over all weights in the network! We put together the two phases described above: 1. Forward pass: Compute the outputs of all units in the network, o k, k = N + 1,... N + H + 1, going in increasing order of the layers 2. Backward pass: Compute the δ k updates described before, going from k = N + H + 1 down to k = N + 1 (in decreasing order of the layers) 3. Update to all the weights in the network: w i,j w i,j + α i,j δ i x i,j For computing probabilities, drop the o(1 o) terms from the δ COMP-652, Lecture 5 - September 21, 2009 24

Backpropagation algorithm 1. Initialize all weights to small random numbers. 2. Repeat until satisfied: (a) Pick a training example (b) Input example to the network and compute the outputs o k (c) For each output unit k, δ k o k (1 o k )(y k o k ) (d) For each hidden unit l δ l o l (1 o l ) k outputs w lk δ k (e) Update each network weight: w ij w ij + α ij δ j x ij x ij is the input from unit i into unit j (for the output neurons, these are signals received from the hidden layer neurons) α ij is the learning rate or step size COMP-652, Lecture 5 - September 21, 2009 25

Backpropagation variations The previous version corresponds to incremental (stochastic) gradient descent An analogous batch version can be used as well: Loop through the training data, accumulating weight changes Update weights One pass through the data set is called epoch Algorithm can be easily generalized to predict probabilities, instead of minimizing sum-squared error Generalization is easy for other network structures as well. COMP-652, Lecture 5 - September 21, 2009 26

Convergence of backpropagation Backpropagation performs gradient descent over all the parameters in the network Hence, if the learning rate is appropriate, the algorithm is guaranteed to converge to a local minimum of the cost function NOT the global minimum Can be much worse than global minimum There can be MANY local minima (Auer et al, 1997) Partial solution: restarting = train multiple nets with different initial weights. In practice, quite often the solution found is very good COMP-652, Lecture 5 - September 21, 2009 27

Adding momentum On the t-th training sample, instead of the update: we do: w ij α ij δ j x ij w ij (t) α ij δ j x ij + β w ij (t 1) The second term is called momentum Advantages: Easy to pass small local minima Keeps the weights moving in areas where the error is flat Increases the speed where the gradient stays unchanged Disadvantages: COMP-652, Lecture 5 - September 21, 2009 28

With too much momentum, it can get out of a global maximum! One more parameter to tune, and more chances of divergence COMP-652, Lecture 5 - September 21, 2009 29

Choosing the learning rate Backprop is VERY sensitive to the choice of learning rate Too large divergence Too small VERY slow learning The learning rate also influences the ability to escape local optima Very often, different learning rates are used for units inn different layers It can be shown that each unit has its own optimal learning rate COMP-652, Lecture 5 - September 21, 2009 30

Adjusting the learning rate: Delta-bar-delta Heuristic method, works best in batch mode (though there have been attempts to make it incremental) The intuition: If the gradient direction is stable, the learning rate should be increased If the gradient flips to the opposite direction the learning rate should be decreased A running average of the gradient and a separate learning rate is kept for each weight If the new gradient and the old average have the same sign, increase the learning rate by a constant amount If they have opposite sign, decay the learning rate exponentially COMP-652, Lecture 5 - September 21, 2009 31

How large should the network be? Overfitting occurs if there are too many parameters compared to the amount of data available Choosing the number of hidden units: Too few hidden units do not allow the concept to be learned Too many lead to slow learning and overfitting If the n inputs are binary, log n is a good heuristic choice Choosing the number of layers Always start with one hidden layer Never go beyond 2 hidden layers, unless the task structure suggests something different COMP-652, Lecture 5 - September 21, 2009 32

Overtraining in feed-forward networks Error 0.01 0.009 0.008 0.007 0.006 0.005 0.004 0.003 0.002 Error versus weight updates (example 1) Training set error Validation set error 0 5000 10000 15000 20000 Number of weight updates Traditional overfitting is concerned with the number of parameters vs. the number of instances In neural networks there is an additional phenomenon called overtraining which occurs when weights take on large magnitudes, pushing the sigmoids into saturation Effectively, as learning progresses, the network has more actual parameters Use a validation set to decide when to stop training! COMP-652, Lecture 5 - September 21, 2009 33

Finding the right network structure Destructive methods start with a large network and then remove (prune) connections Constructive methods start with a small network (e.g. 1 hidden unit) and add units as required to reduce error COMP-652, Lecture 5 - September 21, 2009 34

Destructive methods Simple solution: consider removing each weight in turn (by setting it to 0), and examine the effect on the error Weight decay: give each weight a chance to go to 0, unless it is needed to decrease error: where λ is a decay rate Optimal brain damage: w j = α j J w j λw j Train the network to a local optimum Approximate the saliency of each link or unit (i.e., its impact on the performance of the network), using the Hessian matrix Greedily prune the element with the lowest saliency This loop is repeated until the error starts to deteriorate COMP-652, Lecture 5 - September 21, 2009 35

Constructive methods Dynamic node creation (Ash): Start with just one hidden unit, train using backprop If the error is still high, add another unit in the same layer and repeat Only one layer is constructed Meiosis networks (Hanson): Start with just one hidden unit, train using backprop Compute the variance of each weight during training If a unit has one or more weights of high variance, it is split into two units, and the weights are perturbed The intuition is that the new units will specialize to different functions. Cascade correlation: Add units to correlate with the residual error COMP-652, Lecture 5 - September 21, 2009 36

Example applications Speech phoneme recognition [Waibel] and synthesis [Nettalk] Image classification [Kanade, Baluja, Rowley] Digit recognition [Bengio, Bouttou, LeCun et al - LeNet] Financial prediction Learning control [Pomerleau et al] COMP-652, Lecture 5 - September 21, 2009 37

When to consider using neural networks Input is high-dimensional discrete or real-valued (e.g. raw sensor input) Output is discrete or real valued, or a vector of values Possibly noisy data Training time is not important Form of target function is unknown Human readability of result is not important The computation of the output based on the input has to be fast COMP-652, Lecture 5 - September 21, 2009 38