Docs » Why?
Why?
Code Quality - Ceres Solver has been used in production at
Google for more than four years now. It is clean, extensively
tested and well documented code that is actively developed
and supported.
Modeling API - It is rarely the case that one starts with the
exact and complete formulation of the problem that one is
trying to solve. Ceres’s modeling API has been designed so that
the user can easily build and modify the objective function, one
term at a time. And to do so without worrying about how the
solver is going to deal with the resulting changes in the
sparsity/structure of the underlying problem.
Derivatives Supplying derivatives is perhaps the most
tedious and error prone part of using an optimization
library. Ceres ships with automatic and numeric
differentiation. So you never have to compute derivatives
by hand (unless you really want to). Not only this, Ceres
allows you to mix automatic, numeric and analytical
derivatives in any combination that you want.
Robust Loss Functions Most non-linear least squares
problems involve data. If there is data, there will be
outliers. Ceres allows the user to shape their residuals
using a LossFunction
LossFunction to reduce the influence of outliers.
Local Parameterization In many cases, some parameters lie
on a manifold other than Euclidean space, e.g., rotation
matrices. In such cases, the user can specify the geometry
of the local tangent space by specifying a
LocalParameterization object.
LocalParameterization
Solver Choice Depending on the size, sparsity structure, time
& memory budgets, and solution quality requiremnts, different
optimization algorithms will suit different needs. To this end,
Ceres Solver comes with a variety of optimization algorithms:
Trust Region Solvers - Ceres supports Levenberg-
Marquardt, Powell’s Dogleg, and Subspace dogleg
methods. The key computational cost in all of these
methods is the solution of a linear system. To this end Ceres
ships with a variety of linear solvers - dense QR and dense
Cholesky factorization (using Eigen or LAPACK) for dense
problems, sparse Cholesky factorization (SuiteSparse,
CXSparse or Eigen) for large sparse problems custom Schur
complement based dense, sparse, and iterative linear
solvers for bundle adjustment problems.
Line Search Solvers - When the problem size is so large
that storing and factoring the Jacobian is not feasible or a
low accuracy solution is required cheaply, Ceres offers a
number of line search based algorithms. This includes a
number of variants of Non-linear Conjugate Gradients,
BFGS and LBFGS.
Speed - Ceres Solver has been extensively optimized, with C++
templating, hand written linear algebra routines and OpenMP
or TBB based multithreading of the Jacobian evaluation and
the linear solvers.
Solution Quality Ceres is the best performing solver on the
NIST problem set used by Mondragon and Borchers for
benchmarking non-linear least squares solvers.
Covariance estimation - Evaluate the sensitivity/uncertainty
of the solution by evaluating all or part of the covariance
matrix. Ceres is one of the few solvers that allows you to to do
this analysis at scale.
Community Since its release as an open source software,
Ceres has developed an active developer community that
contributes new features, bug fixes and support.
Portability - Runs on Linux, Windows, Mac OS X, Android and
iOS.
BSD Licensed The BSD license offers the flexibility to ship
your application
Docs » Installation
Installation
Getting the source code
You can start with the latest stable release . Or if you want the latest version,
you can clone the git repository
git clone https://ceres-solver.googlesource.com/ceres-solver
Dependencies
Ceres relies on a number of open source libraries, some of which are optional.
For details on customizing the build process, see Customizing the build .
Eigen 3.2.2 or later strongly recommended, 3.1.0 or later required.
! Note
Ceres can also use Eigen as a sparse linear algebra library. Please see the
documentation for EIGENSPARSE for more details.
CMake 2.8.0 or later. Required on all platforms except for Android.
glog 0.3.1 or later. Recommended
glog is used extensively throughout Ceres for logging detailed information
about memory allocations and time consumed in various parts of the solve,
internal error conditions etc. The Ceres developers use it extensively to
observe and analyze Ceres’s performance. glog allows you to control its
behaviour from the command line. Starting with -logtostderr you can add
-v=N for increasing values of N to get more and more verbose and detailed
information about Ceres internals.
Unfortunately, the current version of google-glog does not build using the
Android NDK. So, Ceres also ships with a minimal replacement of glog
called miniglog that can be enabled with the MINIGLOG build option.
So, in an attempt to reduce dependencies, it is tempting to use miniglog on
platforms other than Android. While there is nothing preventing the user
from doing so, we strongly recommend against it. miniglog has worse
performance than glog and is much harder to control and use.
! Note
If you are compiling glog from source, please note that currently, the
unit tests for glog (which are enabled by default) do not compile against
a default build of gflags 2.1 as the gflags namespace changed from
google:: to gflags:: . A patch to fix this is available from here.
gflags. Needed to build examples and tests.
SuiteSparse. Needed for solving large sparse linear systems. Optional;
strongly recomended for large scale bundle adjustment
CXSparse. Similar to SuiteSparse but simpler and slower. CXSparse has no
dependencies on LAPACK and BLAS . This makes for a simpler build process
and a smaller binary. Optional
BLAS and LAPACK routines are needed by SuiteSparse , and optionally used
by Ceres directly for some operations.
TBB is a C++11 template library for parallel programming that optionally can
be used as an alternative to OpenMP. Optional
On UNIX OSes other than Mac OS X we recommend ATLAS, which includes
BLAS and LAPACK routines. It is also possible to use OpenBLAS . However,
one needs to be careful to turn off the threading inside OpenBLAS as it
conflicts with use of threads in Ceres.
Mac OS X ships with an optimized LAPACK and BLAS implementation as part
of the Accelerate framework. The Ceres build system will automatically
detect and use it.
For Windows things are much more complicated. LAPACK For Windows has
detailed instructions..
Optional but required for SuiteSparse .
Linux
We will use Ubuntu as our example linux distribution.
! Note
Up to at least Ubuntu 14.04, the SuiteSparse package in the official package
repository (built from SuiteSparse v3.4.0) cannot be used to build Ceres as a
shared library. Thus if you want to build Ceres as a shared library using
SuiteSparse, you must perform a source install of SuiteSparse or use an
external PPA (see bug report here). It is recommended that you use the
current version of SuiteSparse (4.2.1 at the time of writing).
Start by installing all the dependencies.
# CMake
sudo apt-get install cmake
# google-glog + gflags
sudo apt-get install libgoogle-glog-dev
# BLAS & LAPACK
sudo apt-get install libatlas-base-dev
# Eigen3
sudo apt-get install libeigen3-dev
# SuiteSparse and CXSparse (optional)
# - If you want to build Ceres as a *static* library (the default)
# you can use the SuiteSparse package in the main Ubuntu package
# repository:
sudo apt-get install libsuitesparse-dev
# - However, if you want to build Ceres as a *shared* library, you must
# add the following PPA:
sudo add-apt-repository ppa:bzindovic/suitesparse-bugfix-1319687
sudo apt-get update
sudo apt-get install libsuitesparse-dev
We are now ready to build, test, and install Ceres.
tar zxf ceres-solver-1.14.0.tar.gz
mkdir ceres-bin
cd ceres-bin
cmake ../ceres-solver-1.14.0
make -j3
make test
# Optionally install Ceres, it can also be exported using CMake which
# allows Ceres to be used without requiring installation, see the
documentation
# for the EXPORT_BUILD_DIR option for more information.
make install
You can also try running the command line bundling application with one of the
included problems, which comes from the University of Washington’s BAL
dataset [Agarwal].
bin/simple_bundle_adjuster ../ceres-solver-1.14.0/data/problem-16-22106-
pre.txt
This runs Ceres for a maximum of 10 iterations using the DENSE_SCHUR linear
solver. The output should look something like this.
iter cost cost_change |gradient| |step| tr_ratio
tr_radius ls_iter iter_time total_time
0 4.185660e+06 0.00e+00 1.09e+08 0.00e+00 0.00e+00
1.00e+04 0 7.59e-02 3.37e-01
1 1.062590e+05 4.08e+06 8.99e+06 5.36e+02 9.82e-01
3.00e+04 1 1.65e-01 5.03e-01
2 4.992817e+04 5.63e+04 8.32e+06 3.19e+02 6.52e-01
3.09e+04 1 1.45e-01 6.48e-01
3 1.899774e+04 3.09e+04 1.60e+06 1.24e+02 9.77e-01
9.26e+04 1 1.43e-01 7.92e-01
4 1.808729e+04 9.10e+02 3.97e+05 6.39e+01 9.51e-01
2.78e+05 1 1.45e-01 9.36e-01
5 1.803399e+04 5.33e+01 1.48e+04 1.23e+01 9.99e-01
8.33e+05 1 1.45e-01 1.08e+00
6 1.803390e+04 9.02e-02 6.35e+01 8.00e-01 1.00e+00
2.50e+06 1 1.50e-01 1.23e+00
Ceres Solver v1.14.0 Solve Report
----------------------------------
Original Reduced
Parameter blocks 22122 22122
Parameters 66462 66462
Residual blocks 83718 83718
Residual 167436 167436
Minimizer TRUST_REGION
Dense linear algebra library EIGEN
Trust region strategy LEVENBERG_MARQUARDT
Given Used
Linear solver DENSE_SCHUR DENSE_SCHUR
Threads 1 1
Linear solver threads 1 1
Linear solver ordering AUTOMATIC 22106, 16
Cost:
Initial 4.185660e+06
Final 1.803390e+04
Change 4.167626e+06
Minimizer iterations 6
Successful steps 6
Unsuccessful steps 0
Time ((in seconds)):
Preprocessor 0.261
Residual evaluation 0.082
Jacobian evaluation 0.412
Linear solver 0.442
Minimizer 1.051
Postprocessor 0.002
Total 1.357
Termination: CONVERGENCE ((Function tolerance
reached. |cost_change|/cost: 1.769766e-09 <== 1.000000e-06))
Mac OS X
! Note
Ceres will not compile using Xcode 4.5.x (Clang version 4.1) due to a bug in
that version of Clang. If you are running Xcode 4.5.x, please update to Xcode
>= 4.6.x before attempting to build Ceres.
On OS X, you can either use MacPorts or Homebrew to install Ceres Solver.
If using MacPorts, then
sudo port install ceres-solver
will install the latest version.
If using Homebrew and assuming that you have the homebrew/science [1] tap
enabled, then
brew install ceres-solver