Commit Graph

138 Commits

Author SHA1 Message Date
Sameer Agarwal 3d933750a7 Deprecate Solver::Options::num_linear_solver_threads
1. Solver::Options::num_threads now controls parallelism in Ceres
   Solver. The user specified value of
   Solver::Options::num_linear_solver_threads is ignored.
2. If the user specifies Solver::Options::num_linear_solver_threads
   and it is different from Solver::Options::num_threads,
   a warning is printed.
3. Solver::Summary:num_linear_solver_threads_given and
   Solver::Summary::num_linear_solver_threads_used are also
   deprecated and are always set to Solver::Summary::num_threads_given
   and Solver::Summary::num_threads_used.

Change-Id: I20b9336d9336e400e6f0a15b63857c0c43eb271c
2018-02-27 20:38:05 -08:00
Keir Mierle a3b1e19c2c Add examples to the Bazel build
Also moves the gflags namespace define
into the ceres_library() target.

Change-Id: Ibb8f3fdd9a8c371fe96b475f752f8320ffe63cdc
2018-02-25 14:55:27 -08:00
Mike Vitus 30b862d126 Fixes the pose graph example documentation.
Change-Id: Ia20f1463c042785bdae32568de77750d41963c3c
2018-01-19 16:06:00 -08:00
Rodrigo Queiro 237eb17bdd Consistently use quotes to include Eigen
This makes these files match the convention in the rest of the codebase.

Change-Id: I3a0634274e0e604c575dd3c78fa87f485770e7ff
2018-01-12 18:25:16 +00:00
Sameer Agarwal 030b41dd0e Improve compatibility with ceres::Solver
1. Default linear solver is Eigen::LDLT
2. Options::max_iterations -> Options::max_num_iterations
3. Options::error_threshold -> Options::cost_threshold
4. Options::relative_step_threshold -> Options::parameter_threshold
5. Options::initial_scale_factor -> Options::initial_trust_region_radius
6. The default values of the above parameters have been changed
   to match those in ceres::Solver::Options
7. Status::RUNNING has been removed
8. Update now returns a bool instead of a Status enum and
   the status handling has been included in the main loop.
9. Summary::gradient_norm has been changed to Summary::gradient_max_norm
   to match the convergence test
10. A member variable cost_ has been added which is computed by Update
11. The test for parameter_tolerance based convergence is made
    more robust near zero.
12. Use of double has been replaced by Scalar.
13. Minor clang-formatting

Change-Id: I3cb0e2fd0a0204476bb8718761dc740cdf5e42ce
2017-10-22 21:40:49 -07:00
Sameer Agarwal 75570a599a Remove an extraneous blank
Change-Id: Id089741300b549b2afe6d591d78f5fe3fdda6c43
2017-10-19 20:24:26 +00:00
Keir Mierle b485002bb7 Replace template use of >>
Older compilers do not support >> to terminate
templates, only > >. Ceres supports old compilers.

Change-Id: I7e43dc9fdac06507b32dd0c9bf1a3bc2a544916b
2017-10-14 16:08:17 -07:00
Sameer Agarwal f87dfe9dde Refactor nist.cc to be compatible with TinySolver
Change-Id: Iec0455ff9fe327fe75dc63f5b80c2ecca2c48e55
2017-10-14 15:58:58 -07:00
Alex Stewart 0aad590005 Fix typo in definition of f3 in powell example (x4 -> x3).
- This was reported as issue #307 by versatran01.

Change-Id: I2c8bbd3466d46b550f81fdadb8b1f4e23b858162
2017-08-13 14:59:41 +01:00
Sameer Agarwal f93ad78f23 Lint changes from William Rucklidge
Change-Id: I54ee9d7b90232bb0139398a78a09cf4035d23ea6
2017-05-31 19:44:23 -07:00
Tal Ben-Nun 375a385b2b Revert MSVC compile fix as it is already addressed in CMakeLists.txt
Change-Id: I2ea89c6de7593d77cdf31636686beb05ae6833e9
2017-03-20 14:23:35 +01:00
Tal Ben-Nun 66be7c3a0e MSVC compile fix for ellipse approximation
Change-Id: Ib67a2219ee171770f2ab96dcc261a610d515b6a6
2017-03-20 00:50:43 +01:00
Sameer Agarwal 62a70bc74c Lint cleanup from William Rucklidge
Change-Id: I11ebf9bdb09cfd465a32a61e0a9a045ab650deac
2017-02-15 11:01:27 -08:00
Sameer Agarwal d05515b3eb Remove spurious conversion from doubles to Jets.
Binary operations between Jets and doubles are well defined
and should not require an explicit conversion to Jets to work.
This was an oversight earlier and lead to overzealous conversions
all over our in our example code.

Change-Id: I1799770818e136edfc0a5802d86037ce9aec4923
2017-02-10 11:36:58 -08:00
Alex Stewart 29888185a1 Make gflags a public dependency of Ceres if it and glog are found.
- Previously we were not listing gflags as a public dependency of Ceres
  if it and glog were found (and MINIGLOG was not being used). This
  does not reflect that if glog was compiled with gflags then it will
  #include gflags/gflags.h in glog/logging.h, thus making gflags a
  public dependency of anything linking against glog.
- On *nix OSs if glog/gflags are shared libraries this did not result
  in a link error when compiling Ceres as the gflags symbols were
  indirectly resolved.  However, on MSVC this is not the case, and this
  could result in unresolved gflags symbol link errors when compiling
  Ceres.
- Now we add gflags to the list of public Ceres dependencies if both
  glog and gflags are found (and MINIGLOG is not enabled).

Change-Id: I5ce6038fa816781cc81b378522068dc563d29c51
2016-11-20 19:44:46 +00:00
Mike Vitus 716f049a7b Convert pose graph 2D example to glog and gflags.
Change-Id: I0ed75a60718ef95199bb36f33d9eb99157d11d40
2016-08-31 13:55:58 -07:00
David Gossow 46c5ce89dd Fix compiler errors on some systems
This fixes some signed-unsigned comparisons and a missing header
include.

Change-Id: Ieb2bf6e905faa74851bc4ac4658d2f1da24b6ecc
2016-08-31 20:26:53 +00:00
Sameer Agarwal 4b6ad5d88e Use ProductParameterization in bundle_adjuster.cc
Previously, when using a quaternion to parameterize the camera
orientation, the camera parameter block was split into two
parameter blocks. One for the rotation and another for the
translation and intrinsics. This was to enable the use of the
Quaternion parameterization.

Now that we have a ProductParameterization which allows us
to compose multiple parameterizations, this is no longer needed
and we use a size 10 parameter block instead.

This leads to a more than 2x improvements in the linear solver time.

Change-Id: I78b8f06696f81fee54cfe1a4ae193ee8a5f8e920
2016-08-31 05:46:44 -07:00
Mike Vitus f6df6c05dd Add an example for modeling and solving a 3D pose graph SLAM problem.
Change-Id: I750ca5f20c495edfee5f60ffedccc5bd8ba2bb37
2016-08-22 15:26:02 -07:00
Mike Vitus fd7cab65ef Fix typos in the pose graph 2D example.
Change-Id: Ie024ff6b6cab9f2e8011d21121a91931bd987bd1
2016-08-10 09:37:47 -07:00
Mike Vitus f554681bf2 Add an example for modeling and solving a 2D pose graph SLAM problem.
Change-Id: Ia89b12af7afa33e7b1b9a68d69cf2a0b53416737
2016-08-05 14:22:27 -07:00
Mike Vitus 16980b4fec Delete the remove_definitons command from sampled_functions
CMakeLists.txt because it will be inherited from the top level examples
CMakeLists.txt.

Change-Id: I25593587df0ae84fd8ddddc589bc2a13f3777427
2016-07-15 13:44:56 -07:00
Mike Vitus a04490be97 Add readme for the sampled_function example.
Change-Id: I9468b6a7b9f2ffdd2bf9f0dd1f4e1d5f894e540c
2016-07-14 17:06:38 -07:00
Sameer Agarwal 7ec8ba2a64 Saner tolerances & stricter LRE test.
NIST recommends greater than 4 digits rather than greater than
or equal to 4 digits to declare that the solve was successful.

Change-Id: I5c65e6e791508b95b692c23dafd3833d73cd0487
2016-01-03 22:44:48 -08:00
Tal Ben-Nun 4f049db7c2 Adaptive numeric differentiation using Ridders' method.
This method numerically computes function derivatives in different
scales, extrapolating between intermediate results to conserve function
evaluations. Adaptive differentiation is essential to produce accurate
results for functions with noisy derivatives.

Full changelist:
-Created a new type of NumericDiffMethod (RIDDERS).
-Implemented EvaluateRiddersJacobianColumn in NumericDiff.
-Created unit tests with f(x) = x^2 + [random noise] and
 f(x) = exp(x).

Change-Id: I2d6e924d7ff686650272f29a8c981351e6f72091
2015-08-30 14:06:13 +03:00
Sameer Agarwal 070bba4b43 Lint fixes from William Rucklidge
Change-Id: I719e8852859c970091df842e59c44e02e2c65827
2015-08-25 13:37:33 -07:00
Sameer Agarwal 1a740cc787 Add the option to use numeric differentiation to nist and more_garbow_hillstrom
Change-Id: If0a5caef90b524dcf5e2567c5b681987f5459401
2015-08-11 20:16:12 -07:00
Alex Stewart cc8d47aabb Update all CMake to lowercase function name style.
- Updated to new CMake style where function names are all lowercase,
  this will be backwards compatible as CMake function names are
  case insensitive.
- Updated using Emacs' M-x unscreamify-cmake-buffer.

Change-Id: If7219816f560270e59212813aeb021353a64a0e2
2015-08-09 15:18:42 +01:00
Sameer Agarwal 560940fa27 A refactor of the cubic interpolation code
1. Push the boundary handling logic into the underlying array
object. This has two very significant impacts:

a. The interpolation code becomes extremely simple to write
and to test.

b. The user has more flexibility in implementing how out of bounds
values are handled. We provide one default implementation.

Change-Id: Ic2f6cf9257ce7110c62e492688e5a6c8be1e7df2
2015-08-06 14:49:55 -07:00
Alex Stewart 6414bd0279 Add option to use C++11 (not TR1) shared_ptr & unordered_map.
- On at least some compilers, -std=c++11 is required in order to compile
  against std::shared_ptr & std::unordered_map, which resulted in our
  checks failing to find them and using the TR1 versions instead, which
  causes conflicts for users using C++11.
- Now, if the compiler supports it and the user enables the CXX11
  option, we explicitly enable C++11 before searching for shared_ptr &
  unordered_map, which means we should always find the C++11 versions
  if they are available.
- As use of CXX11 results in a version of Ceres that must be used with
  -std=c++11 for GCC & Clang, we roll this into the Ceres target when
  the version of CMake supports this, otherwise we warn the user they
  will have to do this themselves.
- CXX11 is OFF by default, to ensure that the behaviour of Ceres is
  unchanged from before.

Change-Id: I157ea7a4fadc6bc02da176b8e771f1f327ccaf78
2015-06-22 08:54:40 +00:00
Sameer Agarwal 6d1dedad50 Fix an incorrect usage message in bundle_adjuster.cc
Change-Id: I66889ac8e52dd3baaee9e80cb04b7a8575537249
2015-06-10 09:26:31 -04:00
Sameer Agarwal 2175d025a6 Make the robust curve fitting example robust.
Change-Id: Iffcde8f168b7cd68e56f351c43088d7aef1e5e2f
2015-04-27 06:54:12 -07:00
Sameer Agarwal 365084f976 Lint changes from William Rucklidge.
Change-Id: I5a9683333fbab189058076cb2053f8f7afc7096a
2015-04-16 12:35:51 -07:00
pmoulon 0b9147692d Fix typo Matlab->Meshlab.
Change-Id: If64a1e2bd10637eac8ed74a5c43cfa133c7aa575
2015-04-14 14:51:42 +02:00
pmoulon 9536c967a0 Add PLY file logger before and after BA in order to ease visual comparison.
Change-Id: Ib14e8f4b2de686ab6494de270458392f81a0b946
2015-04-14 12:12:21 +00:00
Keir Mierle 7492b0d8de Update copyright headers with new year and URL
Since Ceres is moving to using GitHub for issues, and the Google
Code URL in the current copyright header will soon become invalid,
update all the headers.

Change-Id: I1fce70375d1bcf098591f07b4d8f01a5c1e0789c
2015-03-18 05:43:23 +00:00
Sameer Agarwal c62bb845cd Fix sampled_function.cc to use the new CubicInterpolator API.
Change-Id: I1b2063505dc2296c141989c93a939175d5dba7e1
2015-02-08 10:56:39 -08:00
Sameer Agarwal 940c0032eb Fix a typo in sampled_function.cc
Thanks to Pablo Speciale for reporting this.

Change-Id: Icd526856f91dba98f7abf86b098b210a89556445
2015-01-29 11:53:27 -08:00
Sameer Agarwal 2bf6fbcd37 Example code for cubic interpolation.
Example code demonstrates how a sampled function can be
minimized. Also, in the process uncovered some deficiencies
in the CubicInterpolator and BicubicInterpolator interfaces and
fixed them.

Change-Id: I18c8f670fbee076bf1e94d1f45c7477fd71640e8
2015-01-28 07:26:06 -08:00
Sameer Agarwal 74fd412420 Lint changes from William and Jim.
Change-Id: Ida89b67c66b3bc7683d95e63646dfb2f9679d1b1
2015-01-08 11:45:15 -08:00
Sameer Agarwal bcc865f81c Remove using namespace std;
For historical reasons we had a "using namespace std;" in port.h. This
is generally a bad idea. So removing it and along the way doing a bunch
of cpplint cleanup.

Change-Id: Ia125601a55ae62695e247fb0250df4c6f86c46c6
2015-01-07 14:26:53 -08:00
Sameer Agarwal 68222eb819 Lint cleanup from Jim Roseborough
Change-Id: Ic55b8e48110bc651ae942d34fe5402a6e0422fe3
2014-12-01 12:31:46 -08:00
Alex Stewart 9631c69354 Fix missing include in libmv_bundle_adjuster on OSX.
- If compiling without glog (but with gflags) on OSX, unistd.h is
  required for close() et al, when using glog this was pulled in
  indirectly.

Change-Id: I8f0807d98479e386921fb48da30683d027d4bc61
2014-11-29 16:38:59 +00:00
Sameer Agarwal 882aea18ae Add more problems from More Garbow Hillstrom.
Also try solving the unconstrained problems from
three different starting points.

Change-Id: I8343a4dd979a3e8733981819915d25d6e9fcf993
2014-11-29 08:38:08 -08:00
Alex Stewart cbe694505e Autodetect gflags namespace.
- At version 2.1, gflags changed from using the google namespace, to
  using gflags by default.  However, it can be configured at build time
  to be something else (which would be google for legacy compatibility
  unless you were evil).
- Ceres previously assumed that gflags was in the google namespace.
- Now, FindGFlags.cmake extracts the namespace when gflags.h is found
  and saves it in GFLAGS_NAMESPACE.
- When building the tests and examples that require gflags,
  CERES_GFLAGS_NAMESPACE is defined to be the detected namespace, and
  all tests/examples now use CERES_GFLAGS_NAMESPACE:: instead of
  google:: when calling gflags functions.

Change-Id: Ia333df7a7e2f08ba9f26bbd339c3a785b88f04c4
2014-11-27 09:56:37 +00:00
Sameer Agarwal 352e4dd182 Stricter options checking breaks nist.cc
Fix the breakage!

Change-Id: Ic263852cd7c8a9615d8d3dab43c6cf7d81fc8d40
2014-11-17 06:50:41 -08:00
Sameer Agarwal b44cfdef25 Let ITERATIVE_SCHUR use an explicit Schur Complement matrix.
Up till now ITERATIVE_SCHUR evaluates matrix-vector products
between the Schur complement and a vector implicitly by exploiting
the algebraic expression for the Schur complement.

This cost of this evaluation scales with the number of non-zeros
in the Jacobian.

For small to medium sized problems there is a sweet spot where
computing the Schur complement is cheap enough that it is much
more efficient to explicitly compute it and use it for evaluating
the matrix-vector products.

This changes implements support for an explicit Schur complement
in ITERATIVE_SCHUR in combination with the SCHUR_JACOBI preconditioner.

API wise a new bool Solver::Options::use_explicit_schur_complement
has been added.

The implementation extends the SparseSchurComplementSolver to use
Conjugate Gradients.

Example speedup:

use_explicit_schur_complement = false

Time (in seconds):
Preprocessor                            0.585

  Residual evaluation                   0.319
  Jacobian evaluation                   1.590
  Linear solver                        25.685
Minimizer                              27.990

Postprocessor                           0.010
Total                                  28.585

use_explicit_schur_complement = true

Time (in seconds):
Preprocessor                            0.638

  Residual evaluation                   0.318
  Jacobian evaluation                   1.507
  Linear solver                         5.930
Minimizer                               8.144

Postprocessor                           0.010
Total                                   8.791

Which indicates an end-to-end speedup of more than 3x, with the linear
solver being sped up by > 4x.

The idea to explore this optimization was inspired by the recent paper:

Mining structure fragments for smart bundle adjustment
L. Carlone, P. Alcantarilla, H. Chiu, K. Zsolt, F. Dellaert
British Machine Vision Conference, 2014

which uses a more complicated algorithm to compute parts of the
Schur complement to speed up the matrix-vector product.

Change-Id: I95324af0ab351faa1600f5204039a1d2a64ae61d
2014-09-29 10:29:32 -07:00
Sameer Agarwal 092b94970a Add GradientProblem and GradientProblemSolver.
The line search minimizer in Ceres does not require that the
problems that is solving is a sum of squares. Over the past
year there have been multiple requests to expose this algorithm
on its own so that it can be used to solve unconstrained
non-linear minimization problems on its own.

With this change, a new optimization problem called
GradientProblem is introduced which is basically a thin
wrapper around a user defined functor that evaluates cost
and gradients (FirstOrderFunction) and an optional LocalParameterization.

Corresponding to it, a GradientProblemSolver and its associated
options and summary structs are introduced too.

An example that uses the new API to find the minimum of Rosenbrock's
function is also added.

Change-Id: I42bf687540da25de991e9bdb00e321239244e8b4
2014-09-15 10:21:09 -07:00
Sameer Agarwal b766177bab Remove support for Solver::Options::solver_log.
This is not really used and if needed can be implemented
in user code.

Change-Id: I56328d51c9d3788f90c751ff9c3a5937989f6ee0
2014-05-29 21:59:37 +00:00
Sergey Sharybin 36c2ce87d1 Libmv 2D homography estimation example application
Add an example application of homography matrix estimation
from a 2D euclidean correspondences which is done in two
steps:

- Coarse algebraic estimation
- Fine refinement using Ceres minimizer

Nothing terribly exciting apart from an example of how to
use user callbacks.

User callback is used here to stop minimizer when average
of symmetric geometric distance becomes good enough.
This might be arguable whether it's the best way to go
(in some cases you would want to stop minimizer when
maximal symmetric distance is lower than a threshold) but
for a callback usage example it's good enough to stick
to current logic.

Change-Id: I60c8559cb10b001a0eb64ab71920c08bd68455b8
2014-05-15 15:17:14 +02:00