optim Build Coverage Status

Watch Star Fork

OptimLib is a C++ library of numerical optimization methods for nonlinear functions.


  • C++11 library of local and global optimization algorithms, as well as root finding techniques.
  • Derivative-free optimization using advanced, parallelized metaheuristics.
  • Constrained optimization routines can handle simple box constraints, or systems of nonlinear constraints.
  • Built on the Armadillo C++ linear algebra library for fast and efficient matrix-based computation.
  • OpenMP-accelerated algorithms for parallel computation.
  • Straightforward linking with parallelized BLAS libraries, such as OpenBLAS.
  • Released under a permissive, non-GPL license.


  • Broyden's Method (for root finding)
  • Newton's method, BFGS, and L-BFGS
  • Gradient descent: basic, momentum, Adam, AdaMax, Nadam, NadaMax, and more
  • Nonlinear Conjugate Gradient
  • Nelder-Mead
  • Differential Evolution (DE)
  • Particle Swarm Optimization (PSO)

Author: Keith O'Hara


Download and Installation

  • The source code is available on GitHub.

The library can be installed on Unix-alike systems via the standard ./configure && make method:

# clone optim
git clone -b master --single-branch https://github.com/kthohr/optim ./optim
# build and install
cd ./optim
./configure -i "/usr/local" -p
make install

The last line will install OptimLib into /usr/local

Configuration options: (see ./configure -h)

  • -h print help
  • -i install path; default: the build directory
            example: -i "/usr/local"
  • -m specify the BLAS and Lapack libraries to link against;
            examples: -m "-lopenblas" or -m "-framework Accelerate"
  • -o compiler optimization options;
            default: -O3 -march=native -ffp-contract=fast -flto -DARMA_NO_DEBUG
  • -p enable OpenMP parallelization features (recommended)
  • Secondary
  • -c a coverage build (used with Codecov)
  • -d a 'development' build
  • -g a debugging build (optimization flags set to -O0 -g)
  • -R RcppArmadillo compatible build by setting the appropriate R library directories (R, Rcpp, and RcppArmadillo)
            example: -R "/usr/local/R/lib/R/include /usr/local/R/lib/R/library/Rcpp/include /usr/local/R/lib/R/library/RcppArmadillo/include"


OptimLib is built on the Armadillo C++ linear algebra library. The configure script will search for Armadillo files in the standard locations: /usr/include, /usr/local/include, /opt/include, /opt/local/include. If the Armadillo header files are installed elsewhere, set the following environment variable before running configure:

export ARMA_INCLUDE_PATH=/path/to/armadillo

Otherwise the build script will download the required files from the Armadillo GitLab repository.