Quasi-Newton method derivation
"TLDR: This article introduces the two main forms of the quasi-Newton method: the BFGS method and the L-BFGS method. The BFGS method uses curvature information to preprocess gradients, thereby avoiding the need for a complete calculation of the Hessian matrix in traditional methods. The L-BFGS method further optimizes this preprocessing by saving only the curvature information of the most recent m iterations to calculate an approximation of the Hessian matrix, significantly reducing memory usage and computational effort."
Quasi-Newton equation
BFGS method
BFGS is a kind of quasi-Newton method, which mainly uses curvature information to preprocess the gradient to determine the descent direction.
Curvature information is obtained by maintaining a Hessian matrix about the loss function that is gradually approximated using the generalized secant method.
Approximation and Correction
Let , that is to say, the data calculated using the "secant method" approximates the Hessian matrix. Since it is an approximation, there must be an error. Let's try to correct this error.
Of course, this is just an assumption. Whether the assumption can really be corrected in this way requires further calculations.
A very interesting feature is: the constructed approximate Hessian matrix must be positive definite;
In Newton's method, if the Hessian matrix is not positive definite, then the objective function does not necessarily decrease. Only positive definite will definitely decrease. The quasi-Newton method just avoids this problem. Since it must be positive definite, the objective function must decrease.
For convenience of description, remember:
Then there are:
Decompose :
As long as the two vectors are solved, then can be calculated, then can be calculated.
Easy to know:
It can be found that this equation is very broad and can solve many solutions. You might as well try a special case (really a random guess condition):
Then we can derive:
As long as a solution can be found, some additional conditions are introduced here, and a pretty good recursion result is obtained. Keep pushing:
After the push is completed, the final iteration formula is obtained by merging:
Since the direction of Newton's method is , it is best to directly find the inverse of the Hessian matrix, which is obtained according to the Sherman-Morrison formula:
Pseudocode
Set the starting point and the initial Hessian matrix , repeat the following steps, will converge to the solution of the problem:
-
Obtain the descending direction by solving the equation .
-
Perform a one-dimensional optimization line search in the direction to find the appropriate step size . If the search is complete, then . In practice, an incomplete search is generally sufficient, in which case only requires that satisfy the Wolfe condition.
-
Let , and let (very normal gradient iteration)
-
(save the gradient change after iteration)
-
( here is the inverse of the approximate Hessian matrix)
represents the objective function to be minimized. Convergence can be judged by checking the norm of the gradient . If is initialized to , the first step will be equivalent to gradient descent, but the subsequent steps will be regulated by that is approximately a Hessian matrix.
L-BFGS
Benefits of BFGS
It is easy to know that Newton's method actually requires that the initial iteration point and the optimal point are relatively close, otherwise it may converge to other minimum points, so there is such a thing as Newton's fractal.
Well, since the quasi-Newton method is not a complete Newton method, that is to say, its convergence situation does not need to be limited to "closer to the optimal point". In fact, the concept of "very close to the optimal point" is inherently imaginary, so the quasi-Newton method has the convergence speed of the Newton method without so restricting the use area. This is the benefit of BFGS.
Disadvantages of BFGS and L-BFGS
As a Newton method, BFGS needs to save a Hessian matrix for each iteration, with a space complexity of . This makes Newton's method (such as BFGS) unable to be applied to modern neural network models with millions of parameters.
If there is a problem, there is a solution, so there is L-BFGS
L-BFGS full name is storage limited BFGS, L refers to limited memory
A very important point in L-BFGS is: the iteration initial value is set to identity matrix
The iteration formula is the same as BFGS:
~~But, in BFGS, only are calculated each time, and only is retained each time, but this is very large and difficult to save. ~~
(The above statement may or may not be reasonable. My mind is a little confused now)
In order to calculate , it is no longer the sum of all previous operations, but the most recent m times (this m is artificially specified)
At the k-th iteration, the algorithm obtains , and the saved curvature information is . In order to obtain , each iteration of the algorithm needs to select an initial matrix . This is different from the BFGS algorithm. Next, only the nearest m vectors are used to modify the initial matrix. In practice, the setting of is usually as follows:
Among them, represents the proportion coefficient, which uses the latest curvature information to estimate the size of the real Hessian matrix. This makes the search direction of the current step more ideal and does not run "too far", thus eliminating the step of step search and saving time.
In the L-BFGS algorithm, the method of updating the approximate matrix by saving the curvature information of the last m times is very effective in practice. Although the L-BFGS algorithm is linearly convergent, the cost of each iteration is very small, so the execution speed of the L-BFGS algorithm is still very fast, and since each iteration can guarantee the positive definiteness of the approximate matrix, the robustness of the algorithm is still very strong.
Summary
To summarize the differences between BFGS and L-BFGS:
-
When the BFGS algorithm is running, each iteration needs to save an matrix. Nowadays, many machine learning problems are high-dimensional. When n is large, the memory occupied by this matrix is very alarming, and the amount of calculation required is also very large, which makes the traditional BFGS algorithm very unsuitable. L-BFGS is an improved version of this problem. As can be seen from the above, the BFGS algorithm uses the curvature information to correct to obtain .
-
The main idea of the L-BFGS algorithm is: the algorithm only saves the curvature information of the last m iterations to calculate . In this way, the storage space we need changes from to and usually m<<n .