ceres solver ceres solver (http://ceres-solver.org/) is a non-linear least squares solver published by google. It seems to be named after the planet ceres was discovered by the method of least squares.
I will leave the detailed explanation to others. The least squares method is the problem of finding $ x \ in \ Re ^ n $ that minimizes the expression expressed by the sum of squares as follows.
Minimize:
For example, if $ x = [a, b]; a, b \ in \ Re $, $ f_i (a, b) = y_i-(at_i + b) $
Minimize:
It becomes. This is the problem of finding the straight line $ y = ax + b $ that best fits $ (t_i, y_i) $. This example is a linear least squares method, but ceres is a solver that can handle this $ f_i (x) $ even with a nonlinear function.
Ceres is a solver that specializes in solving least squares. You can give upper and lower bounds to each variable, but you cannot give more constraints (equal constraints, inequality constraints, etc.). If it is necessary to give constraints, it is necessary to use a solver that can solve quadratic programming problems (or Lagrange relaxation). Of course, global optimality is not guaranteed for non-convex problems, but it is possible to find (local) solutions. It is also possible to give an arbitrary initial value.
Well, I'm talking about wanting to use it from python, which is the main subject, but is there a better way? This is an article. Because ** I couldn't find a wrapper library that I could use. ** (It seems that there are some that are published on Cython, but I have no experience with the unknown library & Cython) So the following is an introduction to the method I'm using for the time being. ** Please let me know if there is a better way. ** **
** My solution is to use Boost.numpy. ** ** I'm ashamed to say that I haven't done much in C ++, so I've only heard the name, but Boost seems to be a collection of various libraries. My understanding is that Boost.python is a wrapper library for calling C ++ functions and classes from python, and Boost.numpy is a wrapper library that allows you to pass numpy's ndarray and matrix to C ++ functions. To be honest, if you know the existence of this library, the rest is easy. After all, the C ++ part can write native (?) Code, so the learning cost is almost zero. I have to write both C code and python code, so it is doubtful that I can use ceres from python ...
I myself define the minimum optimization part with a C function, and implement the rest with python. Personally, I am satisfied with the current implementation method for the time being, it is very wide because it can basically call any function of C ++ (although it seems that classes etc. can be wrapped in the library) as well as ceres. I think that has spread.
For Boost.numpy, I referred to the following. There was also an example of CMakeLists, which was very helpful.
The tutorial alone is easy enough to understand about Ceres.
Recommended Posts