Commit Graph

690 Commits

Author SHA1 Message Date
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
Greg Coombe bca76b5bb5 Disable LAPACK for iOS builds.
Apple annoyingly claims that dsyrk_ is a private API, and rejects
submissions to the Apple Store that include this symbol.

Also change ifdef -> ifndef in blas.cc

Change-Id: I432e9519cfe661fc96a58f36a86389a916b6a8b6
2015-03-17 11:45:06 -07:00
Sameer Agarwal f129b61d6b Hide dsyrk_ if CERES_NO_LAPACK is defined.
This will allow iOS users not to suffer Apple's
idiotic AppStore approval process.

Change-Id: I34ad3f458b0cf8ffb0f89205937233264c3bb63a
2015-03-17 13:06:41 +00:00
Alex Stewart ffa324765e Force use of single-thread in Problem::Evaluate() without OpenMP.
- Ensure that, as in the preprocessor, we force num_threads to be 1
  if Ceres was compiled without OpenMP to prevent a CHECK() failure
  in internal code.

Change-Id: I49d7bdeff81e5bb24aaaa3945018d9d012cd9df9
2015-03-15 22:30:50 +00:00
Chris Sweeney 8db90ca2f6 Less strict check for multithreading.
Removes the CHECK-fail for num_threads > 1 when
OpenMP is not detected

Change-Id: I5c1d48aad66c8b7a1f73c93dae572b73953859a0
2015-03-15 19:13:42 +01:00
Sameer Agarwal e98445e0a6 Update tolerances in small_blas_test.cc
Thanks to Philipp Hubner for reporting this.

Change-Id: Ia4f9dfa84edc164fa0c363381e94c929905f57b6
2015-03-13 06:48:54 -07:00
Steve Hsu a1579be80b Add method to return covariance in tangent space
This CL is required to build Tango.

Inspired by this commit in RedwoodInternal repository:
  commit 09dde53c248e04f432b5eccceea5daeedb706aea
  Author: Mike Vitus <mike@hidof.com>
  Date:   Wed Apr 23 11:05:17 2014 -0700

Change-Id: I328b6634969de4ccdd71947945aa67a49ee9073f
2015-03-12 11:40:18 -07:00
Sameer Agarwal 3125c23228 A complete re-write of the cubic interpolation code.
The key change is that there is a new layer of abstract,
a Array object that the interpolator depends on.

The Array provides a one dimension or two dimensional
array like interface independent of the underlying representation
of the data.

Also included here is support for vector valued functions.

Change-Id: Ica68f03778cf0d84192db00cd55653f8b4124d51
2015-02-06 22:06:11 -08:00
Sameer Agarwal 3687f9ae4c Lint changes from William Rucklidge
Change-Id: I351bef3bf7969a60d8d715731a9eafab5d612a81
2015-01-30 16:33:40 -08:00
Sameer Agarwal f572d1dd44 Improve the error handling in Conjugte Gradients.
Due to floating point and conditioning issues, a system
matrix which is guaranteed to be PSD in exact arithmetic
can appear indefinite to the ConjugateGradientsSolver.

Previously, x'Ax <= 0, the solver returned with numerical
failure. Which the trust region solver will treat as a failed
solve.

But, more general truncated Newton when they encounter indefiniteness
use the step computed till that point instead of declaring failure.

This changes does this and adds a bit more logging.

Change-Id: I0e0cc56ef7d856f1c54ac6d638327b8353039f70
2015-01-30 14:20:05 -08:00
Sameer Agarwal a2a998ce58 Add BiCubic interpolation.
This bi-cubic interpolation implementation is based
on the cubic convolution algorithm of keys, which allows
us to implement a bi-cubic spline like interpolation scheme
using five one dimensional cubic spline operations.

Change-Id: I116aa8036191c3e654af788323fc8298ae8252a6
2015-01-27 21:40:47 -08:00
Sameer Agarwal 1789fc6d66 Add a one dimensional cubic interpolator.
Add a cubic interpolator based on the Catmull-Rom spline,
with support for automatic differentiation.

Change-Id: I02ae4c4ea37805ff1f717b05ea805989b474bd59
2015-01-26 22:24:53 -08:00
Sameer Agarwal 57d29a18f4 Fix a broken test.
The previous commit broke levenberg_marquardt_strategy_test due
a change in the logging string being used.

Change-Id: I6ea69c0bba195c3e7d457d509b9a6605458d69b4
2015-01-23 12:02:46 -08:00
Sameer Agarwal 2e1317fd98 Improve logging for linear solver failures.
Change-Id: Idc7dce702e99637f47d7585399ef8da38f0b8111
2015-01-23 11:40:44 -08:00
Sameer Agarwal db1a76d866 Better crash error messages.
When a user requests an operation on a parameter block which has
not been added to the problem, we now display a more helpful
error message with more context.

Change-Id: Ia7e54815111eb6375b31ed0d1cddca5917138ae1
2015-01-16 11:54:28 -08:00
Alex Stewart 378b575217 Add SuiteSparse link dependency for compressed_col_sparse_matrix_utils_test.
- Reported by stonier@yujinrobot.com as Issue 153:
  https://code.google.com/p/ceres-solver/issues/detail?id=153

Change-Id: I3f0e67291adf129a6e7857ccc5f4e7e355feceb8
2015-01-14 21:03:18 +00:00
Sameer Agarwal 3c8bad8fd3 Add a missing using std::max and std::min.
Thanks to Philipp Bender for reporting this.

Change-Id: I1f2947d378e0e98f6d225126a686d52738df3df0
2015-01-09 07:29:52 -08:00
Sameer Agarwal 74fd412420 Lint changes from William and Jim.
Change-Id: Ida89b67c66b3bc7683d95e63646dfb2f9679d1b1
2015-01-08 11:45:15 -08:00
Sameer Agarwal 05a07ecc77 Remove using std::string from port.h
Change-Id: I7376f5e7eace22ec1fc05a61eaa858594f08682d
2015-01-07 15:10:46 -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
Alex Stewart 60cc520f63 Add explicit no sparse linear algebra library available option.
- Previously we had no defined default value for
  sparse_linear_algebra_library_type in Solver::Options if Ceres
  was compiled with no sparse library available.  Thus in that case,
  the default value (dependent upon the compiler) would indicate that
  one was available.
- Now we have an explicit option that means no sparse library is
  available, which is now the default value in Solver::Options in this
  case.
- Add a warning in CMake when the user disables all sparse libraries.
- Fix typos in trust_region_preprocessor_test:
  (SUITE/CX)_SPARSE -> (SUITE/CX)SPARSE that induced failures when
  no sparse libraries were available.

Change-Id: I869c399a12d42bfc44220cbb25ce6d6dd80236bd
2015-01-01 18:51:45 +00:00
Sameer Agarwal 31b1d42ce5 Delete Incomplete LQ Factorization.
This code never got expanded into a full preconditioner. No point
keeping dead code around.

Change-Id: I45badcd9e5f7eb39e8d288a96c65a02f325d76bd
2014-12-15 12:51:58 -08:00
Alessandro Dal Grande 4992b0493e Template specialization <2,3,6>
Change-Id: If7bfaef9dea604b78290ab739e21ae2ec6195ed6
2014-12-02 19:45:11 +00:00
Sameer Agarwal 159815797b Do not try the gradient step if TR step line search fails.
The line search used by the trust region minimizer when enforcing
the bounds constraints starts by using the trust region step
as the line search direction and if that fails, uses the gradient
as the fallback.

The problem with this logic is that the calling code only sees
whether one of the line searches succeeds or not. It does not see
that the fallback happened. So if the fallback line search suceeeds
it still thinks that the line search direction was the trust region
step. This is clearly wrong.

This change, removes the broken fallback logic. This has no effect
on current solution quality as it stands.

Change-Id: Ibc8edd98f77c782ec4708d1e66eaa76d6867b990
2014-11-30 13:51:50 -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
Alex Stewart 9ad59a760a Compute & report timing information for line searches.
- We now compute & report the cumulative time spent performing the
  following tasks as part of a line search:
  - Evaluation of the univariate cost function value & gradient.
  - Minimization of the interpolating polynomial.
  - Total time spent performing line searches.
- This information is now reported for all minimizers, although only in
  the case of a constrained problem for the TR minimizer.
- Remove LineSearch::Function abstraction in place of using
  LineSearchFunction implementation directly, and remove virtual
  functions from LineSearchFunction.
-- LineSearch::Function added an unnecessary level of abstraction since
   the user always had to create a LineSearchFunction anyway to use a
   Ceres Evaluator, and it added an unncessary virtual function call.

Change-Id: Ia4e1921d78f351ae119875aa97a3ea5e8b5d9877
2014-11-26 01:00:17 +00:00
Sameer Agarwal c929917e97 Conditionally log evaluation failure warnings.
Logging was happening unconditionally and that is rather jarring
in certain circumstances, e.g., when ceres is being called
inside a RANSAC loop.

Thanks to Bryan Klingner for reporting this.

Change-Id: I97a0b6c48df51f5f7362eb9d46654712ef044a00
2014-11-20 05:45:01 -08:00
Sameer Agarwal d9bb71c733 Runtime uses four digits after the decimal in Summary:FullReport.
Change-Id: I939bb5cf951f572832b0d665831ab2f6015f75f7
2014-11-17 06:53:51 -08:00
Sameer Agarwal b58a877634 Better options checking for TrustRegionMinimizer.
Since the trust region minimizer can use the line search
minimizer when it is solving a box constrained problem,
ensure that the line search options are valid.

Also some minor spacing fixes in the line search code.

Change-Id: Ife04204855cfac389cf980f0a79155d4accc8662
2014-11-14 11:18:25 -08:00
Sameer Agarwal 993622e915 Minor fixes.
1. Remove an unused private member in TukeyLoss.
2. The test for RotationMatrixToAngle had an indexing error.

Change-Id: I7decc9448ae0abef53aa435005f739e9e0931e80
2014-11-14 07:31:31 -08:00
Sameer Agarwal 0484fabab8 Lint and documentation update.
Change-Id: I05f40983f267dd1534e3eee8c0fc038e4429abed
2014-11-13 23:08:30 -08:00
Sameer Agarwal 730aa537cd Add RotationMatrixToQuaternion.
Use this function to implement RotationMatrixToAngleAxis.
This simplifies the implementation of RotationMatrixToAngleAxis,
just like Eigen does. It is also autodiff compatible, unlike the
Eigen based version.

Also significantly improve the test coverage of
RotationMatrixToAngleAxis.

Change-Id: Ic192a12fb5de952197ee24b0deedc45f195477f1
2014-11-14 06:57:30 +00:00
Mike Vitus 7c0ac8f995 Add Tukey loss function.
Change-Id: I7c76f13e01863440fc207e99b3fc7ad3fb6f7d1a
2014-11-13 15:29:37 -08:00
Sameer Agarwal cd358c760f Fix RotationMatrixToAngleAxis near Pi.
Use Eigen's much more complicated conversion routine
when we encounter cases where the angle of rotation is
close to Pi.

Along the way also fix the way angle_axis vectors are
compared by making the matcher more robust.

Thanks to Tobias Strauss for reporting this.

Change-Id: Ia7e65dafad92c48d29d5f3cd22c4d6534789c183
2014-11-12 22:56:38 -08:00
Sameer Agarwal 5648c6324b Move gradient convergence test after step update.
The trust region minimizer was detecting convergence due to
the gradient tolerance being reached but was not updating the
step. In the unconstrained test this is usually not a problem,
since we approach this point quite slowly. In the constrained
case however, we may approach this point quite quickly as a
result of the line search.

As a consequence, even though the solver finds the optimal
solution on the boundary, it fails to return this solution
to the user.

Thanks to Rodney Hoskinson for reporting this.

Change-Id: I7b1bcd1310ef0582e05957f43d1700eaabd73241
2014-11-05 15:25:07 -08:00
Alex Stewart e81a5dd300 Ignore warnings from within Eigen/SparseQR (3.2.2).
- As reported by Chris Sweeney on the mailing list, Eigen 3.2.2
  trips various warnings in Eigen/SparseQR when compiling with GCC.
- Following Petter Strandmark's suggestion, Eigen headers are now
  treated as system headers, which implicitly suppresses all warnings.

Change-Id: I104e8cb3f00935cefb894089bea827771e0e9fd0
2014-10-28 13:04:46 +00:00
Sameer Agarwal 7b6bd1cd31 Documentation update.
1. Complete restructuring of the documentation to account for
   GradientProblemSolver.
2. Update the version history to account for changes since 1.9.0.
3. Add links and document the various examples that ship with ceres.
4. Documentation for GradientProblem GradientProblemSolver.

Change-Id: If3a18f2850cbc98be1bc34435e9ea468785b8b27
2014-10-08 08:47:34 -07:00
Sameer Agarwal 94c6e7d27b Improve multithreading when using inner iterations.
Inner iterations by default would use problems where the evaluator
was configured to use exactly one thread for doing the evaluation.
This is fine when there are multiple inner iteration problems
being executed concurrently, but every now and then there are
problem decompositions where there is just one parameter block
in the current independent set and it touches every single
residual block. In such cases it is essential that the evaluator
be configured to use multiple threads.

We now pay attention to the size of the independent set and
dynamically configure the number of threads being used by the
outer loop and the evaluator loop.

Thanks to William Rucklidge for reporting this issue and providing
a test problem to debug.

Change-Id: Iaff9a4ab6d2658cf7b61ea213575d23aab604e3b
2014-10-01 16:00:26 -07:00
Sameer Agarwal 9e11cd16d0 Faster BlockRandomAccessSparseMatrix::SymmetricRightMultiply.
Trade a small amount of memory to improve the cache coherency of
the SymmetricRightMultiply operation.

The resulting code leads to a 10-20% speedup in the linear solver
end to end.

Change-Id: I8ab2fe152099e849b211b5b19e4ef9f03d8e7f1c
2014-09-29 15:50:19 -07:00
Sameer Agarwal 46b8461fd0 Various minor fixes from William Rucklidge.
Change-Id: Ibe731d5db374ad8ee148d62a9fdd8d726b607a3f
2014-09-29 15:10:58 -07: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 4ad9149082 Simplify the Block Jacobi and Schur Jacobi preconditioners.
1. Extend the implementation of BlockRandomAccessDiagonalMatrix
by adding Invert and RightMultiply methods.

2. Simplify the implementation of the Schur Jacobi preconditioner
using these new methods.

3. Replace the custom storage used inside Block Jacobi preconditioner
with BlockRandomAccessDiagonalMatrix and simplify its implementation
too.

Change-Id: I9d4888b35f0f228c08244abbdda5298b3ce9c466
2014-09-29 08:40:03 -07:00
Sameer Agarwal 8f7be1036b Fix a formatting error TrustRegionMinimizer logging.
Change-Id: Iad1873c51eece46c3fdee1356d154367cfd7925e
2014-09-29 08:13:35 -07:00
Sameer Agarwal c99872d48e Add BlockRandomAccessSparseMatrix::SymmetricRightMultiply.
Change-Id: Ib06a22a209b4c985ba218162dfb6bf46bd93169e
2014-09-24 21:34:53 -07:00
Alex Stewart 5dd76869cf Fix unused-function warning with Eigen < 3.2.2.
- CreateBlockJacobian() is only ever used when Eigen >= 3.2.2 is
  detected, but was previously defined whenever CERES_USE_EIGEN_SPARSE
  was defined with no check on the Eigen version.
- This resulted in an unused-function compile warning that became an
  error due to -Werror, preventing compilation when using Eigen < 3.2.2.

Change-Id: I24628ff329f14b087ece66bf2626bdc0de4ba224
2014-09-19 16:08:25 +01: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 6c45d6b891 Add more inspection methods to Problem.
Problem::GetCostFunctionForResidualBlock
Problem::GetLossFunctionForResidualBlock

are added, so that users do not have to maintain this mapping
outside the Problem.

Change-Id: I38356dfa094b2c7eec90651dafeaf3a33c5f5f56
2014-09-11 12:17:54 -07:00
Sameer Agarwal 6ad9b8e2ae Ignore row/column blocks structure when using dynamic sparsity
The row/column blocks can be huge when using dynamic sparsity. This
can result in very large memory usage when augmenting the jacobian
with the LM diagonal.

Thanks to Mingsong Dou for reporting this.

Change-Id: I6aa140ceefa98389ae17958f89ca76e0c76f95b8
2014-09-09 14:29:28 -07:00
Sameer Agarwal 1aef66eeae Remove errant space.
Change-Id: Iedc06960417a9b938d57f623b4beb87a98e3d081
2014-09-07 21:18:44 -07:00
Sameer Agarwal 89080ab153 Add LocalParameterization::MultiplyByJacobian.
This is needed to efficiently support LocalParameterization objects
in GradientProblemSolver.

Change-Id: Ic7b715b8be694b099dc95d6707a67474297533e6
2014-09-07 20:46:33 -07:00