ceng 783 on optimizationemre/resources/...softmax classifier –cross-entropy loss β€’...

Post on 14-Mar-2021

5 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CENG 793

On Machine Learning and Optimization

Sinan Kalkan

2

Now

β€’ Introduction to ML– Problem definition– Classes of approaches– K-NN– Support Vector Machines– Softmax classification / logistic regression– Parzen Windows

β€’ Optimization– Gradient Descent approaches– A flavor of other approaches

3

Introduction toMachine learning

Uses many figures and material from the following website:

http://www.byclb.com/TR/Tutorials/neural_networks/ch1_1.htm4

Testing

Training

Overview

β€œLearn”

LearnedModels or Classifiers

Data with label(label: human, animal etc.)

- Size- Texture- Color- Histogram of

oriented gradients- SIFT- Etc.

Test input

ExtractFeatures

ExtractFeatures

Pred

ict

Human or Animal or …

5

Content

β€’ Problem definition

β€’ General approaches

β€’ Popular methods

– kNN

– Linear classification

– Support Vector Machines

– Parzen windows

6

Problem Definition

β€’ Given – Data: a set of instances 𝐱1, 𝐱2, … , 𝐱𝑛

sampled from a space 𝐗 ∈ ℝ𝑑 .

– Labels: the corresponding labels 𝑦𝑖 for each 𝐱𝑖 . 𝑦𝑖 ∈ 𝐘 ∈ ℝ.

β€’ Goal: – Learn a mapping from the space of β€œdata”

to the space of labels, i.e.,

β€’ β„³:𝐗 β†’ 𝐘.

β€’ 𝑦 = 𝑓 𝐱 .

7

Issues in Machine Learning

β€’ Hypothesis space

β€’ Loss / cost / objective function

β€’ Optimization

β€’ Bias vs. variance

β€’ Test / evaluate

β€’ Overfitting, underfitting

8

GenerativeDiscriminative

General Approaches

Find separating line (in general: hyperplane)

Fit a function to data(regression).

Learn a model for each class.

9

Generative

β€’ Regressionβ€’ Markov Random Fieldsβ€’ Bayesian Networks/Learningβ€’ Clustering via Gaussian Mixture Models,

Parzen Windows etc.β€’ …

Discriminative

β€’ Support Vector Machinesβ€’ Artificial Neural Networksβ€’ Conditional Random Fieldsβ€’ K-NN

General Approaches (cont’d)

10

Supervised

Instance Label

elma

elma

armut

elma

armut

Unsupervised

General Approaches (cont’d)

Extract Features

Learn a model

Extract Features

Learn a model

e.g. SVM

e.g. k-meansclustering

11

General Approaches (cont’d)

Generative Discriminative

SupervisedRegression

Markov Random FieldsBayesian Networks

Support Vector MachinesNeural Networks

Conditional Random FieldsDecision Tree Learning

UnsupervisedGaussian Mixture Models

Parzen WindowsK-means

Self-Organizing Maps

12

Now

Generative Discriminative

Supervised

Unsupervised

Support VectorMachines

Parzen Windows

Softmax/Logistic Regression

14

Feature Space

17

General pitfalls/problems

β€’ Overfitting

β€’ Underfitting

β€’ Occams’ razor

18

21

K-NEAREST NEIGHBOR

22

A very simple algorithm

β€’ Advantages:– No training– Simple

β€’ Disadvantages:– Slow testing time (more efficient

versions exist)– Needs a lot of memory

Wikipedia

http://cs231n.github.io/classification/23

PARZEN WINDOWS

A non-parametric method

24

Probability and density

β€’ Probability of a continuous probability function, 𝑝 π‘₯ , satisfies the following:– Probability to be between two values:

𝑃 π‘Ž < π‘₯ < 𝑏 = π‘Ž

𝑏

𝑝 π‘₯ 𝑑π‘₯

– 𝑝 π‘₯ > 0 for all real π‘₯.– And

βˆ’βˆž

∞

𝑝 π‘₯ 𝑑π‘₯ = 1

β€’ In 2-D:– Probability for 𝐱 to be inside region 𝑅:

𝑃 = 𝑅

𝑝 𝐱 𝑑𝐱

– 𝑝 𝐱 > 0 for all real 𝐱.– And

βˆ’βˆž

∞

𝑝 𝐱 𝑑𝐱 = 1

26

Density Estimation

β€’ Basic idea:

𝑃 = 𝑅

𝑝 𝐱 𝑑𝐱

β€’ If 𝑅 is small enough, so that 𝑝(𝐱) is almost constant in 𝑅:

– 𝑃 = 𝑅 𝑝 𝐱 𝑑𝐱 β‰ˆ

p 𝐱 𝑅 𝑑𝐱 = 𝑝 𝐱 𝑉

– 𝑉: volume of region 𝑅.

β€’ If π‘˜ out of 𝑛 samples fall into 𝑅, then

𝑃 = π‘˜/𝑛

β€’ From which we can write:

π‘˜

𝑛= 𝑝 𝐱 𝑉 β‡’ 𝑝 𝐱 =

π‘˜/𝑛

𝑉27

Parzen Windows

β€’ Assume that: – 𝑅 is a hypercube centered at 𝐱.– β„Ž is the length of an edge of the hypercube.– Then, 𝑉 = β„Ž2 in 2D and 𝑉 = β„Ž3 in 3D etc.

β€’ Let us define the following window function:

𝑀𝐱𝑖 βˆ’ π±π‘˜

β„Ž=

1, |𝐱𝑖 βˆ’ π±π‘˜|/β„Ž < 1/20, otherwise

β€’ Then, we can write the number of samples falling into 𝑅 as follows:

π‘˜ =

𝑖=1

𝑛

𝑀𝐱𝑖 βˆ’ π±π‘˜

β„Ž28

Parzen Windows (cont’d)

β€’ Remember: 𝑝 𝐱 =π‘˜/𝑛

𝑉.

β€’ Using this definition of π‘˜, we can rewrite 𝑝(𝐱)(in 2D):

𝑝 𝐱 =1

𝑛

𝑖=1

𝑛1

β„Ž2𝑀

𝐱𝑖 βˆ’ 𝐱

β„Ž

β€’ Interpretation: Probability is the contribution of window functions fitted at each sample!

29

Parzen Windows (cont’d)

β€’ The type of the window function can add different flavors.

β€’ If we use Gaussian for the window function:

𝑝 𝐱 =1

𝑛

𝑖=1

𝑛1

𝜎√2πœ‹exp βˆ’

𝐱𝑖 βˆ’ 𝐱 𝟐

2𝜎2

β€’ Interpretation: Fit a Gaussian to each sample.

30

31

LINEAR CLASSIFICATION

32

Linear classificationβ€’ Linear classification relies on the following score function:

𝑓(π‘₯𝑖;π‘Š, 𝑏) = π‘Šπ‘₯𝑖 + 𝑏Or

𝑓(π‘₯𝑖;π‘Š, 𝑏) = π‘Šπ‘₯𝑖‒ where the bias is implicitly represented in π‘Š and π‘₯𝑖

http://cs231n.github.io/linear-classify/One row per class 33

Linear classification

β€’ We can rewrite the score function as:𝑓(π‘₯𝑖;π‘Š, 𝑏) = π‘Šπ‘₯𝑖

β€’ where the bias is implicitly represented in π‘Šand π‘₯𝑖

http://cs231n.github.io/linear-classify/34

Linear classification: One interpretation

β€’ Since an image can be thought as a vector, we can consider them as points in high-dimensional space.

http://cs231n.github.io/linear-classify/

One interpretation of:

𝑓(π‘₯𝑖;π‘Š, 𝑏) = π‘Šπ‘₯𝑖 + 𝑏

- Each row describes a line for a class, and β€œb”

35

Linear classification:Another interpretation

β€’ Each row in π‘Š can be interpreted as a template of that class.

– 𝑓(π‘₯𝑖;π‘Š, 𝑏) = π‘Šπ‘₯𝑖 + 𝑏 calculates the inner product to find which template best fits π‘₯𝑖.

– Effectively, we are doing Nearest Neighbor with the β€œprototype” images of each class.

http://cs231n.github.io/linear-classify/36

Loss functionβ€’ A function which measures how good our weights are.

– Other names: cost function, objective function

β€’ Let 𝑠𝑗 = 𝑓 π‘₯𝑖;π‘Š 𝑗

β€’ An example loss function:

𝐿𝑖 =

𝑗≠𝑦𝑖

max(0, 𝑠𝑗 βˆ’ 𝑠𝑦𝑖 + Ξ”)

Or equivalently:

𝐿𝑖 =

𝑗≠𝑦𝑖

max(0, 𝑀𝑗𝑇π‘₯𝑖 βˆ’ 𝑀𝑦𝑖

𝑇 π‘₯𝑖 + Ξ”)

β€’ This directs the distances to other classes to be more than Ξ” (the margin)

http://cs231n.github.io/linear-classify/37

Example

β€’ Consider our scores for π‘₯𝑖 to be 𝑠 =[13, βˆ’7,11] and assume Ξ” as 10.

β€’ Then, 𝐿𝑖 = max 0,βˆ’7 βˆ’ 13 + 10 +max(0,11 βˆ’ 13 + 10)

http://cs231n.github.io/linear-classify/ 38

Regularization

β€’ In practice, there are many possible solutions leading to the same loss value.– Based on the requirements of the problem, we

might want to penalize certain solutions.

β€’ E.g.,

𝑅 π‘Š =

𝑖

𝑗

π‘Šπ‘–,𝑗2

– which penalizes large weights. β€’ Why do we want to do that?

39http://cs231n.github.io/linear-classify/

Combined Loss Function

β€’ The loss function becomes:

β€’ If you expand it:

𝐿 =1

𝑁

𝑖

𝑗≠𝑦𝑖

max 0, 𝑓 π‘₯𝑖 ,π‘Š 𝑗 βˆ’ 𝑓 π‘₯𝑖 ,π‘Š 𝑦𝑖 + Ξ” + πœ†

𝑖

𝑗

π‘Šπ‘–,𝑗2

Hyper parameters(estimated using validation set)40http://cs231n.github.io/linear-classify/

Hinge Loss, or Max-Margin Loss

𝐿 =1

𝑁

𝑖

𝑗≠𝑦𝑖

max 0, 𝑓 π‘₯𝑖 ,π‘Š 𝑗 βˆ’ 𝑓 π‘₯𝑖 ,π‘Š 𝑦𝑖 + Ξ” + πœ†

𝑖

𝑗

π‘Šπ‘–,𝑗2

41http://cs231n.github.io/linear-classify/

Interactive Demo

http://vision.stanford.edu/teaching/cs231n/linear-classify-demo/ 42

SUPPORT VECTOR MACHINES

An alternative formulation of

Barrowed mostly from the slides of:- Machine Learning Group, University of Texas at Austin.- Mingyue Tan, The University of British Columbia

43

Linear Separators

β€’ Binary classification can be viewed as the task of separating classes in feature space:

wTx + b = 0

wTx + b < 0wTx + b > 0

f(x) = sign(wTx + b)

44

Linear Separators

β€’ Which of the linear separators is optimal?

45

Classification Margin

β€’ Distance from example xi to the separator is

β€’ Examples closest to the hyperplane are support vectors.

β€’ Margin ρ of the separator is the distance between support vectors.

w

xw br i

T

r

ρ

46

Maximum Margin Classification

β€’ Maximizing the margin is good according to intuition.

β€’ Implies that only support vectors matter; other training examples are ignorable.

47

Linear SVM Mathematically

What we know:

β€’ w . x+ + b = +1

β€’ w . x- + b = -1

β€’ w . (x+-x-) = 2

X-

x+

ww

wxx 2)(

ρ=Margin Width

49

Linear SVMs Mathematically (cont.)

β€’ Then we can formulate the optimization problem:

Which can be reformulated as:

Find w and b such that

is maximized

and for all (xi, yi), i=1..n : yi(wTxi + b) β‰₯ 1

w

2

Find w and b such that

Ξ¦(w) = ||w||2=wTw is minimized

and for all (xi, yi), i=1..n : yi (wTxi + b) β‰₯ 1

50

Lagrange Multipliers

β€’ Given the following optimization problem:minimize 𝑓 π‘₯, 𝑦 subject to 𝑔 π‘₯, 𝑦 = 𝑐

β€’ We can formulate it as:𝐿 π‘₯, 𝑦, πœ† = 𝑓 π‘₯, 𝑦 + πœ†(𝑔 π‘₯, 𝑦 βˆ’ 𝑐)

β€’ and set the derivative to zero:𝛻π‘₯,𝑦,πœ†πΏ π‘₯, 𝑦, πœ† = 0

51

Lagrange Multipliers

β€’ Main intuition:

– The gradients of f and g are parallel at the maximum

𝛻𝑓 = πœ†π›»π‘”

52

Fig: http://mathworld.wolfram.com/LagrangeMultiplier.html

Lagrange Multipliers

β€’ See the following for proof– http://ocw.mit.edu/courses/mathematics/18-02sc-

multivariable-calculus-fall-2010/2.-partial-derivatives/part-c-lagrange-multipliers-and-constrained-differentials/session-40-proof-of-lagrange-multipliers/MIT18_02SC_notes_22.pdf

β€’ A clear example:– http://tutorial.math.lamar.edu/Classes/CalcIII/Lagrang

eMultipliers.aspx

β€’ More intuitive explanation:– http://www.slimy.com/~steuard/teaching/tutorials/La

grange.html

53

54

Non-linear SVMs

β€’ Datasets that are linearly separable with some noise work out great:

β€’ But what are we going to do if the dataset is just too hard?

β€’ How about… mapping data to a higher-dimensional space:

0

0

0

x2

x

x

x

55

SOFTMAX OR LOGISTIC CLASSIFIERS

56

Cross-entropy

β€’ Uses cross-entropy (𝑑: target probabilities, π‘œ: estimated probabilities):

𝐻 𝑝, π‘ž = 𝐸𝑝 βˆ’ log π‘ž = βˆ’

𝑗

𝑝𝑗 log π‘žπ‘—

β€’ Wikipedia:– β€œthe cross entropy between two probability distributions 𝑝 and π‘ž over

the same underlying set of events measures the average number of bits needed to identify an event drawn from the set, if a coding scheme is used that is optimized for an "unnatural" probability distribution π‘ž, rather than the "true" distribution 𝑝”

57

Softmax classifier – cross-entropy loss

β€’ Cross-entropy: 𝐻 𝑝, π‘ž = 𝐸𝑝 βˆ’ log π‘ž = βˆ’ 𝑗 𝑝𝑗 log π‘žπ‘—

β€’ In our case, – 𝑝 denotes the correct probabilities of the categories. In other words,

𝑝𝑗 = 1 for the correct label and 𝑝𝑗 = 0 for other categories.

– π‘ž denotes the estimated probabilities of the categories

β€’ But, our scores are not probabilities!

– One solution: Softmax function: 𝑓 𝑧𝑖 =𝑒𝑧𝑖

𝑗 𝑒𝑧𝑗

– It maps arbitrary ranges to probabilities

β€’ Using the normalized values, we can define the cross-entropy loss for classification problem now:

𝐿𝑖 = βˆ’ log𝑒𝑓𝑦𝑖

𝑗 𝑒𝑓𝑗

= βˆ’π‘“π‘¦π‘– + log

𝑗

𝑒𝑓𝑗

58http://cs231n.github.io/

logistic loss

β€’ A special case of cross-entropy for binary classification:

𝐻 𝑝, π‘ž = βˆ’

𝑗

𝑝𝑗 log π‘žπ‘— = βˆ’π‘π‘— log π‘žπ‘— βˆ’ 1 βˆ’ 𝑝𝑗 log 1 βˆ’ π‘žπ‘—

β€’ Softmax function reduces to the logistic function:1

1 + 𝑒π‘₯

β€’ And the loss becomes:

𝐿𝑖 = βˆ’ log1

1 + 𝑒𝑓

59http://cs231n.github.io/

Why take logarithm of probabilities?

β€’ Maps probability space to logarithmic space

β€’ Multiplication becomes addition

– Multiplication is a very frequent operation with probabilities

β€’ Speed:

– Addition is more efficient

β€’ Accuracy:

– Considering loss in representing real numbers, addition is friendlier

β€’ Since log-probability is negative, to work with positive numbers, we usually negate the log-probability

62

Softmax classifier: One interpretation

β€’ Information theory

– Cross-entropy between a true distribution and an estimated one:

𝐻 𝑝, π‘ž = βˆ’

π‘₯

𝑝 π‘₯ log π‘ž π‘₯ .

– In our case, 𝑝 = [0,… , 1,0, . . 0], containing only one 1, at the correct label.

– Since 𝐻 𝑝, π‘ž = 𝐻 𝑝 + 𝐷𝐾𝐿(𝑝||π‘ž), we are minimizing the Kullback-Leibler divergence.

63http://cs231n.github.io/

Softmax classifier: Another interpretation

β€’ Probabilistic view

𝑃 𝑦𝑖 π‘₯𝑖;π‘Š) =𝑒𝑓𝑦𝑖

𝑗 𝑒𝑓𝑗.

β€’ In our case, we are minimizing the negative log likelihood.

β€’ Therefore, this corresponds to Maximum Likelihood Estimation (MLE).

64http://cs231n.github.io/

Numerical Stability

β€’ Exponentials may become very large. A trick:

β€’ Set log 𝐢 = βˆ’max𝑗

𝑓𝑗.

65http://cs231n.github.io/

SVM loss vs. cross-entropy loss

β€’ SVM is happy when the classification satisfies the margin

– Ex: if score values = [10, 9, 9] or [10, -10, -10]

β€’ SVM loss is happy if the margin is 1

– SVM is local

β€’ cross-entropy always wants better

– cross-entropy is global

66

0-1 Loss

β€’ Minimize the # of cases where the prediction is wrong:

𝐿 =

π’Š

𝟏 𝑓 π‘₯𝑖;π‘Š, 𝑏 𝑦𝑖 β‰  𝑦𝑖

Or equivalently,

𝐿 =

π’Š

𝟏 𝑦𝑖𝑓 π‘₯𝑖;π‘Š, 𝑏 𝑦𝑖 < 0

68

Absolute Value Loss, Squared Error Loss

𝐿𝑖 =

𝑗

𝑠𝑗 βˆ’ π‘¦π‘—π‘ž

β€’ π‘ž = 1: absolute value loss

β€’ π‘ž = 2: square error loss.

69Bishop

MORE ON LOSS FUNCTIONS

70

Visualizing Loss Functions

β€’ If you look at one of the example loss functions:

𝐿𝑖 =

𝑗≠𝑦𝑖

max(0, 𝑀𝑗𝑇π‘₯𝑖 βˆ’π‘€π‘¦π‘–

𝑇 π‘₯𝑖 + 1)

β€’ Since π‘Š has too many dimensions, this is difficult to plot.

β€’ We can visualize this for one weight direction though, which can give us some intuition about the shape of the function.– E.g., start from an arbitrary π‘Š0, choose a direction π‘Š1

and plot 𝐿(π‘Š0 + π›Όπ‘Š1) for different values of 𝛼.

75http://cs231n.github.io/

Visualizing Loss Functions

β€’ Example:

β€’ If we consider just 𝑀0, we have many linear functions in terms of 𝑀0 and loss is a linear combination of them.

76http://cs231n.github.io/

Visualizing Loss Functions

β€’ You see that this is a convex function.– Nice and easy for optimization

β€’ When you combine many of them in a neural network, it becomes non-convex.

Loss along one direction Loss along two directions Loss along two directions(averaged over many samples)

77http://cs231n.github.io/

β€’ 0-1 loss:𝐿 = 1(𝑓 π‘₯ β‰  𝑦)

or equivalently as:𝐿 = 1(𝑦𝑓 π‘₯ > 0)

β€’ Square loss:𝐿 = 𝑓 π‘₯ βˆ’ 𝑦 2

in binary case:

𝐿 = 1 βˆ’ 𝑦𝑓 π‘₯2

β€’ Hinge-loss𝐿 = max(1 βˆ’ 𝑦𝑓 π‘₯ , 0)

β€’ Logistic loss:

𝐿 = ln 2 βˆ’1ln(1 + π‘’βˆ’π‘¦π‘“ π‘₯ )

Another approach for visualizing loss functions

78

Rosacco et al., 2003

SUMMARY OF LOSS FUNCTIONS

79

80

81

82

83

Sum up

β€’ 0-1 loss is not differentiable/helpful at training– It is used in testing

β€’ Other losses try to cover the β€œweakness” of 0-1 loss

β€’ Hinge-loss imposes weaker constraint compared to cross-entropy

β€’ For classification: use hinge-loss or cross-entropy loss

β€’ For regression: use squared-error loss, or absolute difference loss

84

SO, WHAT DO WE DO WITH A LOSS FUNCTION?

85

Optimization strategies

β€’ We want to find π‘Š that minimizes the loss function.

– Remember that π‘Š has lots of dimensions.

β€’ NaΓ―ve idea: random search

– For a number of iterations:β€’ Select a π‘Š randomly

β€’ If it leads to better loss than the previous ones, select it.

– This yields 15.5% accuracy on CIFAR after 1000 iterations (chance: 10%)

86http://cs231n.github.io/

Optimization strategies

β€’ Second idea: random local search

– Start at an arbitrary position (weight π‘Š)

– Select an arbitrary direction π‘Š + π›Ώπ‘Š and see if it leads to a better loss

β€’ If yes, move along

– This leads to 21.4% accuracy after 1000 iterations

– This is actually a variation of simulated annealing

β€’ A better idea: follow the gradient

87http://cs231n.github.io/

A quick reminder on gradients / partial derivatives

– In one dimension: 𝑑𝑓 π‘₯

𝑑π‘₯= lim

β„Žβ†’0

𝑓 π‘₯+β„Ž βˆ’π‘“ π‘₯

β„Ž

– In practice:

‒𝑑𝑓 𝑛

𝑑𝑛=

𝑓 𝑛+β„Ž βˆ’π‘“[𝑛]

β„Ž

‒𝑑𝑓 𝑛

𝑑𝑛=

𝑓 𝑛+β„Ž βˆ’π‘“[π‘›βˆ’β„Ž]

2β„Ž(centered difference – works better)

– In many dimensions:

1. Compute gradient numerically with finite differences

– Slow

– Easy

– Approximate

2. Compute the gradient analytically

– Fast

– Exact

– Error-prone to implement

β€’ In practice: implement (2) and check against (1) before testing

88

http://cs231n.github.io/

A quick reminder on gradients / partial derivatives

β€’ If you have a many-variable function, e.g., 𝑓 π‘₯, 𝑦 = π‘₯ + 𝑦, you can take its derivative wrt either π‘₯ or 𝑦:

–𝑑𝑓 π‘₯,𝑦

𝑑π‘₯= lim

β„Žβ†’0

𝑓 π‘₯+β„Ž,𝑦 βˆ’π‘“(π‘₯,𝑦)

β„Ž= 1

– Similarly, 𝑑𝑓 π‘₯,𝑦

𝑑𝑦= 1

– In fact, we should denote them as follows since they are β€œpartial derivatives” or β€œgradients on x or y”:

β€’πœ•π‘“

πœ•π‘₯and

πœ•π‘“

πœ•π‘¦

β€’ Partial derivative tells you the rate of change along a single dimension at a point.

– E.g., if πœ•π‘“/πœ•π‘₯=1, it means that a change of π‘₯0 in π‘₯ leads to the same amount of change in the value of the function.

β€’ Gradient is a vector of partial derivatives:

– 𝛻𝑓 =πœ•π‘“

πœ•π‘₯,πœ•π‘“

πœ•π‘¦

89http://cs231n.github.io/

A quick reminder on gradients / partial derivatives

β€’ A simple example:– 𝑓 π‘₯, 𝑦 = max(π‘₯, 𝑦)

– 𝛻𝑓 = 𝟏 π‘₯ β‰₯ 𝑦 , 𝟏 𝑦 β‰₯ π‘₯

β€’ Chaining:– What if we have a composition of functions?

– E.g., 𝑓 π‘₯, 𝑦, 𝑧 = π‘ž π‘₯, 𝑦 𝑧 and π‘ž π‘₯, 𝑦 = π‘₯ + 𝑦

β€“πœ•π‘“

πœ•π‘₯=

πœ•π‘“

πœ•π‘ž

πœ•π‘ž

πœ•π‘₯= 𝑧

β€“πœ•π‘“

πœ•π‘¦=

πœ•π‘“

πœ•π‘ž

πœ•π‘ž

πœ•π‘¦= 𝑧

β€“πœ•π‘“

πœ•π‘§= π‘ž π‘₯, 𝑦 = π‘₯ + 𝑦

β€’ Back propagation– Local processing to improve the system globally

– Each gate locally determines to increase or decrease the inputs

90http://cs231n.github.io/

Partial derivatives and backprop

β€’ Which has many gates:

91http://cs231n.github.io/

In fact, that was the sigmoid function

β€’ We will combine all these gates into a single gate and call it a neuron

92

Intuitive effects

β€’ Commonly used operations– Add gate– Max gate– Multiply gate

β€’ Due to the effect of the multiply gate, when one of the inputs is large, the small input gets the large gradient– This has a negative effect in

NNs– When one of the weights is

unusually large, it effects the other weights.

– Therefore, it is better to normalize the input / weights

93http://cs231n.github.io/

Optimization strategies: gradient

β€’ Move along the negative gradient (since we wish to go down)

– π‘Š βˆ’ π‘ πœ•πΏ π‘Š

πœ•π‘Š

– 𝑠: step size

β€’ Gradient tells us the direction– Choosing how much to move along that direction is difficult to

determine

– This is also called the learning rate

– If it is small: too slow to converge

– If it is big: you may overshoot and skip the minimum

94http://cs231n.github.io/

Optimization strategies: gradient

β€’ Take our loss function:

𝐿𝑖 =

𝑗≠𝑦𝑖

max(0,𝑀𝑗𝑇π‘₯𝑖 βˆ’ 𝑀𝑦𝑖

𝑇 π‘₯𝑖 + 1)

β€’ Its gradient wrt 𝑀𝑗 is:πœ•πΏπ‘–πœ•π‘€π‘—

= 𝟏 𝑀𝑗𝑇π‘₯𝑖 βˆ’π‘€π‘¦π‘–

𝑇 π‘₯𝑖 + 1 > 0 π‘₯𝑖

β€’ For the β€œwinning” weight, this is:

95http://cs231n.github.io/

Gradient Descent

β€’ Update the weight:

π‘Šπ‘›π‘’π‘€ ← π‘Š βˆ’ π‘ πœ•πΏ π‘Š

πœ•π‘Š

β€’ This computes the gradient after seeing all examples to update the weight.– Examples can be on the order of millions or billions

β€’ Alternative:– Mini-batch gradient descent: Update the weights after, e.g., 256 examples

– Stochastic (or online) gradient descent: Update the weights after each example

– People usually use batches and call it stochastic.

– Performing an update after one example for 100 examples is more expensive than performing an update at once for 100 examples due to matrix/vector operations

96http://cs231n.github.io/

A GENERAL LOOK AT OPTIMIZATION

97

Mathematical Optimization

Convex Optimization

Least-squares LP

Nonlinear Optimization

Rong Jin

100

Mathematical Optimization

101

Rong Jin

Convex Optimization

102

Rong Jin

Interpretation

Function’s value is below the line connecting two points

Mark Schmidt103

Another interpretation

Mark Schmidt104

Example convex functions

Mark Schmidt106

Operations that conserve convexity

107

Rong Jin

π‘₯ + 𝑦𝑝

<= π‘₯𝑝+ 𝑦

𝑝

108

Rong Jin

A KTEC Center of Excellence 109

Why convex optimization?

β€’ Can’t solve most OPs

β€’ E.g. NP Hard, even high polynomial time too slow

β€’ Convex OPs

β€’ (Generally) No analytic solution

β€’ Efficient algorithms to find (global) solution

β€’ Interior point methods (basically Iterated Newton) can be used:

– ~[10-100]*max{p3 , p2m, F} ; F cost eval. obj. and constr. f

β€’ At worst solve with general IP methods (CVX), faster

specialized

A KTEC Center of Excellence 110

Convex Function

β€’ Easy to see why convexity allows for

efficient solution

β€’ Just β€œslide” down the objective function as

far as possible and will reach a minimum

A KTEC Center of Excellence 111

Convex vs. Non-convex Ex.

β€’ Convex, min. easy to find

Affine – border

case of convexity

A KTEC Center of Excellence 112

Convex vs. Non-convex Ex.

β€’ Non-convex, easy to get stuck in a local min.

β€’ Can’t rely on only local search techniques

A KTEC Center of Excellence 113

Non-convex

β€’ Some non-convex problems highly multi-modal,

or NP hard

β€’ Could be forced to search all solutions, or hope

stochastic search is successful

β€’ Cannot guarantee best solution, inefficient

β€’ Harder to make performance guarantees with

approximate solutions

β€’ Analytical solutionβ€’ Good algorithms and softwareβ€’ High accuracy and high reliabilityβ€’ Time complexity:

Mathematical Optimization

Convex Optimization

Least-squares LP

Nonlinear Optimization

knC 2

A mature technology!

114

Rong Jin

β€’ No analytical solutionβ€’ Algorithms and softwareβ€’ Reliable and efficientβ€’ Time complexity:

Mathematical Optimization

Convex Optimization

Least-squares LP

Nonlinear Optimization

mnC 2

Also a mature technology!

115

Rong Jin

Mathematical Optimization

Convex Optimization

Nonlinear Optimization

Almost a mature technology!

Least-squares LP

β€’ No analytical solutionβ€’ Algorithms and softwareβ€’ Reliable and efficientβ€’ Time complexity (roughly)

},,max{ 23 Fmnn

116

Rong Jin

Mathematical Optimization

Convex Optimization

Nonlinear Optimization

Far from a technology! (something to avoid)

Least-squares LP

β€’ Sadly, no effective methods to solveβ€’ Only approaches with some compromiseβ€’ Local optimization: β€œmore art than technology”

β€’ Global optimization: greatly compromised efficiency β€’ Help from convex optimization

1) Initialization 2) Heuristics 3) Bounds

117

Rong Jin

Why Study Convex Optimization

If not, ……

-- Section 1.3.2, p8, Convex Optimization

there is little chance you can solve it.

118

Rong Jin

Recognizing Convex Optimization

Problems

121

Rong Jin

Least-squares

126

Rong Jin

Analytical Solution of Least-squares

β€’ Set the derivative to zero:

–𝑑𝑓0 π‘₯

𝑑π‘₯= 0

– 𝐴𝑇𝐴 2π‘₯ βˆ’ 2𝐴𝑏 = 0

– 𝐴𝑇𝐴 π‘₯ = 𝐴𝑏

β€’ Solve this system of linear equations

127

Linear Programming (LP)

128

Rong Jin

To sum up

β€’ We introduced some important concepts in machine learning and optimization

β€’ We introduced popular machine learning methods

β€’ We talked about loss functions and how we can optimize them using gradient descent

135

top related