Commit Graph

761 Commits

Author SHA1 Message Date
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
Sameer Agarwal 9a41132a05 Small changes from Jim Roseborough.
Change-Id: Ic8b19ea5c5f4f8fd782eb4420b30514153087d18
2014-08-05 05:49:27 +00:00
Sameer Agarwal a521fc3afc Simplify, cleanup and instrument SchurComplementSolver.
The instrumentation revealed that EIGEN_SPARSE can be upto
an order of magnitude slower than CX_SPARSE on some bundle
adjustment problems.

The problem comes down to the quality of AMD ordering that
CXSparse/Eigen implements. It does particularly badly
on the Schur complement. In the CXSparse implementation
we got around this by considering the block sparsity structure
and computing the AMD ordering on it and lifting it to the
full matrix.

This is currently not possible with the release version of
Eigen, as the support for using preordered/natural orderings
is in the master branch but has not been released yet.

Change-Id: I25588d3e723e50606f327db5759f174f58439e29
2014-08-01 16:42:00 -07:00
Sameer Agarwal b43e73a034 Simplify the Eigen code in SparseNormalCholeskySolver.
Simplifying some of the template handling, and remove the use
of SelfAdjointView as it is not needed. The solver itself takes
an argument for where the data is actually stored.

The performance of SparseNormalCholesky with EIGEN_SPARSE
seems to be on par with CX_SPARSE.

Change-Id: I69e22a144b447c052b6cbe59ef1aa33eae2dd9e3
2014-08-01 12:10:04 -07:00
Sameer Agarwal 031598295c Enable Eigen as sparse linear algebra library.
SPARSE_NORMAL_CHOLESKY and SPARSE_SCHUR can now be used
with EIGEN_SPARSE as the backend.

The performance is not as good as CXSparse. This needs to be
investigated. Is it because the quality of AMD ordering that
we are computing is not as good as the one for CXSparse? This
could be because we are working with the scalar matrix instead
of the block matrix.

Also, the upper/lower triangular story is not completely clear.
Both of these issues will be benchmarked and tackled in the
near future.

Also included in this change is a bunch of cleanup to the
SparseNormalCholeskySolver and SparseSchurComplementSolver
classes around the use of the of defines used to conditionally
compile out parts of the code.

The system_test has been updated to test EIGEN_SPARSE also.

Change-Id: I46a57e9c4c97782696879e0b15cfc7a93fe5496a
2014-07-31 22:05:34 -07:00
Sameer Agarwal 1b17145adf Make canned loss functions more robust.
The loss functions that ship with ceres can sometimes
generate a zero first derivative if the residual is too
large.

In such cases Corrector fails with an ugly undebuggable
crash. This CL is the first in a series of fixes to
take care of this.

We clamp the values of rho' from below by
numeric_limits<double>::min().

Also included here is some minor cleanup where the constants
are treated as doubles rather than integers.

Thanks to Pierre Moulon for reporting this problem.

Change-Id: I3aaf375303ecc2659bbf6fb56a812e7dc3a41106
2014-07-30 10:14:15 -07:00
Alex Stewart b27a2044b3 Fix type of suppressed compiler warning for Eigen 3.2.0.
- Warning type generated is unused-but-set-variable, not unused-variable
  and the corresponding "local variable is initialized but not
  referenced" MSVC warning.

Change-Id: I716fd6a87cc91533bc862b2ef932601c8857818d
2014-07-22 19:38:50 +01:00
Alex Stewart b76615a670 Suppress unused variable warning from Eigen 3.2.0.
- Eigen 3.2.0 emits an unused variable warning from Ordering.h
  #included by Eigen/SparseQR which prevents Ceres compilation due
  to -Werror.
- As Eigen 3.2.0 is still in widespread use, we explicitly disable
  the warning only around the inclusion of Eigen/SparseQR.

Change-Id: I48ce905ef6a22bc1b06f9e5bed328bd315f407f0
2014-07-22 18:18:08 +00:00
Sameer Agarwal c89e82e001 Drop iostream from solver.cc
Change-Id: I512a247c183113ef5dcf09e13f19c17c83293f21
2014-07-22 10:53:32 -07:00
Sameer Agarwal bb3b865883 Add sstream header to solver.cc
Thanks to Filippo Basso for reporting this.

Change-Id: I45059cd66bad9d26e706fc3011f714cf60121320
2014-07-22 10:47:46 -07:00
Sameer Agarwal 060a850602 Remove SPARSE_CHOLESKY based covariance estimation.
Sparse Cholesky factorization is not rank revealing. Therefore
this algorithm cannot reliably tell when the Jacobian matrix is
rank deficient or so poorly conditioned that the covariance matrix
cannot be estimated.

Making things worse, this algorithm works on the normal equations,
which makes the conditioning problem much worse.

This change, deletes the SPARSE_CHOLESKY algorithm in the covariance
estimation code. Also to make the naming consistent, it renames

SPARSE_QR -> SUITE_SPARSE_QR

so that it parallels EIGEN_SPARSE_QR.

Also, since we now have EIGEN_SPARSE_QR, we can default to using
it when SuiteSparse is not available instead of DENSE_SVD, which
generally speaking should only be used by folks who are dealing
with small rank deficient jacobians.

Change-Id: I8b134c7e8a2e86ca374371f185b19f1c3e74349c
2014-07-20 07:35:35 -07:00
Sameer Agarwal c2131dea9c Add "make install" to the install instructions.
Alessandro Gentilini pointed out that the install instructions
don't actually install the library.

Also included are some other minor changes to dependency
description.

Change-Id: I50872114bca7a9774ef66f55ba78ed9b7adad93f
2014-07-13 13:50:43 -07:00
Alessandro Gentilini c1485df515 Correct formula in documentation of Solver::Options::function_tolerance.
Change-Id: I5cfb9d58bd2ea12e9be46fb9d9e5a37466b0a7cb
2014-07-13 12:18:29 +00:00
Mike Vitus 0bbb48a941 Adds support for computing the covariance using Eigen's sparse QR module.
For smaller problems Eigen is faster than SuiteSparseQR. This has been
tested with Eigen 3.2.1. Below are detailed timings. Problem 1 is the
smallest and problem 3 is the largest. The timings below are:
mean +- standard deviation.

Problem 1:
Eigen       0.0009218 +- 0.0002755
SuiteSparse 0.001406 +- 0.001610

Problem 2:
Eigen       0.002338 +- 0.001005
SuiteSparse 0.001910 +- 0.0004513

Problem 3:
Eigen       0.005455 +- 0.001759
SuiteSparse 0.002411 +- 0.0004974

Detailed problem descriptions:

Problem 1 size:
                               Original                  Reduced
Parameter blocks                533                       54
Parameters                      368                      104
Effective parameters           1201                       94
Residual blocks                 233                       77
Residual                       1194                      258

Problem 2 size:
                              Original                  Reduced
Parameter blocks                573                       84
Parameters                     1458                      184
Effective parameters           1281                      164
Residual blocks                 263                      107
Residual                       1314                      378

Problem 3 size:
                              Original                  Reduced
Parameter blocks                613                      114
Parameters                     1548                      264
Effective parameters           1361                      234
Residual blocks                 293                      137
Residual                       1434                      498

Change-Id: I884a67e2f728fe2992812148d82ccf5f27864fd7
2014-07-11 14:42:48 -07:00
Alex Stewart 22b26cd7b7 Add release flags to iOS toolchain.
- Without explicitly specifying the flags for release compilation in
  the iOS toolchain file, no additional flags are passed and so the
  libraries were not being built with full optimisations, even though
  the CMAKE_BUILD_TYPE was 'Release'.

Change-Id: I742bab7589906b556640776d481491a8cc2303d4
2014-07-07 22:08:24 +01:00
Sameer Agarwal 753ada79ea Fix a bug in assert_ndk_version.sh
The version parsing code was hard coding the fact that the
desired version is of the form

r + NUMERIC_MAJOR_VERSION + ALPHABETIC_MINOR_VERSION

r10 release of the NDK does not have a minor version an it breaks
the logic.

The fix is to make the version extraction be more robust to the
optional presence of the minor version.

Change-Id: Iace13ae7cad8cbd93ed635ecf7f1dce3a3ae15d5
2014-07-07 11:11:55 -07:00
Sameer Agarwal 0a9bca18f1 Fix a broken hyperlink in the documentation.
Thanks to Henrique Mendonca for pointing this out.

Change-Id: I40a214cfa900265f85492017799a5f2062904d76
2014-07-06 08:18:18 -07:00
Alex Stewart da86231ddd Add fixes for multiple definitions of ERROR on Windows to docs.
- Explain the various ways to fix the problem of multiple definitions
  of ERROR from glog / miniglog vs windows.h.
- Add note about use of CMAKE_LIBRARY_PATH to aid FindBLAS & FindLAPACK.
- Fix minor style typo in code-block for sample Ceres output.

Change-Id: I21742614f4c5a8fe1ac8f66811b7777a72bcc503
2014-06-15 14:21:49 +01:00
Sameer Agarwal 603277d343 Add check for dynamic sparsity in Solver::Options::IsValid.
Dynamic sparsity should only be used with SPARSE_NORMAL_CHOLESKY.

Change-Id: I8dd33c05ec0337b3c13b547ecffe3aefc3e5ab12
2014-06-10 10:07:53 -07:00
Sameer Agarwal e9fcf3decb Add OrderedGroups::MinNonZeroGroup.
Change-Id: If571c2435a7c884b472c33421722208cb2d036ff
2014-06-09 13:14:05 -07:00
Alex Stewart ec6bfa5b12 Compile miniglog into Ceres if enabled on all platforms.
- Previously if miniglog was being used (on a non-Android system), we
  compiled it into a separate library, against which Ceres then linked.
- This was unsatisfactory as it required miniglog being built as a
  static library when building Ceres as a Windows DLL, because miniglog
  did not use the dllexport/dllimport statements, whilst for other
  platforms when building Ceres as a shared library, miniglog needed to
  be compiled as a shared library.

- We now compile miniglog into Ceres on all platforms, not just on
  Android.
- miniglog now uses the CERES_EXPORT macro to support Windows DLLs.
  This means that miniglog now depends on Ceres' internal/port.h (and
  thus internal/config.h) which define the CERES_EXPORT macro and
  control its behaviour respectively.
- miniglog now also uses localtime_s, not localtime on Windows.

Change-Id: Ia55b9af8b4e6decf067eab92f0a5c2d14358a1e9
2014-06-09 19:02:07 +00:00
Sameer Agarwal 0cc1bc5bbd Add missing files to the NDK build.
Add reorder_program.cc and also fix an include
error which was only triggered by the NDK build.

Change-Id: Ic800687d1857be1e3d60a44b87595d59e52c1117
2014-06-06 15:24:03 -07:00
Sameer Agarwal e497f4939a Refactor reordering routines.
Move all the program reordering programs into their own file.
Also split the reordering routines for SPARSE_NORMAL_CHOLESKY
into individual library dependent routines.

Also get rid of RemovedFixedBlocksFromProgram.

Change-Id: Ie969f529e6d20dded9da021b9df1a040e08287c1
2014-06-06 05:32:21 +00:00
Sameer Agarwal 4fce29c29e Documentation update.
Update the documentation to reflect the new trust region solver
logging style.

Change-Id: Id2d6b9efeee86c690c349a225d344e9f97ddbcdf
2014-06-06 05:02:07 +00:00
Greg Coombe 252917655b Add two missing files to Android.mk
Change-Id: Ic69a9550874de9540fbb351b882d87541e7c2542
2014-06-05 17:05:36 -07:00
Sameer Agarwal bb5baea725 Improve NDK version detection.
The script assert_ndk_version.sh used to require that the user
either define ANDROID_NDK_ROOT or ndk-build be in the path
so that ANDROID_NDK_ROOT can be inferred.

But since we are always calling this script from within an
Android.mk file, ndk-build already defines a variable called
NDK_ROOT, which we can pass to the script, thereby simplifying it
and making it more robust.

Change-Id: I31d66529a36a93e760e0dd0f17cfe61428fbac55
2014-06-05 12:18:23 -07:00
Sameer Agarwal d54e98777f Add a note about git commit message style.
Update contributing.rst to point to Tim Pope's suggestions
for how to write git commit messages.

Change-Id: Idcbece3e7576f54794d8a107aa2c5aa48dc4ddf7
2014-06-05 19:10:19 +00:00
Sameer Agarwal 14ec849eac Change logging for TRUST_REGION.
The current logging for trust region minimizer is very informative
but cryptic. Single or double letter abbreviations must be deciphered
to make sense of it.

Here is an alternate take on it.

Before:

   0: f: 4.185660e+06 d: 0.00e+00 g: 2.16e+07 h: 0.00e+00 rho: 0.00e+00 mu: 1.00e+04 li:  0 it: 7.36e-02 tt: 3.47e-01
   1: f: 1.980525e+05 d: 3.99e+06 g: 5.34e+06 h: 2.40e+03 rho: 9.60e-01 mu: 3.00e+04 li:  1 it: 1.80e-01 tt: 5.27e-01
   2: f: 5.086543e+04 d: 1.47e+05 g: 2.11e+06 h: 1.01e+03 rho: 8.22e-01 mu: 4.09e+04 li:  1 it: 1.57e-01 tt: 6.84e-01
   3: f: 1.859667e+04 d: 3.23e+04 g: 2.87e+05 h: 2.64e+02 rho: 9.85e-01 mu: 1.23e+05 li:  1 it: 1.50e-01 tt: 8.34e-01
   4: f: 1.803857e+04 d: 5.58e+02 g: 2.69e+04 h: 8.66e+01 rho: 9.93e-01 mu: 3.69e+05 li:  1 it: 1.47e-01 tt: 9.82e-01
   5: f: 1.803391e+04 d: 4.66e+00 g: 3.11e+02 h: 1.02e+01 rho: 1.00e+00 mu: 1.11e+06 li:  1 it: 1.51e-01 tt: 1.13e+00

After:

iter      cost      cost_change  |gradient|   |step|    tr_ratio  tr_radius  ls_iter  iter_time  total_time
   0  4.185660e+06    0.00e+00    2.16e+07   0.00e+00   0.00e+00  1.00e+04       0    7.16e-02    3.27e-01
   1  1.980525e+05    3.99e+06    5.34e+06   2.40e+03   9.60e-01  3.00e+04       1    1.77e-01    5.04e-01
   2  5.086543e+04    1.47e+05    2.11e+06   1.01e+03   8.22e-01  4.09e+04       1    1.49e-01    6.54e-01
   3  1.859667e+04    3.23e+04    2.87e+05   2.64e+02   9.85e-01  1.23e+05       1    1.45e-01    7.99e-01
   4  1.803857e+04    5.58e+02    2.69e+04   8.66e+01   9.93e-01  3.69e+05       1    1.46e-01    9.45e-01
   5  1.803391e+04    4.66e+00    3.11e+02   1.02e+01   1.00e+00  1.11e+06       1    1.48e-01    1.09e+00

Change-Id: I251f99d474028e07cb709965d513809c443884b6
2014-06-05 19:09:29 +00:00
Greg Coombe 2a5599f378 Fix Cmake error when using miniglog.
Create the glog include directories and library directories
only if we've already checked that the user is using
glog (and not miniglog).

Otherwise, @GLOG_INCLUDE_DIR@ and @GLOG_LIBRARY@ will be
empty and the generated files will cause Cmake errors.

Change-Id: Ia0ce9cf98f7d56c83b2285f72f45b8e0d5dc34c4
2014-06-04 23:21:33 +00:00
Björn Piltz add50e3697 Don't build miniglog unconditionally as a static library
This is only needed on Windows because of lacking dllexport's.

Change-Id: I7ee4b3fd640d5870af2a73d7bfa6ccc8356b2fa0
2014-06-04 10:23:41 +02:00
Björn Piltz 4c5f6cd032 Added missing include.
MSVC complained about not finding std::min(),

Change-Id: If0a1eb77fa2988cabf26da4a49bf018e34a38b9c
2014-06-04 10:17:04 +02:00
Sameer Agarwal c8063df917 POLAK_RIBIRERE -> POLAK_RIBIERE
Thanks to Vladimir Chalupecky for reporting this.

Change-Id: I2e419415394f5d2be35b825d7c777b01ff31add1
2014-06-03 20:30:15 -07:00
Alex Stewart 52bad6223b Adding assert_ndk_version for Android from Jørgen Tjernø.
- Ceres now requires Android NDK version >= r9d to compile, Jørgen's
  script allows a clean way to verify this condition is met before
  trying to compile for Android.
- Note that this is a modified version of the original script, which
  adds support for versions >= 10, and fixes extraction of the version
  number now that the architecture is also included.

Change-Id: Icd7ffd25407bcf29af007e30b5da5d18eb799adf
2014-06-03 23:25:56 +01:00
Sameer Agarwal 70af9a58f1 Improve logging in Solver::Options::IsValid.
The error message now includes the value of the offending option.

Change-Id: Ic2493709f54f7efe59313d51d1ff9638191c8b38
2014-06-03 16:06:23 +00:00
Sameer Agarwal 79df23ed78 Remove NDK/Eigen bug work around.
The bug was multiple compilers ago. Now is as good a point as
any to remove the work around.

Change-Id: I1f14732d042fe061adcb31b14a6b39d8fc0ca69e
2014-06-02 21:33:40 -07:00
Sameer Agarwal 5d51e4d4bc Addressing comments from Jim Roseborough.
Change-Id: I9f5bdb4a81cd25ee4ea5de65aeddcaa0c5d18197
2014-06-02 08:12:11 -07:00
Sameer Agarwal b4a5f7ea25 Program::RemoveFixedBlocks -> Program::CreateReducedProgram.
CreateReducedProgram is a safer API, reduces the possibility of
memory leaks and produces valid programs.

Change-Id: I094d53d207fced970a4d9ea0b66cdb09ce5f0657
2014-06-01 16:38:08 -07:00
Sameer Agarwal 29fe072781 Solver::Options::min_relative_decrease can be zero.
Change-Id: I82ae5227ad0f8f6ff21e859e11f0d18ac7d9828c
2014-06-01 00:25:34 -07:00
Sameer Agarwal 226a95e488 Fix more typos in solver.cc
A number of typos in solver.cc which were hidden behind ifdefs
and were only revealed when building under android.

Change-Id: I89cbe8056da071479d2d1a251a8919b0be1f1cd4
2014-06-01 06:55:18 +00:00
Sameer Agarwal 7135be7b34 Conditionally disable SparseNormalCholesky.
Disable creation of SparseNormalCholesky if CXSparse and
SuiteSparse are not evailable.

Change-Id: I9a3beafef0073d1c55305beb0af31bc67ef39691
2014-05-31 23:44:18 -07:00
Sameer Agarwal be43201953 Update Android.mk
Add callbacks.cc and summary_utils.cc.

Change-Id: Ia356b0c82138ca4c2235015986deff0e30b37304
2014-05-31 23:30:32 -07:00
Sameer Agarwal e911db19aa Fix a memory leak in program_test.cc
Program::RemoveFixedBocks will happily drop all fixed parameter
and residual blocks. So if it is called on the one and only copy
of a program, like it was being called in the tests, this will
result in a memory leak because we would have lost track of the
fixed parameter and residual blocks.

This is not a problem in actual usage since CreateReducedProgram
will first create a copy of the program and then remove the fixed
blocks from it. But in the tests, we were creating a ProblemImpl
and then calling RemovedFixedBlocks on the underlying program
object causing a memory leak.

The fix to make a copy in the tests and then work on that. I
have also added a warning in program.h

Change-Id: I03a5f7a7f5453aec848451a5c0ace4b065f71e9b
2014-05-31 23:21:44 -07:00
Sameer Agarwal 19dee8d591 Fix a typo in solver.cc
Change-Id: I3f2e058e2d45c72eaa12129ff0b9366332ee87f5
2014-05-31 23:04:44 -07:00
Sameer Agarwal 99dead5cbf Move inner iteration ordering related methods.
Inner iterations require specific constraints on parameter
block orderings. The creation and validation routines for
these orderings are not static methods in CoordinateDescentMinimizer.

Change-Id: Ifc89491c9a8672e08523191b74b53058cbfa1db3
2014-05-30 16:16:27 -07:00
Sameer Agarwal 1228a4f332 Move alternate linear solver and preconditioner policy.
Move functions that determine alternatives to Schur type linear
solver and preconditioners into the LinearSolver and Preconditioner
interfaces.

Change-Id: Iae900afb7db17cdbeb7753497005a48c3144e2d7
2014-05-30 15:58:44 -07:00