$ show PatWie/CppNumericalSolvers
CppNumericalSolvers is a header-only C++17 library for numerical optimization that provides a suite of modern solvers for both unconstrained and constrained problems. The library features a sophisticated expression template system for building complex objective functions, implementations of popular algorithms like L-BFGS, BFGS, and Newton's method, and advanced constrained optimization via the Augmented Lagrangian method. It uses Eigen3 as its sole dependency for linear algebra operations and is designed for easy integration into other projects. The architecture is modular with separate components for function interfaces, solvers, line searches, and utilities, all leveraging C++ templates for flexibility and performance.
The LLM identified 3 files worth highlighting for reuse:
Implements a sophisticated expression template system that allows users to build complex objective functions from simpler components (e.g., f = g + 2*h) while automatically computing gradients and Hessians. Demonstrates advanced C++ template metaprogramming skills by handling different differentiability modes and enabling natural mathematical syntax for function composition. The system is largely self-contained and could be extracted for use in other mathematical libraries with minimal adaptation.
Provides a robust implementation of the Augmented Lagrangian method for constrained optimization that handles both equality and inequality constraints. Features include automatic penalty scaling, warm-up strategies for early iterations, KKT-based stopping criteria, and best iterate tracking to handle non-convex objectives. The Powell-Hestenes-Rockafellar formulation for inequalities prevents unboundedness issues. While it depends on supporting components, the core algorithm is well-encapsulated and could be reused with different inner solvers.
Implements the Hager-Zhang (2006) line search algorithm, a sophisticated method that satisfies Wolfe conditions for optimization. The code includes detailed comments referencing the original research paper and appears to be a faithful implementation. This component is highly self-contained, depending only on basic function types, and could be easily extracted for use in other optimization frameworks. It demonstrates correct implementation of a non-trivial numerical algorithm.