Commit Graph

805 Commits

Author SHA1 Message Date
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
Sameer Agarwal d3ecd18625 Add an explicit include for local_parameterization.h
Thanks to cooordz for reporting this.

Change-Id: I7d345404e362a94ff1eb433ad6b9dcc4960ba76d
2014-09-23 10:12:42 -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 820cb7b148 Add solver_utils.cc to Android.mk
Change-Id: I358522971711280f4362a1fa39b1568160e21e63
2014-09-17 09:46:08 -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 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
Martin Baeuml 7e43460d42 Fix a few typos in the documentation.
Change-Id: I541db56b2b81ae758e233ce850d78c3cbb4b6fa3
2014-09-08 16:49:06 +02: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
Sameer Agarwal d76da16f49 Move some routines to solver_utils.h/cc
This moves a couple of routines from solver.cc into solver_utils.h/cc
so that they can also be used by the upcoming GradientProblemSolver.

Change-Id: I627b32ad3dc639422aacde78a8e391459d947e99
2014-09-07 20:39:14 -07:00
Sameer Agarwal cbf03ac292 Make LineSearchMinimizer consistent with TrustRegionMinimizer.
Change the logic for how IterationSummary objects are added to
Summary::iterations to match the one in TrustRegionMinimizer.

Change-Id: I57851ad8294e58f83b9115cca9c24695d86ee92a
2014-09-07 18:39:00 -07:00
Sameer Agarwal f04c323197 Fix some obsolete documentation in CostFunction::Evaluate
Change-Id: I1d7ee5c596fbf6a4d886dce5b989c8eb18af2dce
2014-09-07 12:30:40 -07:00
Johannes Schönberger 9263547c02 Fix CG solver options for ITERATIVE_SCHUR, which did not copy min_num_iterations
Change-Id: If31bc53b49ec20426fd438b79b8fa1f69d11e861
2014-09-06 17:26:15 -04:00
Martin Baeuml b41f048256 Remove obsolete include of numeric_diff_functor.h.
numeric_diff_functor.h was removed and does not exist anymore.

Change-Id: I07bf04bf81142551e867b95b83a0653e11cad54c
2014-09-05 15:05:37 +02:00
Sameer Agarwal b7fb6056a7 Remove NumericDiffFunctor.
Its API was broken, and its implementation was an unnecessary
layer of abstraction over CostFunctionToFunctor.

Change-Id: I18fc261fc6a3620b51a9eeb4dde0af03d753af69
2014-09-03 16:53:53 -07:00
Sameer Agarwal 175fa8ff09 CostFunctionToFunctor allows dynamic number of residuals.
The code itself was perfectly capable of handling residuals, but there
was an overly strict runtime check that had to be removed.

Thanks to Domink Reitzle for reporting this.

Change-Id: I6a6d000a7c5203dd5945a61b4caeda1b8aeb09c9
2014-09-02 06:52:31 -07:00
Johannes Schönberger 70ace0d5a5 Fix max. linear solver iterations in ConjugateGradientsSolver
Change-Id: Ice0cef46441dbc1c121eeb42113667a46c96936f
2014-08-30 20:37:55 -04:00
Sameer Agarwal c5d8d06802 Fix a unused function error with Eigen version 3.2.1 or less.
Thanks to Johannes Schoenberger  for reporting this.

Change-Id: Ie17d28f2a68734a978a8c95007724bc4055de43a
2014-08-29 20:31:19 -07:00
Sameer Agarwal 0e1cc2a554 Fix the build on Eigen version 3.2.1 and older.
Change-Id: I18f5cb5d42113737d7b8f78a67acee28bd5b3e08
2014-08-29 09:24:59 -07:00
Sameer Agarwal 5f96c62b56 Add Block AMD ordering for SPARSE_SCHUR + EIGEN_SPARSE.
Ordering routines for the Schur complement when using EIGEN_SPARSE.
Also integration into SchurComplementSolver.

Part of this CL is also a refactoring of the block jacobian matrix
construction.

Change-Id: I11d665cc7d4867c64190e6fed1118f4d2e13d59b
2014-08-28 23:57:58 -07:00
Sameer Agarwal 7344626c04 Let EIGEN_SPARSE + SPARSE_NORMAL_CHOLESKY use block AMD.
Modify SparseNormalCholeskySolver to use a pre-ordered Jacobian
matrix.

Change-Id: Ib4d725d7a2d7bb94ea76dbb3a9b172784dbc8ea0
2014-08-28 22:47:27 -07:00
Sameer Agarwal 9f7032369e Block AMD for SparseNormalCholesky + EIGEN_SPARSE.
This is just the reordering routine. The integration with
SparseNormalCholesky shall happen in a subsequent CL.

Change-Id: I39ddc32aa66b11c368faf75404850fa0ae0d2b3a
2014-08-28 21:46:43 -07:00
Sameer Agarwal b9331cd407 Cleanup reorder_program.cc
Program::SetParameterOffsetsAndIndex() was being called willy nilly.
Now the invariant is that any function that actually reorders the
program, updates the offsets and indices.

Also the logic around handling EIGEN_SPARSE has been simplified in
anticipation of the block AMD code that is forthcoming.

Last but not the least, num_eliminate_blocks, which is a rather
cryptic name to begin with has been replaced by the more meaningful
size_of_first_elimination_group.

Change-Id: I77e684f699a93b53e76aa406d64f40f8704df813
2014-08-28 21:25:48 -07:00
Sameer Agarwal 79491a3f4a Solver::FullReport now reports build config.
The header of Summary::FullReport now looks like

Solver Summary (v 1.10.0-suitesparse-cxsparse-lapack-no_openmp)

                                     Original                  Reduced
Parameter blocks                        22122                    22122
Parameters                              66462                    66462
Residual blocks                         83718                    83718
Residual                               167436                   167436

Change-Id: Id1b81bbf90ba412d19e2dd3687eeb9d372b72c1b
2014-08-28 23:30:28 +00:00
Sameer Agarwal 48068c753e Lint cleanup from William Rucklidge.
Change-Id: Ie0e0aa58440be7a4f67dcd633dbb6f1bb0c051a8
2014-08-28 13:03:40 -07:00
Sameer Agarwal 6a51b135e6 Fix solver_test.cc
When Eigen is not installed, Solver::IsValid was not detecting
it correctly.

Change-Id: Id285a84d829a9e20bc5de663adfca66ac31e08f3
2014-08-28 10:48:29 -07:00
Sameer Agarwal 62a8d64453 Expand check for lack of a sparse linear algebra library.
The LinearSolver factory was creating a NULL linear solver
if only Eigen's sparse linear algebra backend was available.

Thanks to Michael Samples and Domink Reitzle for reporting this.

Change-Id: I35e3a6c0fd0da2a31934adb5dfe4cad29577cc73
2014-08-28 09:46:10 -07:00
Sameer Agarwal 12eb389b4e Fix Eigen Row/ColMajor bug in NumericDiffCostFunction.
If the parameter block size is 1, asking Eigen to create
a row-major matrix triggers a compile time error. Previously
we were handling the case where the number of rows in the
jacobian block was known statically, but the problem is present
when the nummber of rows is dynamic.

This CL fixes this problem.

Thanks to Dominik Reitzle for reporting this.

Change-Id: I99c3eec3558e66ebf4efa51c4dee8ce292ffe0c1
2014-08-28 16:34:22 +00:00
Alex Stewart 6c25185bb1 Fix crash in Covariance if # threads > 1 requested without OpenMP.
- Previously if options.num_threads > 1 was given to Covariance compiled
  without OpenMP, a CHECK() would be triggered in program_evalutor.

Change-Id: Iaade4f5ed5326b0c59a7014c750c41ee026e1124
2014-08-28 16:07:51 +01:00
Sameer Agarwal 6f89d850fb Further build breakage fixes.
1. Allow the minimum number of linear solver iterations to be zero.
2. Fix conjugate gradients solver's iteration loop to be sane again.

Change-Id: I8594815fec940c2b30e28eb58ec5d8baacf13dae
2014-08-27 11:51:50 -07:00
Sameer Agarwal dd596d0f0d Fix the broken build.
Change-Id: I083cf1cca1bf4cca956193022d450364e73f833a
2014-08-27 11:26:50 -07:00
Sameer Agarwal d906afae22 A number of bug fixes.
1. Fix a build breakage in graph_test.
2. Respect Solver::Options::min_num_linear_solver_iterations in
   conjugate_gradients_solver.cc

Thanks to Johannes Schönberger for reporting these.

Change-Id: Ib32e3929bf5d92dd576ae5b53d4d88797095136e
2014-08-25 22:32:38 -07:00
Sameer Agarwal dab955928c Add an unweighted graph.
Rename Graph -> WeightedGraph.
Add a new Graph class, which is cheaper to construct and
work with if the weights are not needed.

This cuts down the cost of building the Hessian graph
significantly.

Change-Id: Id0cfc81dd2c0bb5ff8f63a1b55aa133c53c0c869
2014-08-25 09:51:35 -07:00
Sameer Agarwal a0c282adbd Add EIGEN_STRONG_INLINE annotation to jet.h
This improves performance when using MSVC on Windows. On GCC
there will be no effect.

Change-Id: I555a81ff6823c2855d64773073f75af50c48d716
2014-08-25 08:32:41 -07:00
Björn Piltz 20de0a7793 Fixed Malformed regex
I got the following error with MSVC:
Syntax error at index 9 in simple regular expression "NumGroups()": '(' is unsupported.

Change-Id: Id1952831d81d3eb5d73bbed8c311914c4c8ab51f
2014-08-25 17:05:54 +02:00
Björn Piltz ccf8aea988 Fixed MSVC error C2124: divide or mod by zero
Alternatively, if quiet_NaN is not available on all platforms a workaround would be:
    volatile double zero = 0.0;
    double x = 1.0/zero;
The 'volatile' is needed to shut up "warning C4723: potential divide by 0".

Change-Id: If2bbdab8540595aa2e0079e1eb6b6fed6d4a6ef7
2014-08-25 16:16:01 +02:00
Sameer Agarwal 8de27be218 Fix a bug in TrustRegionPreprocessor
TrustRegionPreprocessor was not setting Minimizer::Options::is_constrained.
This meant that the line search for bounds constraints was not being
invoked for bounds constrained problems.

And some minor lint cleanup.

Change-Id: I18852cfaf1b33fd90b7d8c196f2063c128126658
2014-08-19 08:39:48 -07:00
Sameer Agarwal 1745dd615b Refactor SolverImpl.
Replace SolverImpl with

 a. A minimizer specific preprocessor class.
 b. A generic Solve function inside solver.cc
 c. Presummarize and Postsummarize functions to handle
    updates to the summary object.

The existing SolverImpl class was a mixture of the above three
things and was increasingly complicated code to follow. This change,
breaks it into its three separate constituents, with the aims of
better separation of concerns and thus better testability and
reliability.

The call to Solver::Solve() now consists of

1. Presummarize - summarize the given state of the problem and solver
   options.
2. Preprocess - Setup everything that is needed to call the minimizer.
   This includes, removing redundant parameter and residual blocks,
   setting up the reordering for the linear solver, creating the
   linear solver, evaluator, inner iteration minimizer etc.
3. Minimize.
4. Post summarize - summarize the result of the preprocessing and the
   solve.

Change-Id: I80f35cfc9f2cbf78f1df4aceace27075779d8a3a
2014-08-18 13:31:31 -07:00
Sameer Agarwal bd90384226 Lint comments from William Rucklidge.
Also some minor refactoring of the trust_region_preprocessor_test.cc

Change-Id: Ica28002254c95722faf93a7ef35bf3deab557f0b
2014-08-18 11:27:06 -07:00
Sameer Agarwal 3150321db4 Preprocessor for the LineSearchMinimizer.
Change-Id: Ieb5dfe1c0b96ef323c1130edd0c3a8a8b2c644cc
2014-08-12 23:00:07 -07:00
Sameer Agarwal f7da411ef0 Preprocessor for the TrustRegionMinimizer.
1. Base class for preprocessors.
2. A preprocessor for problems that will be solved using
   the trust region minimizer.
3. Added sanity tests to the program reordering options
   for Schur type linear solvers.
4. Tests for the TrustRegionPreprocessor.

Change-Id: I88cd926f0053bbbf2bd6b11e03ec55b8bf473cf1
2014-08-12 21:58:25 -07:00
Alex Stewart 54893ba523 Add missing #include of <limits> for loss functions.
Change-Id: Id632451429e03031a1533a9be795270debc70706
2014-08-11 19:04:18 +01:00
Sameer Agarwal 4a2a888905 Change ownership of pointers in Minimizer::Options.
This is a intermediate change to clean things up
in preparation for a broader refactoring of the SolverImpl.

Essentially we are replacing raw pointers in Minimizer::Options
with shared_ptr objects. For now this only makes things a bit
more complicated looking inside solver_impl.cc, but going
forward this will lead to considerable simplifications in
tracking ownership of various pointers.

Change-Id: I21db8fc6763c29b0d15e834d7c968a0f514042a0
2014-08-07 20:14:12 +00:00
Sameer Agarwal 0d4e3bd664 GradientCheckingProblem's parameter blocks are initialized correctly.
Ensure that when a new problem object is constructed for validing
gradients, the parameter blocks have their data pointers point to
the user's parameter blocks.

We used to do this inside solver_impl.cc, but doing this at
construction is the right thing to do.

Change-Id: I3bfdc89bb0027c8d67cde937e8f2fa385d89c30c
2014-08-07 12:22:48 -07:00
Sameer Agarwal cfb36463f9 Small fixes from William Rucklidge.
Change-Id: I0be52f0f1e53cedccffe4807dc664a2f3fb4a8e4
2014-08-05 14:42:33 -07:00