Newton's method

Posted on July 6, 2017

optimization, Newton's method, Taylor series, quadratic approximation


This post and others are heavily inspired by Goodfellow’s Deep Learning book. Newton’s method is just a smarter version of gradient descent. Let be our cost function. Gradient descent follows the gradient directly downhill from the previous point:

There’s one problem. The direction pointing directly downhill changes as we move.

Newton’s avoids this wasteful naivety by considering how the gradient will change as we move. Since the Hessian is the gradient of the gradient, we just left-multiply our step by the inverse Hessian:

So Newton’s just rescales each element of the gradient by the weighted sum of its second derivatives. We can derive Newton’s method with a few lines of calculus.


Taylor approximation

Remember that the Taylor polynomial approximates a function from the perspective of a given point. Here’s a GIF showing how the Taylor polynomial matches more and more of as we add terms, from the perspective of .

Well, it takes a lot of terms. You’ll be surprised to hear that in a lot of optimization we only use two terms. Yeah, this is a bad approximation, but it works as long as we don’t move too far. Besides, after we move, we’ll make a new Taylor approximation from our new point, which will suit us for another small move from there.


Deriving Newton’s from the Taylor expansion

If we look at the second-order Taylor polynomial from the perspective of , we have

This approximates our cost function , as long as we don’t move too far from our perspective point . Since we’re trying to minimize our cost, we’ll set its gradient equal to zero. That means, in one step, we’ll move in the direction and distance that gets us to a flat gradient, assuming our quadratic approximation is accurate up until that point. This assumption can be good or bad. In deep learning it can end up jumping us to saddle points. A quick note: we’re using column gradients below, so is a row vector which forms a dot product with .


Finding the gradient

The gradient of the second-order Taylor approximation of the cost function is and by linearity of the gradient operator The first term is zero since is fixed and we’re taking the gradient with respect to .

By linearity of transpose and linearity of matrix product and again upon the right side Distributing and applying the gradient operators gives and distributing the transpose across the product and exploiting the fact that the Hessian is symmetric such that


Setting the gradient to zero

So this is the gradient of our quadratic approximation of our cost function when evaluated at our current parameter setting . If we set this equation equal to zero and solve for we get the new parameter setting that sets our gradient equal to zero assuming that our quadratic approximation is valid up until that point:


Conclusion

Newton’s method is gradient descent where we scale the gradient by the inverse Hessian. This gives Newton’s foresight of how the gradient will change as we move, which lets us jump straight to the point where the gradient is zero if we so choose. A learning rate of will make this happen. A learning rate less than is more conservative.

Newton’s has weakness. It will actually move uphill to a point of zero gradient, and that point could also be a saddle point rather than a local minimum. Additionally you have to use operations to compute the Hessian. There are ways to fix these weaknesses, known as quasi-Newton methods. We’ll explore these in future posts.