ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Advanced Optimization Techniques for Machine Learning
Chapter 1: Foundations of Optimization in Machine Learning
Revisiting Gradient Descent Variants
The Role of Convexity
Understanding Loss Surfaces
Convergence Analysis Fundamentals
Challenges in Non-Convex Optimization
Numerical Stability Considerations
Practice: Analyzing Convergence Behavior
Chapter 2: Second-Order Optimization Methods
Newton's Method: Theory and Derivation
The Hessian Matrix: Computation and Properties
Challenges with Newton's Method
Quasi-Newton Methods: Approximating the Hessian
BFGS Algorithm Explained
Limited-memory BFGS (L-BFGS)
Trust Region Methods
Hands-on Practical: Implementing L-BFGS
Chapter 3: Adaptive Learning Rate Algorithms
Limitations of Fixed Learning Rates
AdaGrad: Adapting Rates Based on Past Gradients
RMSprop: Addressing AdaGrad's Diminishing Rates
Adam: Combining Momentum and RMSprop
Adamax and Nadam Variants
AMSGrad: Improving Adam's Convergence
Understanding Learning Rate Schedules
Hands-on Practical: Comparing Adaptive Optimizers
Chapter 4: Optimization for Large-Scale Datasets
Stochastic Gradient Descent Revisited: Variance Reduction
Stochastic Average Gradient (SAG)
Stochastic Variance Reduced Gradient (SVRG)
Mini-batch Gradient Descent Trade-offs
Asynchronous Stochastic Gradient Descent
Data Parallelism Strategies
Hands-on Practical: Implementing SVRG
Chapter 5: Distributed Optimization Strategies
Motivation for Distributed Training
Parameter Server Architectures
Synchronous vs. Asynchronous Updates
Communication Bottlenecks and Strategies
All-Reduce Algorithms
Federated Learning Optimization Principles
Hands-on Practical: Simulating Distributed SGD
Chapter 6: Optimization Challenges in Deep Learning
Characteristics of Deep Learning Loss Landscapes
Impact of Network Architecture on Optimization
Normalization Techniques and Optimization
Gradient Clipping and Explosion/Vanishing Gradients
Initialization Strategies and Their Effect
Regularization Methods as Implicit Optimization
Practice: Tuning Optimizers for Deep Networks
Chapter 7: Advanced and Specialized Optimization Topics
Constrained Optimization Fundamentals
Lagrangian Duality and KKT Conditions
Projected Gradient Methods
Derivative-Free Optimization Overview
Bayesian Optimization for Hyperparameter Tuning
Optimization for Reinforcement Learning Policies
Practice: Implementing Projected Gradient Descent

BFGS Algorithm Explained

The Broyden–Fletcher–Goldfarb–Shanno (BFGS) algorithm is an effective and widely used optimization technique, categorized as a Quasi-Newton method. These methods enhance optimization by approximating the Hessian matrix. Unlike Newton's method, which requires computing and inverting the true Hessian ∇2f(x)\nabla^2 f(x)∇2f(x) at each step, BFGS incrementally builds an approximation to the inverse Hessian, denoted as HkH_kHk​, using only first-order gradient information. This bypasses the significant computational burden associated with the true Hessian.

The Core Idea: Approximating the Inverse Hessian

The update direction in Newton's method is pk=−[∇2f(xk)]−1∇f(xk)p_k = -[\nabla^2 f(x_k)]^{-1} \nabla f(x_k)pk​=−[∇2f(xk​)]−1∇f(xk​). BFGS aims to replace the costly inverse Hessian term [∇2f(xk)]−1[\nabla^2 f(x_k)]^{-1}[∇2f(xk​)]−1 with a matrix HkH_kHk​ that is cheaper to compute and update. The search direction then becomes:

pk=−Hk∇f(xk)p_k = -H_k \nabla f(x_k)pk​=−Hk​∇f(xk​)

The central challenge is how to update HkH_kHk​ to Hk+1H_{k+1}Hk+1​ at each iteration so that it effectively captures curvature information, similar to the true inverse Hessian.

The Secant Equation

Quasi-Newton methods, including BFGS, are typically constrained by the secant equation. This equation relates the change in gradient ∇f\nabla f∇f to the change in the parameter vector xxx. Let sk=xk+1−xks_k = x_{k+1} - x_ksk​=xk+1​−xk​ be the step taken and yk=∇f(xk+1)−∇f(xk)y_k = \nabla f(x_{k+1}) - \nabla f(x_k)yk​=∇f(xk+1​)−∇f(xk​) be the change in gradients. A second-order Taylor expansion motivates the relationship:

∇f(xk+1)−∇f(xk)≈∇2f(xk+1)(xk+1−xk)\nabla f(x_{k+1}) - \nabla f(x_k) \approx \nabla^2 f(x_{k+1}) (x_{k+1} - x_k)∇f(xk+1​)−∇f(xk​)≈∇2f(xk+1​)(xk+1​−xk​)

Rearranging this gives ∇2f(xk+1)sk≈yk\nabla^2 f(x_{k+1}) s_k \approx y_k∇2f(xk+1​)sk​≈yk​. If we denote the Hessian approximation at step k+1k+1k+1 as Bk+1B_{k+1}Bk+1​ (approximating ∇2f(xk+1)\nabla^2 f(x_{k+1})∇2f(xk+1​)), the secant equation requires Bk+1sk=ykB_{k+1} s_k = y_kBk+1​sk​=yk​. Correspondingly, for the inverse Hessian approximation Hk+1=Bk+1−1H_{k+1} = B_{k+1}^{-1}Hk+1​=Bk+1−1​, the secant equation becomes:

Hk+1yk=skH_{k+1} y_k = s_kHk+1​yk​=sk​

This condition ensures that the updated approximation Hk+1H_{k+1}Hk+1​ correctly relates the observed change in gradient yky_kyk​ to the step sks_ksk​ that was taken.

The BFGS Update Formula

The BFGS algorithm provides a specific rank-two update rule for the inverse Hessian approximation HkH_kHk​. Given the current approximation HkH_kHk​, the step sks_ksk​, and the gradient difference yky_kyk​, the next approximation Hk+1H_{k+1}Hk+1​ is calculated as:

Hk+1=(I−skykTykTsk)Hk(I−ykskTykTsk)+skskTykTskH_{k+1} = \left(I - \frac{s_k y_k^T}{y_k^T s_k}\right) H_k \left(I - \frac{y_k s_k^T}{y_k^T s_k}\right) + \frac{s_k s_k^T}{y_k^T s_k}Hk+1​=(I−ykT​sk​sk​ykT​​)Hk​(I−ykT​sk​yk​skT​​)+ykT​sk​sk​skT​​

Let's dissect this formula:

  1. Input: It uses the previous inverse Hessian approximation HkH_kHk​, the step vector sks_ksk​, and the gradient difference vector yky_kyk​.
  2. Curvature Condition: The update requires ykTsk>0y_k^T s_k > 0ykT​sk​>0. This condition is related to the curvature of the function along the search direction. It ensures that the update maintains the positive definiteness of HkH_kHk​ if the initial H0H_0H0​ was positive definite and an appropriate line search (satisfying Wolfe conditions) is used. Positive definiteness of HkH_kHk​ guarantees that the search direction pk=−Hk∇f(xk)p_k = -H_k \nabla f(x_k)pk​=−Hk​∇f(xk​) is a descent direction.
  3. Rank-Two Update: The update modifies HkH_kHk​ by adding two symmetric rank-one matrices.
  4. Properties: The resulting Hk+1H_{k+1}Hk+1​ is symmetric and satisfies the secant equation (Hk+1yk=skH_{k+1} y_k = s_kHk+1​yk​=sk​).

While the formula looks complex, its structure is designed to incorporate the new curvature information contained in the pair (sk,yk)(s_k, y_k)(sk​,yk​) while minimally perturbing the previous approximation HkH_kHk​ in other directions.

The BFGS Algorithm Steps

The iterative process for BFGS optimization typically proceeds as follows:

  1. Initialization: Choose a starting point x0x_0x0​. Initialize the inverse Hessian approximation H0H_0H0​. A common choice is the identity matrix H0=IH_0 = IH0​=I. Set iteration counter k=0k=0k=0.
  2. Compute Search Direction: Calculate the descent direction pk=−Hk∇f(xk)p_k = -H_k \nabla f(x_k)pk​=−Hk​∇f(xk​).
  3. Line Search: Find an appropriate step size αk>0\alpha_k > 0αk​>0 along the direction pkp_kpk​. This is usually done using a line search algorithm that satisfies the Wolfe conditions, which helps ensure stability and maintain positive definiteness of the Hessian approximation. Common choices include backtracking line search.
  4. Update Position: Update the parameter vector: xk+1=xk+αkpkx_{k+1} = x_k + \alpha_k p_kxk+1​=xk​+αk​pk​.
  5. Check Convergence: Evaluate termination criteria (e.g., ∥∇f(xk+1)∥<ϵ\|\nabla f(x_{k+1})\| < \epsilon∥∇f(xk+1​)∥<ϵ, maximum iterations reached, small change in xxx or function value). If converged, stop.
  6. Compute Update Vectors: Define sk=xk+1−xk=αkpks_k = x_{k+1} - x_k = \alpha_k p_ksk​=xk+1​−xk​=αk​pk​ and yk=∇f(xk+1)−∇f(xk)y_k = \nabla f(x_{k+1}) - \nabla f(x_k)yk​=∇f(xk+1​)−∇f(xk​).
  7. Check Curvature Condition: If ykTsk>0y_k^T s_k > 0ykT​sk​>0:
    • Update Inverse Hessian: Compute Hk+1H_{k+1}Hk+1​ using the BFGS update formula shown above.
  8. Else (Curvature Condition Fails): Skip the update (keep Hk+1=HkH_{k+1} = H_kHk+1​=Hk​) or use a different strategy to handle this situation. This is rare if a proper line search is used.
  9. Increment and Loop: Set k=k+1k = k + 1k=k+1 and go back to step 2.

A diagram outlining the iterative steps involved in the BFGS optimization algorithm.

Advantages and Disadvantages

Advantages:

  • No Hessian Calculation/Inversion: Like other Quasi-Newton methods, BFGS avoids the direct computation, storage, and inversion of the n×nn \times nn×n Hessian matrix. It only requires gradient computations.
  • Fast Convergence: BFGS typically exhibits superlinear convergence rates (faster than linear, slower than quadratic) when close to a minimum, making it much faster than first-order methods like gradient descent for many problems.
  • Robustness: It is widely recognized as one of the most effective general-purpose optimization algorithms for smooth, unconstrained problems.

Disadvantages:

  • Memory Cost: The primary drawback of BFGS is the need to store and update the dense n×nn \times nn×n inverse Hessian approximation HkH_kHk​. For high-dimensional problems typical in machine learning (where nnn, the number of parameters, can be millions or billions), storing this matrix becomes infeasible due to memory requirements (O(n2)O(n^2)O(n2)).
  • Computational Cost per Iteration: While cheaper than Newton's method, updating HkH_kHk​ involves matrix-vector and outer product operations, costing O(n2)O(n^2)O(n2) computation per iteration. Computing the search direction pk=−Hk∇f(xk)p_k = -H_k \nabla f(x_k)pk​=−Hk​∇f(xk​) also takes O(n2)O(n^2)O(n2) operations. This can still be prohibitive for very large nnn.
  • Line Search Requirement: BFGS relies on a reasonably accurate line search (often satisfying the Wolfe conditions) to guarantee convergence and maintain the positive definiteness of HkH_kHk​.

The significant memory and computational costs associated with the dense HkH_kHk​ matrix in high dimensions directly motivate the development of Limited-memory BFGS (L-BFGS), which we will discuss in the next section. L-BFGS retains many benefits of BFGS while drastically reducing the memory footprint.

  • Conditioning of quasi-Newton methods for function minimization, David F. Shanno, 1970 Mathematics of Computation, Vol. 24 DOI: 10.1090/S0025-5718-1970-0274531-X - One of the original papers that introduced the BFGS update formula, important for the method's development.
  • Convex Optimization, Stephen Boyd and Lieven Vandenberghe, 2004 (Cambridge University Press) - A fundamental text in optimization, especially for machine learning. It covers convex optimization and discusses quasi-Newton methods.

© 2026 ApX Machine Learning