second-order optimization methods

28
Second-Order Optimization Methods Anupam Datta CMU Spring 2018 Security and Fairness of Deep Learning

Upload: others

Post on 24-Jan-2022

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Second-Order Optimization Methods

Second-Order Optimization

Methods Anupam Datta

CMU

Spring 2018

Security and Fairness of Deep Learning

Page 2: Second-Order Optimization Methods

Key insight

Leverage second-order derivatives (gradient) in addition to first-order derivatives to converge faster to minima

Page 3: Second-Order Optimization Methods

In two steps

• Function of single variable

• Function of multiple variables

Page 4: Second-Order Optimization Methods

Derivative at minima

x

f(x)

𝑑𝑑 = 0

Page 5: Second-Order Optimization Methods

Turning Points

• Both maxima and minima have zero derivative

• Both are turning points

5

0

+

+ +

0

+ +

+

+

+

+

0

- - - - - -

- - - - - - - -

Page 6: Second-Order Optimization Methods

Derivatives of a curve

• Both maxima and minima are turning points

• Both maxima and minima have zero derivative

6

x f(x)

f ’(x)

Page 7: Second-Order Optimization Methods

Derivative of the derivative of the curve

• The second derivative f’’(x) is –ve at maxima and +ve at minima

7

x f(x)

f’(x) f’’(x)

Page 8: Second-Order Optimization Methods

Summary

• All locations with zero

derivative are critical points

• The second derivative is

• 0 at minima

• 0 at maxima

• Zero at inflection points

8

𝑓

𝑑𝑓𝑑

𝑑 𝑓𝑑

maximum

minimum

Inflection point

negative

positive

zero

Page 9: Second-Order Optimization Methods

In two steps

• Function of single variable

• Function of multiple variables

Page 10: Second-Order Optimization Methods

Gradient of function with multi-variate inputs

•Consider 𝑓 𝑋 = 𝑓 , , … , 𝑛 •𝛻𝑓 𝑋 = 𝜕𝑓 𝑋𝜕𝑥 𝜕𝑓 𝑋𝜕𝑥 ⋯ 𝜕𝑓 𝑋𝜕𝑥𝑛

Note: Scalar function of multiple variables

Page 11: Second-Order Optimization Methods

The Hessian

• The Hessian of a function 𝑓 , , … , 𝑛

11

Ñ2f (x

1,..., x

n) :=

¶2f

¶x1

2

¶2f

¶x1¶x

2

. .¶2f

¶x1¶x

n

¶2f

¶x2¶x

1

¶2f

¶x2

2. .

¶2f

¶x2¶x

n

. . . . .

. . . . .

¶2f

¶xn¶x

1

¶2f

¶xn¶x

2

. .¶2f

¶xn

2

é

ë

êêêêêêêêêêêêê

ù

û

úúúúúúúúúúúúú

Page 12: Second-Order Optimization Methods

Unconstrained minimization of multivariate

function

1. Solve for the 𝑋 where the gradient equation equals to zero

2. Compute the Hessian Matrix 𝛻 𝑓 𝑋 at the candidate solution and

verify that

• Hessian is positive definite (eigenvalues positive) -> to identify local minima

• Hessian is negative definite (eigenvalues negative) -> to identify local

maxima

12

0)( Xf

Page 13: Second-Order Optimization Methods

Example

• Minimize

• Gradient

13

f (x1, x

2, x

3) = (x

1)

2+ x

1(1 - x

2) - (x

2)

2- x

2x

3+ (x

3)

2+ x

3

T

xx

xxx

xx

f

12

2

12

32

321

21

Page 14: Second-Order Optimization Methods

Example

• Set the gradient to null

• Solving the 3 equations system with 3 unknowns

14

Ñf = 0Þ

2x1+1 - x

2

- x1+ 2x

2- x

3

- x2

+ 2x3+1

é

ë

êêêê

ù

û

úúúú

=

0

0

0

é

ë

êêê

ù

û

úúú

x =

x1

x2

x3

é

ë

êêêê

ù

û

úúúú

=

- 1

- 1

- 1

é

ë

êêê

ù

û

úúú

Page 15: Second-Order Optimization Methods

Example

• Compute the Hessian matrix

• Evaluate the eigenvalues of the Hessian matrix

• All the eigenvalues are positive => the Hessian matrix is positive definite

• This point is a minimum

15

Ñ2f =

2 - 1 0

- 1 2 - 1

0 - 1 2

é

ë

êêê

ù

û

úúú

l1

= 3.414, l2

= 0.586, l3

= 2

x =

x1

x2

x3

é

ë

êêêê

ù

û

úúúú

=

- 1

- 1

- 1

é

ë

êêê

ù

û

úúú

Page 16: Second-Order Optimization Methods

Catch

• Closed form solutions not always available

• Instead use an iterative refinement approach

• (Stochastic) gradient descent makes use of first-order derivatives (gradient)

• Can we do better with second-order derivatives (Hessian)?

Page 17: Second-Order Optimization Methods

Ne to ’s ethod for co ex fu ctio s

• Iterative update of model parameters like gradient descent

• Key update step

• Compare with gradient descent

Page 18: Second-Order Optimization Methods

Taylor series

The Taylor series of a function f (x) that is infinitely differentiable at the

point a is the power series

Page 19: Second-Order Optimization Methods

Taylor series second-order approximation

The Taylor series second-order approximation of a function f (x) that

is infinitely differentiable at the point a is

Page 20: Second-Order Optimization Methods

Local minimum of Taylor series second-order

approximation

Page 21: Second-Order Optimization Methods

Ne to ’s ethod approach

Take step to local minima of second-order Taylor approximation of loss function

Page 22: Second-Order Optimization Methods

Example

Murphy, Machine Learning, Fig 8.4

Page 23: Second-Order Optimization Methods

Taylor series second-order approximation for

multivariate function

Page 24: Second-Order Optimization Methods

Deriving update rule

Local minima of this function

is

Page 25: Second-Order Optimization Methods

Weak ess of Ne to ’s ethod

• Appropriate when function is strictly convex

• Hessian always positive definite

Murphy, Machine Learning, Fig 8.4

Page 26: Second-Order Optimization Methods

Weak ess of Ne to ’s ethod

• Computing inverse Hessian explicitly is too expensive

• O(k^3) if there are k model parameters: inverting a k x k matrix

Page 27: Second-Order Optimization Methods

Quasi-Newton methods address weakness

• Iteratively build up approximation to the Hessian

• Popular method for training deep networks

• Limited memory BFGS (L-BFGS)

• Will discuss in a later lecture

Page 28: Second-Order Optimization Methods

Acknowledgment

Based in part on material from CMU 11-785