• Stars
    star
    830
  • Rank 54,934 (Top 2 %)
  • Language
    C++
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a lightweight header-only C++17 library of numerical optimization methods for nonlinear functions based on Eigen

CppOptimizationLibrary (A header-only C++17 optimization library)

Build Status

It has been now 6 years since the initial release. I did some mistakes in the previous design of this library and some features felt a bit ad-hoc. Given that C++14 is around and C++17 will become mainstream, I will take the opportunity to correct some of these mistakes and simplify things here in this v2-branch.

This branch is under development.

For the previous fully-tested version please refer to the master-branch of this repository.

Have you ever looked for a C++ function fminsearch, which is easy to use without adding tons of dependencies and without editing many setting-structs and without dependencies?

Want a full example?

    using FunctionXd = cppoptlib::function::Function<double>;

    class Rosenbrock : public FunctionXd {
      public:
        EIGEN_MAKE_ALIGNED_OPERATOR_NEW

        double operator()(const Eigen::VectorXd &x) const {
            const double t1 = (1 - x[0]);
            const double t2 = (x[1] - x[0] * x[0]);
            return   t1 * t1 + 100 * t2 * t2;
        }
    };
    int main(int argc, char const *argv[]) {
        using Solver = cppoptlib::solver::Bfgs<Rosenbrock>;

        Rosenbrock f;
        Eigen::VectorXd x(2);
        x << -1, 2;

        // Evaluate
        auto state = f.Eval(x);
        std::cout << f(x) << " = " << state.value << std::endl;
        std::cout << state.x << std::endl;
        std::cout << state.gradient << std::endl;
        if (state.hessian) {
          std::cout << *(state.hessian) << std::endl;
        }

        std::cout << cppoptlib::utils::IsGradientCorrect(f, x) << std::endl;
        std::cout << cppoptlib::utils::IsHessianCorrect(f, x) << std::endl;

        Solver solver;

        auto [solution, solver_state] = solver.Minimize(f, x);
        std::cout << "argmin " << solution.x.transpose() << std::endl;
        std::cout << "f in argmin " << solution.value << std::endl;
        std::cout << "iterations " << solver_state.num_iterations << std::endl;
        std::cout << "solver status " << solver_state.status << std::endl;
        return 0;
    }

To use another solver, simply replace BfgsSolver by another name.

Changes

  • Instead of nesting information in each class, this implementation will handle and update states of functions and solvers.
  • This will follow clang-format google-code-style and will be compliant cpplint.
  • This will drop Support for TensorFlow and Matlab (maybe Python will be an option).

References

L-BFGS-B: A LIMITED MEMORY ALGORITHM FOR BOUND CONSTRAINED OPTIMIZATION Richard H. Byrd, Peihuang Lu, Jorge Nocedal and Ciyou Zhu

L-BFGS: Numerical Optimization, 2nd ed. New York: Springer J. Nocedal and S. J. Wright

Citing this implementation

I see some interests in citing this implementation. Please use the following bibtex entry, if you consider to cite this implementation:

@misc{wieschollek2016cppoptimizationlibrary,
  title={CppOptimizationLibrary},
  author={Wieschollek, Patrick},
  year={2016},
  howpublished={\url{https://github.com/PatWie/CppNumericalSolvers}},
}

More Repositories

1

tensorflow-cmake

TensorFlow examples in C, C++, Go and Python without bazel but with cmake and FindTensorFlow.cmake
CMake
443
star
2

cuda-design-patterns

Some CUDA design patterns and a bit of template magic for CUDA
C++
130
star
3

tensorflow-recipes

A collection of TensorFlow (Tensorpack) implementations of recent deep learning approaches including pretrained models. (FlowNet 2, PWC, PointNet, EnhanceNet)
Python
79
star
4

cluster-smi

nvidia-smi but for an entire GPU cluster
C++
65
star
5

saccade

A sophisticated scientific image viewer for Linux with OpenGL support and synchronized viewports
C++
39
star
6

tf_zmq

TensorFlow operation for reading data from sockets (lightweight c++)
C++
33
star
7

digitalmusicstand

web based music sheet viewer (go, pdfjs) as a single binary
JavaScript
28
star
8

paperhero

webapp written in python to manage pdf collections and notes
CSS
28
star
9

pylint

Self-hosted GitHub Integration for new Check API, Commit Status and Python linting
Go
6
star
10

GitLab-LaTeX-CI

webhook handler for latex-auto-builder
PHP
6
star
11

cluster-top

same as top but for multiple machines
Go
3
star
12

ros-core-rs

This Rust library provides a standalone implementation of the ROS (Robot Operating System) core, allowing you to build ROS nodes entirely in Rust without needing other ROS dependencies. Start the ROS core, run any ROS stack, and use the provided examples to create publishers and subscribers. Contributions are welcome!
Rust
3
star
13

tfGo

Independent efficient re-Implementation AlphaGo SL policy network
C
3
star
14

include-guard.nvim

Add cpplint include guard to header files in neovim
Lua
2
star
15

svelte-konvajs

svelte wrapper for konvajs
Svelte
2
star
16

cpuinfo

read cpu usage in golang (hopefully in an effective way)
Go
2
star
17

StaticAnalysis

OpenSource static disassembler using QT5 (merged in x64dbg)
C++
2
star
18

tensorflow-serving-lite

TensorFlow-Serving-Lite written in Go
Go
2
star
19

scramble

Obfuscate integers
Go
2
star
20

RobustKernelPaths

ICML paper: Robust and Efficient Kernel Hyperparameter Paths with Guarantees
C++
2
star
21

symphony-web

a small webapp for solving AMPL models using SYMPHONY from COIN-OR
JavaScript
1
star
22

nvprof2json

Go
1
star