Commit Graph

43 Commits

Author SHA1 Message Date
NeroBurner a548766d14 Use glfags target
Update the usage of Google Flags (gflags) library the same way Glog
updated it [1]. This pushes the minimum required gflags version to
v2.2.0.

Remove the ceres specific define of CERES_GFLAGS_NAMESPACE and directly
use GFLAGS_NAMESPACE defined in gflags/gflags_declare.h [2].

In CeresConfig.cmake the hard coded paths for gflags are ommited.
Instead we rely on the gflagsConfig file to get closer to a relocatable
CeresConfig.cmake.
Furthermore use the find_dependency() [4] cmake function specifically
created for cmake-config files.

This change builds upon the explicit PUBLIC/PRIVATE link change [3].

[1] https://github.com/google/glog/pull/199
[2] https://github.com/gflags/gflags/blob/d9b184bd0026b16bb4c2fded75d56fb2cce50d66/src/gflags_declare.h.in#L43
[3] https://ceres-solver-review.googlesource.com/c/ceres-solver/+/16220
[4] https://cmake.org/cmake/help/latest/module/CMakeFindDependencyMacro.html

Change-Id: I9861a2699f2702bf1a5e99d07863a7e6639b7c39
2019-12-12 14:00:59 +00:00
Sergey Sharybin 54ba6c27b5 Fix missing declaration warnings in Ceres code
This commit includes the following:

- Changes to CMake to make it safer to see which compiler flags are supported,
  so this way we do not need to worry about version checks in CMake.

- Unix platforms (which includes both Linux and Apple as far as i can tell)
  will now enable -Wmissing-declarations warning for the whole Ceres.

- Changes in all sources to solve missing declaration warning. In most cases
  it was either matter of using static qualifier or moving functions to an
  anonymous namespace.

  In one case the function got removed, since it seems to be unused.

  Additionally, in slam examples there was a non-inlined function implementation
  in a header, which is a direct way to cause linking errors if other .cc file
  will include that helper header.

- All third party sources (which is currently only gmock) has this extra
  paranoid warning disabled.

This warning is important in the following cases:

- Detect helper functions which are not needed anymore.
- Avoid unnoticed pollution of namespace.
- Avoid bad level calls.
- Avoid missing updates in header files after changes in implementation file.
- Helps integrating Ceres into software where paranoid warnings are important.

Change-Id: I9b1044aced3910d8c6b2356cfe2bf57f3c8c58db
2019-04-23 12:16:28 +02:00
Sameer Agarwal f973e107d2 Enable mixed precision solves.
1. Add Solver::Options::use_mixed_precision_solves,
   and Solver::Options::max_num_refinement_iterations.
2. Make SparseCholesky::Create return a unique_ptr.
3. SparseCholesky::Create now takes LinearSolver::Options
   as an argument.
4. IterativeRefiner's constructor does not require num_cols
   as an argument.
5. SparseNormalCholeskySolver now uses a separate rhs vector.

This basic implementation results in a 10% reduction in solver time
and 30% reduction in linear solver memory usage.

Change-Id: I6830f32cae2febf082d2733262eb2c9f0482b0ea
2018-04-10 11:01:38 -07:00
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
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
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 365084f976 Lint changes from William Rucklidge.
Change-Id: I5a9683333fbab189058076cb2053f8f7afc7096a
2015-04-16 12:35:51 -07: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
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 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 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
Sameer Agarwal b1668067f1 Variety of changes to documentation and example code.
1. Update version history.
2. Minor changes to the tutorial to reflect the bounds constrained
   problem.
3. Added static factory methods to the SnavelyReprojectionError.
4. Removed relative gradient tolerance from types.h as it is
   not true anymore.

Change-Id: I8de386e5278a008c84ef2d3290d2c4351417a9f1
2014-04-29 09:09:00 -07:00
Sameer Agarwal bb05be341b Solver::Options uses shared_ptr to handle ownership.
Solver::Options::linear_solver_ordering and
Solver::Options::inner_iteration_ordering
were bare pointers even though Solver::Options took ownership of these
objects.

This lead to buggy user code and the inability to copy Solver::Options
objects around.

With this change, these naked pointers have been replaced by a
shared_ptr object which will managed the lifetime of these objects. This
also leads to simplification of the lifetime handling of these objects
inside the solver.

The Android.mk and Application.mk files have also been updated
to use a newer NDK revision which ships with LLVM's libc++.

Change-Id: I25161fb3ddf737be0b3e5dfd8e7a0039b22548cd
2014-04-25 15:54:39 -07:00
Sameer Agarwal f06b9face5 Add support for multiple visibility clustering algorithms.
The original visibility based preconditioning paper and
implementation only used the canonical views algorithm.

This algorithm for large dense graphs can be particularly
expensive. As its worst case complexity is cubic in size
of the graph.

Further, for many uses the SCHUR_JACOBI preconditioner
was both effective enough while being cheap. It however
suffers from a fatal flaw. If the camera parameter blocks
are split between two or more parameter blocks, e.g,
extrinsics and intrinsics. The preconditioner because
it is block diagonal will not capture the interactions
between them.

Using CLUSTER_JACOBI or CLUSTER_TRIDIAGONAL will fix
this problem but as mentioned above this can be quite
expensive depending on the problem.

This change extends the visibility based preconditioner
to allow for multiple clustering algorithms. And adds
a simple thresholded single linkage clustering algorithm
which allows you to construct versions of CLUSTER_JACOBI
and CLUSTER_TRIDIAGONAL preconditioners that are cheap
to construct and are more effective than SCHUR_JACOBI.

Currently the constants controlling the threshold above
which edges are considered in the single linkage algorithm
are not exposed. This would be done in a future change.

Change-Id: I7ddc36790943f24b19c7f08b10694ae9a822f5c9
2013-10-31 13:22:57 -07:00
Sameer Agarwal d61b68aaac Lint cleanups from William Rucklidge
Change-Id: Ia4756ef97e65837d55838ee0b30806a234565bfd
2013-08-16 17:02:56 -07:00
Sameer Agarwal 367b65e17a Multiple dense linear algebra backends.
1. When a LAPACK implementation is present, then
DENSE_QR, DENSE_NORMAL_CHOLESKY and DENSE_SCHUR
can use it for doing dense linear algebra operations.

2. The user can switch dense linear algebra libraries
by setting Solver::Options::dense_linear_algebra_library_type.

3. Solver::Options::sparse_linear_algebra_library is now
Solver::Options::sparse_linear_algebra_library_type to be consistent
with all the other enums in Solver::Options.

4. Updated documentation as well as Solver::Summary::FullReport
to reflect these changes.

Change-Id: I5ab930bc15e90906b648bc399b551e6bd5d6498f
2013-08-13 14:57:03 -07:00
Sameer Agarwal 1c70ae9aa6 Fix Solver::Summary when line search is used.
Also enable line search in bundle_adjuster.

Change-Id: Ic4343a4334b9f5a6fdeab38d4e3e1f6932bbc601
2013-06-30 12:50:43 -07:00
Sameer Agarwal 9189f4ea4b Enable pre-ordering for SPARSE_NORMAL_CHOLESKY.
Sparse Cholesky factorization algorithms use a fill-reducing
ordering to permute the columns of the Jacobian matrix. There
are two ways of doing this.

1. Compute the Jacobian matrix in some order and then have the
   factorization algorithm permute the columns of the Jacobian.

2. Compute the Jacobian with its columns already permuted.

The first option incurs a significant memory penalty. The
factorization algorithm has to make a copy of the permuted
Jacobian matrix.

Starting with this change Ceres pre-permutes the columns of the
Jacobian matrix and generally speaking, there is no performance
penalty for doing so.

In some rare cases, it is worth using a more complicated
reordering algorithm which has slightly better runtime
performance at the expense of an extra copy of the Jacobian
matrix. Setting Solver::Options::use_postordering to true
enables this tradeoff.

This change also removes Solver::Options::use_block_amd
as an option. All matrices are ordered using their block
structure. The ability to order them by their scalar
sparsity structure has been removed.

Here is what performance on looks like on some BAL problems.

Memory
======
                                     HEAD         pre-ordering
16-22106                      137957376.0          113516544.0
49-7776                        56688640.0           46628864.0
245-198739                   1718005760.0         1383550976.0
257-65132                     387715072.0          319512576.0
356-226730                   2014826496.0         1626087424.0
744-543562                   4903358464.0         3957878784.0
1024-110968                   968626176.0          822071296.0

Time
====
                                     HEAD         pre-ordering
16-22106                              3.8                  3.7
49-7776                               1.9                  1.8
245-198739                           82.6                 81.9
257-65132                            14.0                 13.4
356-226730                           98.8                 95.8
744-543562                          325.2                301.6
1024-110968                          42.1                 37.1

Change-Id: I6b2e25f3fed7310f88905386a7898ac94d37467e
2013-04-19 19:27:23 -07:00
Sameer Agarwal 2c648dbc43 Make examples independent of ceres internals.
Change-Id: I6b6913e067a86fea713646218c8da1439d349d74
2013-03-05 15:37:15 -08:00
Sameer Agarwal 68b32a941c ordering -> linear_solver_ordering.
Change-Id: If4af72da90725db2a2d4f397f4cb671c2e863a98
2012-10-06 23:16:04 -07:00
Sameer Agarwal ba8d967f8c Generalization of the inner iterations algorithm.
Add automatic recursive independent set decomposition.
Clean up the naming and the API for inner iterations.

Change-Id: I3d7d6babb9756842d7367e14b7279d2df98fb724
2012-10-05 08:35:53 -07:00
Sameer Agarwal 2c94eed50f Move from Ordering to ParameterBlockOrdering.
Change-Id: I9320afff13ee62be407c725f42f41a18f537bcc1
2012-10-01 16:47:26 -07:00
Sameer Agarwal 9123e2f624 An implementation of Ruhe & Wedin's Algorithm II.
A non-linear generalization of Ruhe & Wedin's algorithm
for separable non-linear least squares problem. It is implemented
as coordinate descent on an independent subset of the parameter
blocks at the end of every successful Newton step. The resulting
algorithm has much improved convergence at the cost of some
execution time.

Change-Id: I8fdc5edbd0ba1e702c9658b98041b2c2ae705402
2012-09-25 11:13:39 -07:00
Sameer Agarwal 65625f7782 Solver::Options::ordering* are dead.
Remove the old ordering API, and modify solver_impl.cc
to use the new API everywhere.

In the process also clean up the linear solver instantion
logic in solver_impl.cc a bit too.

Change-Id: Ia66898abc7f622070b184b21fce8cc6140c4cebf
2012-09-17 15:41:10 -07:00
Sameer Agarwal 91c9bfee33 Start of the new ordering API.
Change-Id: I37b0f39011f590d54962ad3e1da1f42712008f82
2012-09-17 11:21:22 -07:00
Sameer Agarwal b329e58537 Numerically robust computation of model_cost_change.
Change-Id: I421df17bab3bfdf782d95285cf352ed37675d835
2012-09-05 11:14:09 -07:00
Sameer Agarwal cbae856193 Various cleanups to nist.cc.
More flexible testing.
Read and parse the certified cost value from the data file.
Remove the ugly hack for computing the certified cost.
Refactored the flags parsing logic

Change-Id: I8f2e6be183b758b2453302fcdc6696bfa0db5eb8
2012-09-04 15:39:18 -07:00
Petter Strandmark 87ca1b2ba2 Changing random.h to use cstdlib for Windows compability.
As discussed with Sameer today.

Change-Id: If3d0284830c6591c71cc77b8400cafb45c0da61f
2012-08-28 18:05:20 -07:00
Markus Moll 51cf7cbe3b Add the two-dimensional subspace search to DoglegStrategy
Change-Id: I5163744c100cdf07dd93343d0734ffe0e80364f3
2012-08-20 11:16:41 -07:00
Sameer Agarwal b9f15a5936 Add a dense Cholesky factorization based linear solver.
For problems with a small number of variables, but a large
number of residuals, it is sometimes beneficial to use the
Cholesky factorization on the normal equations, instead of
the dense QR factorization of the Jacobian, even though it
is numerically the better thing to do.

Change-Id: I3506b006195754018deec964e6e190b7e8c9ac8f
2012-08-19 14:47:38 -07:00
Sameer Agarwal 4b0404352d data_fitting.cc should include gflags.
Also fix glog/gflag includes and sorting in examples.

Change-Id: Ie07563b99cbb9172c941bb8f5fb7decb95fbb5d1
2012-08-13 15:09:34 -07:00
Sameer Agarwal 36a3309c84 Add the ability to normalize BALProblem.
Refactor some of the perturbation code so that the
normalization and perturbation code can share the
camera decomposition code.

Change-Id: I084064976804a92f9240d8f5e10d1bb23dcb5ff2
2012-08-13 07:17:14 -07:00
Sameer Agarwal 1b7f3b52fb Add ability to log solver execution to file.
Change-Id: I9996ba2fed5229fe5d621fbb1a027d4c360cd59d
2012-08-10 15:55:31 -07:00
Sameer Agarwal 5476df506e Randomly perturb the bundle adjustment problem.
1. Add the ability to perturb the camera pose and the
point positions using user specified parameters.
2. Re-order the flags.
3. Minor name correction.
4. Added Box-Mueller generator to random.h

Change-Id: I2c9ce74c237f5bde9a7299cc71b205d1ca9bc742
2012-08-10 11:33:59 -07:00
Sameer Agarwal a8f87d7943 Non-monotonic trust region algorithm.
Non-monotonic trust region algorithm based on the work of Phil Toint, as
described in

Non-monotone trust region algorithms for nonlinear
optimization subject to convex constraints.
Philippe L. Toint
Mathematical Programming 77 (1997), 69-94.

Change-Id: I199ecc644e8d1a8cb43666052aef66fb93e15569
2012-08-10 11:09:12 -07:00
Sameer Agarwal fa01519c47 Dogleg strategy and timing cleanups.
1. A new dogleg trust region strategy.
2. Consistent naming of all variables taking and reporting
   time. Also all are doubles now.
3. Enum to stringification routines.
4. bundle_adjuster.cc accepts max solver time and trust_region_strategy.
5. Time accounting is pushed into solver_impl.cc and there is now
   postprocessing time accounted for explicitly.
6. IterationCallback now has cumulative time.
7. LoggingCallback logs per iteration and cumulative time.
8. TrustRegionStrategy now allows for Invalid steps to be indicated
   explicitly.
9. Trust region minimizer actually terminates on max_solver_time.

Change-Id: I7e3b82c8beebc17b6b355ea46ddd280754a2d8b2
2012-06-11 22:16:02 -07:00
Sameer Agarwal 7a3c43b847 Block oriented fill reducing orderings.
By virtue of the modeling layer in Ceres being block oriented,
all the matrices used by Ceres are also block oriented.
When doing sparse direct factorization of these matrices, the
fill-reducing ordering algorithms can either be run on the
block or the scalar form of these matrices. Running it on the
block form exposes more of the super-nodal structure of the
matrix to the Cholesky factorization routines. This leads to
substantial gains in factorization performance.

This changelist adds support for approximate minimium degree
orderings to be computed on the block structure of the
Schur complement matrix. This affects, SchurComplementSolver
and VisibilityBasedPreconditioner and SparseNormalCholesky
 when using SuiteSparse.

A bool, use_block_amd has been added to Solver::Options and
bundle_adjuster.cc has been updated to allow testing with it.

When combined with a multithreaded Schur elimination, speed ups
can be seen quite uniformly across the board. For some problems
this can be dramatic, reducing the factorization time from 70
seconds down to 17 seconds.

Change-Id: I15ebb0afcbc85ada032ec8d179ee3a2f7c8d3e46
2012-06-06 22:02:17 -07:00
Sameer Agarwal aa9a83c657 New Trust region loop.
1. New TrustRegionMinimizer and basic tests for it.
2. New TrustRegionStrategy interface.
3. New LevenbergMarquardtStrategy and tests for it.
4. Updates to SolverImpl to reflect this.
5. Changes to Solver::Options and IterationSummary related to this.
6. Deleted levenberg_marquardt.cc/h/_test.cc

Change-Id: I6c1d1a7c774f014856f9f26263a830aa886e1400
2012-05-30 21:44:46 -07:00
Keir Mierle e2a6cdc081 Address some of the comments on CGNR patch
- Rename BlockDiagonalPreconditioner to BlockJacobiPreconditioner
- Include the diagonal in the block jacobi preconditioner.
- Better flag help for eta.
- Enable test for CGNR
- Rename CONJUGATE_GRADIENTS to CGNR.
- etc.
2012-05-07 06:39:56 -07:00
Keir Mierle 211812a573 Better error handling in bundle_adjuster.cc 2012-05-07 04:33:50 -07:00
Keir Mierle f7898fba1b Add a general sparse iterative solver: CGNR
This adds a new LinearOperator which implements symmetric
products of a matrix, and a new CGNR solver to leverage
CG to directly solve the normal equations. This also
includes a block diagonal preconditioner. In experiments
on problem-16, the non-preconditioned version is about
1/5 the speed of SPARSE_SCHUR, and the preconditioned
version using block cholesky is about 20% slower than
SPARSE_SCHUR.
2012-05-05 20:55:08 -07:00
Keir Mierle 8ebb073038 Initial commit of Ceres Solver. 2012-04-30 23:09:08 -07:00