Commit Graph

626 Commits

Author SHA1 Message Date
Sameer Agarwal 2fd39fcecb FindWithDefault returns by value rather than reference.
Returning by reference leads to lifetime issues with the default
value which may go out of scope by the time it is used.

Thanks to @Ardavel for reporting this, as this causes graph_test
to fail on VS2015x64.

https://github.com/ceres-solver/ceres-solver/issues/216

Change-Id: I596481219cfbf7622d49a6511ea29193b82c8ba3
2016-09-01 16:05:06 -07:00
David Gossow b102d53e1d Gradient checker multithreading bugfix.
This is a follow-up on c/7470. GradientCheckingCostFunction calls
callback_->SetGradientErrorDetected() in its Evaluate method,
which will run in multiple threads simultaneously when enabling
this option in the solver. Thus, the string append operation
inside that method has to be protected by a mutex.

Change-Id: I314ef1df2be52595370d9af05851bf6da39bb45e
2016-08-31 20:25:44 +00:00
Sameer Agarwal 79a28d1e49 Rename a confusingly named member of Solver::Options
Solver::Options::numeric_derivative_relative_step_size to
Solver::Options::gradient_check_numeric_derivative_relative_step_size

Change-Id: Ib89ae3f87e588d4aba2a75361770d2cec26f07aa
2016-08-31 07:47:29 -07:00
Alex Stewart edbd48ab50 Enable support for OpenMP in Clang if detected.
- Previously we disabled OpenMP if Clang was detected, as it did not
  support it.  However as of Clang 3.8 (and potentially Xcode 8) OpenMP
  is supported.

Change-Id: Ia39dac9fe746f1fc6310e08553f85f3c37349707
2016-08-31 08:25:11 +00:00
David Gossow ac3b8e8217 Gradient checking cleanup and local parameterization bugfix
Change the Ceres gradient checking API to make is useful for
unit testing, clean up code duplication and fix interaction between
gradient checking and local parameterizations.

There were two gradient checking implementations, one being used
when using the check_gradients flag in the Solver, the other
being a standalone class. The standalone version was restricted
to cost functions with fixed parameter sizes at compile time, which
is being lifted here. This enables it to be used inside the
GradientCheckingCostFunction as well.

In addition, this installs new hooks in the Solver to ensure
that Solve will fail if any incorrect gradients are detected. This
way, you can set the check_gradient flags to true and detect
errors in an automated way, instead of just printing error information
to the log. The error log is now also returned in the Solver summary
instead of being printed directly. The user can then decide what to
do with it. The existing hooks for user callbacks are used for
this purpose to keep the internal API changes minimal and non-invasive.

The last and biggest change is the way the the interaction between
local parameterizations and the gradient checker works. Before,
local parameterizations would be ignored by the checker. However,
if a cost function does not compute its Jacobian along the null
space of the local parameterization, this wil not have any effect
on the solver, but would result in a gradient checker error.
With this change, the Jacobians are multiplied by the Jacobians
of the respective local parameterization and thus being compared
in the tangent space only.

The typical use case for this are quaternion parameters, where
a cost function will typically assume that the quaternion is
always normalized, skipping the correct computation of the Jacobian
along the normal to save computation cost.

Change-Id: I5e1bb97b8a899436cea25101efe5011b0bb13282
2016-08-18 06:18:43 +00:00
Mike Vitus d4264ec10d Add a quaternion local parameterization for Eigen's quaternion element convention.
Change-Id: I7046e8b24805313c5fb6a767de581d0054fcdb83
2016-08-17 18:28:54 -07:00
Sameer Agarwal e1bcc6e0f5 Add additional logging for analyzing orderings
Change-Id: Ic68d2959db35254e2895f11294fb25de4d4b8a81
2016-08-02 10:12:04 -07:00
Nicolai Wojke 8ea86e1614 Fix: Copy minimizer option 'is_silent' to LinSearchDirection::Options
Change-Id: I23b4c3383cad30033c539ac93883d77c8dd4ba1a
2016-04-25 14:24:41 +02:00
Sameer Agarwal 21ab397dc5 Make some Jet comparisons exact.
Change-Id: Ia08c72f3b8779df96f5c0d5a954b2c0a1dd3a061
2016-04-24 21:13:00 -07:00
Sameer Agarwal 9665e09902 Fix step norm evaluation in LineSearchMinimizer
TrustRegionMinimizer evaluates the size of the step
taken in the ambient space, where as the LineSearchMinimizer
was using the norm in the tangent space. This change fixes
this discrepancy.

Change-Id: I9fef64cbb5622c9769c0413003cfb1dc6e89cfa3
2016-04-19 00:08:06 +00:00
Mike Vitus 0c63bd3efb Add floor and ceil functions to the Jet implementation.
Change-Id: I72ebfb0e9ade2964dbf3a014225ead345d5ae352
2016-04-15 10:47:22 -07:00
Keir Mierle 5512f58536 Only use collapse() directive with OpenMP 3.0 or higher
Change-Id: Icba544c0494763c57eb6dc61e98379312ca15972
2016-04-07 12:03:16 -07:00
Thomas Schneider d61e94da52 Add IsParameterBlockConstant to the ceres::Problem class.
Change-Id: I7d0e828e81324443209c17fa54dd1d37605e5bfe
2016-04-06 23:52:18 +02:00
Alex Stewart 77d94b3474 Fix install path for CeresConfig.cmake to be architecture-aware.
- Previously we were auto-detecting a "64" suffix for the install path
  for the Ceres library on non-Debian/Arch Linux distributions, but
  we were installing CeresConfig.cmake to an architecture independent
  location.
- We now install CeresConfig.cmake to lib${LIB_SUFFIX}/cmake/Ceres.
- Also make LIB_SUFFIX visible to the user in the CMake GUI s/t they can
  easily override the auto-detected value if desired.
- Reported by jpgr87@gmail.com as Issue #194.

Change-Id: If126260d7af685779487c01220ae178ac31f7aea
2016-03-16 21:20:31 +00:00
Keir Mierle f4ba28d09d Fix double conversion to degrees in rotation_test
Change-Id: I16b6d210cdab94340c001b322916c5b1a3b6a35f
2016-03-16 11:38:05 -07:00
Keir Mierle 0149ce0e0e Fix rotation_test IsClose() and related tests
Change-Id: I0ff91e2931615babf1dcc9483fac7f4a2fb13726
2016-03-16 11:09:53 -07:00
Sameer Agarwal 2c178ec35f Add more documentation.
Add documentation to the TrustRegionMinimizer and
TrustRegionStepEvaluator.

Change-Id: I3651e41ff37955a0b7044910403630af1a855071
2016-03-06 21:13:42 -08:00
Sameer Agarwal 2ee3e06064 Loosen an exact equality in local_parameterization_test
The norm comparison in QuaternionParameterizationHelper is exact
but that leads to numerical precision problems and test failures
as reported by Nicu Stiurca.

https://github.com/ceres-solver/ceres-solver/issues/198

Change-Id: I45f42f0373770408ddeee0b4c9d162e619f8d445
2016-03-04 22:12:18 -08:00
Simon Rutishauser 7d670209a2 Fix error message returned when using SUITE_SPARSE_QR in covariance estimation
on a ceres built without SuiteSparse support.

This is only a minor issue, up until now this case would have been handled by
the "default" case of the switch

Change-Id: Ib4568eb827dbf0e8e8d618a5bc8cd379a3c42c42
2016-02-16 11:53:45 +01:00
Sameer Agarwal 982327062e Initialize inner_iterations_were_useful_ correctly.
This variable should be initialized before the decision to
perform inner iterations are performed.

Change-Id: Ic80e2d5284ecc67eaed1859be009b1a4d18bf76b
2016-02-04 11:50:20 -08:00
Sameer Agarwal 46ad4699f4 A complete refactoring of TrustRegionMinimizer.
1. Break up the monolithic loop in TrustRegionMinimizer::Minimize
   into a number of more easily described and analyzed subfunctions.
2. Break out the logic for evaluating the quality of a Trust Region
   step into its own object - TrustRegionStepEvaluator.

Change-Id: I08580ecac074cfd74c096cb8e4880cbda3d48296
2016-02-04 10:05:12 -08:00
Sameer Agarwal dec43ae5e0 Add an implementation for GradientProblemSolver::Options::IsValid
Thanks for Francesco Callari for reporting this.

Change-Id: I2b2f4e0e098fbdc914dc7770db1164884ac50e24
2016-02-03 07:24:05 -08:00
Alex Stewart 706a876541 Fix use of va_copy() if compiling with explicit C++ version < C++11.
- va_copy() was defined in the C99 standard, but did not appear in the
  C++ standard until C++11.  If the C++ standard is not specified,
  both GCC & Clang will define va_copy(), even though strictly speaking
  they should not.  However, if the C++ standard is explicitly specified
  to something < C++11 (e.g. -std=c++03) then va_copy() will NOT be
  defined.
- Now, if va_copy() is not defined, we either define our own version
  on non GCC/Clang compilers (as before for MSVC alone), and use the
  internal __va_copy() version on GCC & Clang, which does exist.

Change-Id: I0224f7fa6aae060dee2287782b1cad767c244d3c
2016-01-21 19:30:58 +00:00
Sameer Agarwal 15587dd1a9 Lint changes from William Rucklidge
Change-Id: If05a774c5e7dd318e6b3ee698e313f0fc58ee922
2016-01-05 11:31:13 -08:00
Wannes Van Loock b0bf9fd2a9 Add covariance matrix for a vector of parameters
Computing the covariance matrix for a number of parameter blocks
previously required adding all parameter blocks to the computation and
subsequently assembling the matrix by concatenating all the blocks.

This patch adds the computation of the covariance matrix for a vector
of parameter blocks. All covariance block pairs are added automatically
and the resulting covariance matrix is assembled in the order the
parameter blocks appear.

Change-Id: I3b70c63f16862adc23a1d7fb7a21dde4e68abe9a
2016-01-04 20:26:40 +00:00
Sameer Agarwal 8ecfb2d705 Fix the build.
Change-Id: I95a62a180a1a21fc379fe27b1309d72f19d9ef29
2015-12-17 13:55:02 -08:00
Sameer Agarwal ed32e6a44a Add logging for sparse Cholesky factorization using Eigen
Print information about the fill-in when using Eigen to perform
Simplicial sparse Cholesky factorization.

Change-Id: I09013b7f4ed2f6c55ae8ce8922447e23d63580a8
2015-12-17 20:22:48 +00:00
Sameer Agarwal a1019f6610 Use std::adjacent_find instead of std::unique
When detecting duplicates, it is more efficient to use std::adjacent_find
than it is to use std::unique.

Change-Id: Ib6b4671c10848bb7dd10aa7a1baeffc8c9c825b5
2015-12-17 20:21:42 +00:00
Sameer Agarwal aaa0e3e4c8 Improve logging in CompressedRowJacobianWriter on crash
Change-Id: Ib56955669279724e7f1dffd9a68b7b2b66b24a85
2015-12-17 11:51:50 -08:00
Sameer Agarwal 6418b33f21 Fix free parameter block handling in covariance computation
Parameter blocks that are not associated with any residual block
lead to structurally zero columns in the Jacobian. The covariance
computation algorithm was only paying attention to structural
sparsity caused by constant parameter blocks but not free parameter
blocks.

This patch fixes this, by iterating over the residual blocks in
the problem and collecting all the parameter blocks in use.

The tests for ComputeCovarianceSparsity are also extended to include
the case where there are constant and free parameter blocks.

Thanks to Wannes Van Loock for reporting this.

Change-Id: Ic298a6e93c53f2f95fb69105397a87200738a2b0
2015-12-04 09:51:57 -08:00
Sameer Agarwal 992ae55e84 Report the number of line search steps in FullReport.
Accumulate the number of steps of the line search algorithm
and report it as part of Summary::FullReport.

Change-Id: I1de12784009a3e08f2a2c2aff5085d57a3c73828
2015-12-01 14:26:13 -08:00
Sameer Agarwal f4214e3ecf Lint changes from William Rucklidge.
Change-Id: I34899063edc2fe1f4ed976406448f829a1f210c0
2015-11-19 08:40:08 -08:00
Wannes Van Loock 5a3a23eb39 Fix covariance computation for constant blocks
This commit fixes a bug related to the computation of covariance blocks
in the tangent space for constant parameter blocks, causing out of
bounds memory access.

Change-Id: Iaeee7992405fcaaae6086612798e96f2e10ebc5c
2015-11-13 09:29:05 +01:00
Alessandro Gentilini aef9c9563b Add test for Bessel functions.
Change-Id: Ief5881e8027643d7ef627e60a88fdbad17f3d884
2015-10-22 18:48:13 +00:00
Simon Rutishauser dfb201220c Make miniglog threadsafe on non-windows system by using
localtime_r() instead of localtime() for time formatting

Change-Id: Ib8006c685cd8ed4f374893bef56c4061ca2c9747
2015-10-15 09:44:53 +02:00
Alex Stewart 41455566ac Remove link-time optimisation (LTO).
- On GCC 4.9+ although GCC supports LTO, it requires use of the
  non-default gcc-ar & gcc-ranlib.  Whilst we can ensure Ceres is
  compiled with these, doing so with GCC 4.9 causes multiple definition
  linker errors of static ints inside Eigen when compiling the tests
  and examples when they are not also built with LTO.
- On OS X (Xcode 6 & 7) after the latest update to gtest, if LTO
  is used when compiling the tests (& examples), two tests fail
  due to typeinfo::operator== (things are fine if only Ceres itself is
  compiled with LTO).
- This patch disables LTO for all compilers. It should be revisited when
  the performance is more stable across our supported compilers.

Change-Id: I17b52957faefbdeff0aa40846dc9b342db1b02e3
2015-10-05 18:54:11 +01:00
Alex Stewart 89c40005bf Only use LTO when compiling Ceres itself, not tests or examples.
- If Ceres is built as a shared library, and LTO is enabled for Ceres
  and the tests, then type_info::operator==() incorrectly returns false
  in gtests' CheckedDowncastToActualType() in the following tests:
-- levenberg_marquardt_strategy_test.
-- gradient_checking_cost_function_test.
  on at least Xcode 6 & 7 as reported here:
  https://github.com/google/googletest/issues/595.
- This does not appear to be a gtest issue, but is perhaps an LLVM bug
  or an RTTI shared library issue.  Either way, disabling the use of
  LTO when compiling the test application resolves the issue.
- Allow LTO to be enabled for GCC, if it is supported.
- Add CMake function to allow easy appending to target properties s/t
  Ceres library-specific compile flags can be iteratively constructed.

Change-Id: I923e6aae4f7cefa098cf32b2f8fc19389e7918c9
2015-09-28 15:08:39 +01:00
Alex Stewart 26cd5326a1 Add gtest-specific flags when building/using as a shared library.
- Currently these flags are only used to define the relevant DLL export
  prefix for Windows.

Change-Id: I0c05207b512cb4a985390aefc779b91febdabb38
2015-09-21 10:16:01 +01:00
Sameer Agarwal 155765bbb3 Import the latest version of gtest and gmock.
Change-Id: I4b686c44bba823cab1dae40efa99e31340d2b52a
2015-09-16 19:23:43 +00:00
Sameer Agarwal f4b768b69a Lint changes from William Rucklidge
Change-Id: I0dac2549a8fa2bfd12f745a8d8a0db623b7ec1ac
2015-09-14 13:53:24 -07:00
Sameer Agarwal 5f2f05c726 Refactor system_test
1. Move common test infrastructure into test_util.
2. system_test now only contains powells function.
3. Add bundle_adjustment_test.

Instead of a single function which computes everything,
there is now a test for each solver configuration which
uses the reference solution computed by the fixture.

Change-Id: I16a9a9a83a845a7aaf28762bcecf1a8ff5aee805
2015-09-12 15:41:05 -07:00
Alex Stewart 1936d47e21 Revert increased inline threshold (iff Clang) to exported Ceres target.
- Increasing the inline threshold results in very variable performance
  improvements, and could potentially confuse users if they are trying
  to set the inline threshold themselves.
- As such, we no longer export our inline threshold configuration for
  Clang, but instead document how to change it in the FAQs.

Change-Id: I88e2e0001e4586ba2718535845ed1e4b1a5b72bc
2015-09-08 23:27:42 +01:00
Sameer Agarwal 1ac3dd223c Fix a bug in CompressedRowSparseMatrix::AppendRows
The test for CompressedRowSparseMatrix::AppendRows tries to add
a matrix of size zero, which results in an invalid pointer deferencing
even though that pointer is never written to.

Change-Id: I97dba37082bd5dad242ae1af0447a9178cd92027
2015-09-05 15:56:14 -07:00
Sameer Agarwal 5742b7d0f1 Improve performance of SPARSE_NORMAL_CHOLESKY + dynamic_sparsity
The outer product computation logic in SparseNormalCholeskySolver
does not work well with dynamic sparsity. The overhead of computing
the sparsity pattern of the normal equations is only amortized if
the sparsity is constant. If the sparsity can change from call to call
SparseNormalCholeskySolver will actually be more expensive.

For Eigen and for CXSparse we now explicitly compute the normal
equations using their respective matrix-matrix product routines and solve.
Change-Id: Ifbd8ed78987cdf71640e66ed69500442526a23d4
2015-09-05 14:31:52 -07:00
Keir Mierle d0b6cf657d Fix incorrect detect structure test
Change-Id: I7062f3639147c40b57947790d3b18331a39a366b
2015-09-04 18:43:41 -07:00
Alex Stewart 0e8264cc47 Add increased inline threshold (iff Clang) to exported Ceres target.
- When compiled with Clang, Ceres and all of the examples are compiled
  with an increased inlining-threshold, as the default value can result
  in poor Eigen performance.
- Previously, client code using Ceres would typically not use an
  increased inlining-threshold (unless the user has specifically added
  it themselves).  However, increasing the inlining threshold can result
  in significant performance improvements in auto-diffed CostFunctions.
- This patch adds the inlining-threshold flags to the interface flags
  for the Ceres CMake target s/t any client code using Ceres (via
  CMake), and compiled with Clang, will now be compiled with the same
  increased inlining threshold as used by Ceres itself.

Change-Id: I31e8f1abfda140d22e85bb48aa57f028a68a415e
2015-09-02 19:37:01 +01: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
Alex Stewart 887a20ca7f Build position independent code when compiling Ceres statically.
- Previously, when Ceres was built as a static library we did not
  compile position independent code.  This means that the resulting
  static library could not be linked against shared libraries, but
  could be used by executables.
- To enable the use of a static Ceres library by other shared libraries
  as reported in [1], the static library must be generated from
  position independent code (except on Windows, where PIC does not
  apply).

[1] https://github.com/Itseez/opencv_contrib/pull/290#issuecomment-130389471

Change-Id: I99388f1784ece688f91b162d009578c5c97ddaf6
2015-08-25 18:29:08 +00:00
Sameer Agarwal 860bba588b Fix a bug in DetectStructure
The logic for determing static/dynamic f-block size in
DetectStructure was broken in a corner case, where the very first
row block which was used to initialize the f_block_size contained
more than one f blocks of varying sizes. The way the if block
was structured, no iteration was performed on the remaining
f-blocks and the loop failed to detect that the f-block size
was actually changing.

If in the remaining row blocks, there were no row blocks
with varying f-block sizes, the function will erroneously
return a static f-block size.

Thanks to Johannes Schonberger for providing a reproduction for this
rather tricky corner case.

Change-Id: Ib442a041d8b7efd29f9653be6a11a69d0eccd1ec
2015-08-25 11:14:10 -07:00