Commit Graph

170 Commits

Author SHA1 Message Date
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
Björn Piltz 5d7eed87b4 Suppport for MSVC DLLs.
Change-Id: Ibbcc4ba4e59f5bbf1cb91fe81c7d3b9042d03493
2014-04-28 19:56:24 +00:00
Sergey Sharybin ceb7a3beaa Fix compilation error when using G++ compiler
This compiler defines shared_ptr in std::tr1 namespace, but
for this <tr1/memory> is to be included. Further, this compiler
also does have <memory> header which confused previous shared
pointer check.

Simplified logic around defines now, so currently we've got:
- CERES_TR1_MEMORY_HEADER defined if <tr1/memory> is to be
  used for shared_ptr, otherwise <memory> is to be used.
- CERES_TR1_SHARED_PTR defined if shared_ptr is defined in
  std::tr1 namespace, otherwise it's defined in std namespace.

All the shared_ptr checks are now moved to own file FindSharedPtr
which simplifies main CMakeLists.

Change-Id: I558a74793baaa0bd088801910a356be4ef17c31b
2014-04-28 15:37:59 +00:00
Richard Stebbing 32530788d0 Add dynamic_sparsity option.
The standard sparse normal Cholesky solver assumes a fixed
sparsity pattern which is useful for a large number of problems
presented to Ceres. However, some problems are symbolically dense
but numerically sparse i.e. each residual is a function of a
large number of parameters but at any given state the residual
only depends on a sparse subset of them. For these class of
problems it is faster to re-analyse the sparsity pattern of the
jacobian at each iteration of the non-linear optimisation instead
of including all of the zero entries in the step computation.

The proposed solution adds the dynamic_sparsity option which can
be used with SPARSE_NORMAL_CHOLESKY. A
DynamicCompressedRowSparseMatrix type (which extends
CompressedRowSparseMatrix) has been introduced which allows
dynamic addition and removal of elements. A Finalize method is
provided which then consolidates the matrix so that it can be
used in place of a regular CompressedRowSparseMatrix. An
associated jacobian writer has also been provided.

Changes that were required to make this extension were adding the
SetMaxNumNonZeros method to CompressedRowSparseMatrix and adding
a JacobianFinalizer template parameter to the ProgramEvaluator.

Change-Id: Ia5a8a9523fdae8d5b027bc35e70b4611ec2a8d01
2014-04-28 07:13:09 +00:00
Sameer Agarwal 2569076ff0 More NDK fixes.
Fix variable names in port.h and fix fpclassify when
using gnustl. This was tested by switching to gnustl
in the JNI build.

Thanks to Carlos Hernandez for suggesting the gnustl fixes.

Change-Id: I690b73caf495ccc79061f45288e416da1604cc72
2014-04-25 23:55:48 -07:00
Sameer Agarwal e55596f886 Change the defaults for shared_ptr.
By default shared_ptr is now assumed to be
in the standard <memory> header and in the
std namespace.

Previously the way the ifdefs were structured if the appropriate
variable was not defined, it would default to <t1/memory>.

The new defaults are more future proof.

Change-Id: If457806191196be2b6425b8289ea7a3488a27445
2014-04-25 16:17:19 -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 5ecb1c3f1d Add Problem::IsParameterBlockPresent.
This allows the user to query the Problem to see if a
parameter block is already present or not.

Change-Id: If786f6c008cc644f3398597901d718d12a6d865d
2014-04-01 10:04:12 -07:00
Alex Stewart 195e49351b Check validity of residual block before removal in RemoveResidualBlock.
- Breaking change: Problem::Options::enable_fast_parameter_block_removal
  is now Problem::Options::enable_fast_removal, as it now controls
  the behaviour for both parameter and residual blocks.

- Previously we did not check that the specified residual block to
  remove in RemoveResidualBlock actually represented a valid residual
  for the problem.
- This meant that Ceres would die unexpectedly if the user passed an
  uninitialised residual_block, or more likely attempted to remove a
  residual block that had already been removed automatically after
  the user removed a parameter block upon on which it was dependent.
- RemoveResidualBlock now verifies the validity of the given
  residual_block to remove.  Either by checking against a hash set of
  all residuals maintained in ProblemImpl iff enable_fast_removal
  is enabled.  Or by a full scan of the residual blocks if not.

Change-Id: I9ab178e2f68a74135f0a8e20905b16405c77a62b
2014-03-26 17:49:36 +00:00
Alex Stewart 74762b6033 Allow construction of an AutoDiffLocalParameterization with a functor.
- Previously AutoDiffLocalParameterization would internally instantiate
  a functor instance whenever one was required.  This prohibits the
  user passing arguments to the constructor of the functor.
- Now AutoDiffLocalParameterization can take over ownership of an
  allocated functor which the user created.  This mimics the behaviour
  of AutoDiffCostFunction.

Change-Id: I264e1face44ca5d5e71cc20c77cc7654d3f74cc0
2014-03-20 19:32:28 +00:00
Sameer Agarwal a482ab8ad5 Add Problem::SetParameterLowerBound and Problem::SetParameterUpperBound.
These two methods allow the user to associate upper and lower bounds
with individual parameters inside parameter blocks.

Change-Id: I68dc37f20b64408da510ba06b89a4f08df54ddad
2014-02-19 00:06:41 -08:00
Sameer Agarwal f949bab440 Add Problem::GetParameterization.
This allows the user to query the local parameterization associated
with a parameter block.

Change-Id: I3ab274aa88221c8e2def7c463825bf3927b1fdc9
2014-02-18 10:11:02 -08:00
Sameer Agarwal e5d62197b9 Remove all references to int16.
Change-Id: Iab87463dd32f64ee371e6cc7d1f5e30128412a10
2014-02-15 15:02:26 -08:00
Filippo Basso 91da310aeb Added epsilon() method to NumTraits<ceres::Jet<T, N> >.
Change-Id: Ie849b4ae5c7260976ebf2fb21a00f13d1e6bb647
2014-01-19 14:35:23 +01:00
Sameer Agarwal 85561eee95 Use int32 for parameter block sizes.
CostFunction now uses int32 instead of int16
to store the size of its parameter blocks.

This is an API breaking change.

Change-Id: I032ea583bc7ea4b3009be25d23a3be143749c73e
2014-01-07 22:22:14 -08:00
Sameer Agarwal dcee120bac Consolidate SolverTerminationType enum.
1. Rename SolverTerminationType to TerminationType.
2. Consolidate the enum as
  a. CONVERGENCE - subsumes FUNCTION_TOLERANCE, PARAMETER_TOLERANCE and GRADIENT_TOLERANCE
  b. NO_CONVERGENCE
  c. FAILURE - captures all kinds of failures including DID_NOT_RUN.
  d. USER_SUCCESS
  e. USER_FAILURE
3. Solver::Summary::error is renamed to be Solver::Summary::message, to both
reduce confusion as well as capture its true meaning.

Change-Id: I27a382e66e67f5a4750d0ee914d941f6b53c326d
2013-12-17 11:21:33 -08:00
Sameer Agarwal a9334d67d7 Fix constant parameter handling in inner iterations.
There was a bug in the way RemoveFixedBlocksFromProgram was working.
It only removed the constant parameter blocks from the
linear_solver_ordering, it was not even aware of the
inner_iteration_ordering.

This change fixes this bug. The code for RemoveFixedBlocksFromProgram
is also cleaned up and made more readable and the test have been updated.

Thanks to Mikael Persson for reporting this.

Change-Id: I454fa89f9b6f4f6320b02d5235e6f322cc15ff51
2013-11-25 17:44:27 +00:00
Sameer Agarwal 79bde35f29 SuiteSparse errors do not cause a fatal crash.
1. Move LinearSolverTerminationType to ceres::internal.
2. Add FATAL_ERROR as a new enum to LinearSolverTerminationType.
3. Pipe SuiteSparse errors via a LinearSolverTerminationType so
   to distinguish between fatal and non-fatal errors.
4. Update levenberg marquardt and dogleg strategies to deal
   with FATAL_ERROR.
5. Update trust_region_minimizer to terminate when FATAL_ERROR
   is encountered.
6. Remove SuiteSparse::SolveCholesky as it screws up the error
   handling.
7. Fix all clients calling SuiteSparse to handle the result of
   SuiteSparse::Cholesky correctly.
8. Remove fatal failures in SuiteSparse when symbolic factorization
   fails.
9. Fix all clients of SuiteSparse to deal with null symbolic factors.

This is a temporary fix to deal with some production problems. A more
extensive cleanup and testing regime will be put in place in a
subsequent CL.

Change-Id: I1f60d539799dd95db7ecc340911e261fa4824f92
2013-11-21 22:16:24 -08:00
Sameer Agarwal 8c155d51fa Speed up the application of robust loss functions.
Since we added special handling for the case for rho[2] < 0,
the bulk of CorrectJacobian is pointless in the common case.
So add a simple one dimensional loop which rescales the Jacobian.
This speeds up this method immensely.

The robustification of a Jacobian gets speeded up by > 50%.

Change-Id: I97c4e897ccbb5521c053e1fb931c5d0d32f542c7
2013-11-08 22:18:14 -08:00
Sameer Agarwal af04d7f187 Remove DCHECK_GE checks from fixed_array.h
This triggers -Wtype-limits warnings on comparisons
which are always true, since the test being done is
n >= 0, where n is of type size_t, which is always
true.

This causes problems when compiling Ceres on linux
with miniglog.

Change-Id: Ia1d1d1483e03469c71fde029b62ca6d84e9b27e0
2013-11-05 13:47:30 -08:00
Sameer Agarwal 9ba0b352a2 Lint and other cleanups from William Rucklidge
Change-Id: I7fb23c2db85f0f121204560b79f1966f3d584431
2013-11-05 13:04:56 -08:00
Sameer Agarwal c71085ed32 Update to 1.8.0rc1.
Change-Id: Iaa10fd5a20be2ef84aca0119306c44669d87cc5d
2013-10-31 14:07:18 -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 e5ce1170bc Minor bug fix to autodiff.h
Change-Id: Ib41050a2f2ba1898c71ff19d74f8eca2496212c0
2013-10-29 07:40:51 -07:00
Sameer Agarwal c6bafdd02c Comments from Jim Roseborough.
1. Fix the tolerance on the rotation matrix conversion test.
2. Fix some out of date comments.

Change-Id: I65e80da1f96d7b4d9ac0630ad8cb708c41739840
2013-10-28 19:38:08 -07:00
Keir Mierle fda69b5213 Export the structure of a problem to the public API
This adds three new public methods to ceres::Problem:

  Problem::GetResidualBlocks()
  Problem::GetParameterBlocksForResidualBlock()
  Problem::GetResidualBlocksForParameterBlock()

These permit access to the underlying graph structure of the problem.

Change-Id: I55a4c7f0e5f325f140cb4830e7a7070554594650
2013-10-29 02:30:57 +00:00
Sameer Agarwal 21d6a99fe6 Fix AngleAxisToRotationMatrix near zero.
The Taylor series approximation had its sign flipped and the
tests did not catch it since we were switching exactly at zero,
which was not getting triggered.

This changes modifies the tolerance, adds a test that triggers
and fixes the bug.

Thanks to Michael Samples for reporting this.

Change-Id: I6f92f6348e5d4421ffe194fba92c04285449484c
2013-10-25 13:53:52 -07:00
Sameer Agarwal 39a427c736 Speed up AngleAxisRotatePoint.
This leads to a ~11% speedup on my mac using clang.

Based on suggestions by Thad Hughes.

Change-Id: If8495c8de6e28f63fb065e35bd6f382dd9fcbbea
2013-10-23 11:45:57 -07:00
Sameer Agarwal 4ad80b7d96 Documentation update.
Update the documentation for Solver::Summary in
solver.h

Also minor typo fixes in solving.rst.

Change-Id: Id9363940ef843b7ce92013fdbb866168e0c5705f
2013-10-21 12:34:57 +00:00
Sameer Agarwal 3654a79b8e Update documentation.
1. Update the documentation to be Sphinx friendly.

2. Remove dead fields in Solver::Summary.
   a. Solver::Summary::num_eliminate_blocks_given.
   b. Solver::Summary::num_eliminate_blocks_used.

Change-Id: I43e0070c88abe3bf285d91e6c7524f3d887deb33
2013-10-11 12:53:59 -07:00
Sameer Agarwal 35ee1f715c Remove RuntimeNumericDiffCostFunction.
Move the GradientCheckingCostFunction to DynamicNumericDiffCostFunction.

Also fix a const correctness issue with DynamicNumericDiffCostFunction.

Change-Id: Id446810f43374e7b7db7fe4dd01a891e3c54abb9
2013-10-09 10:12:43 -07:00
Alex Stewart 468a23f211 Fix operator= ambiguity on some versions of Clang.
- Earlier versions of Clang (up to at least v3.0) throw an ambiguous
  operator= error in this assignment.  Variations on this error have
  cropped up occassionally in some other projects (e.g. PCL).

Change-Id: I73a632c43528eb69840ce697c55d9afc5f3d8e59
2013-10-04 10:58:18 +01:00
Sameer Agarwal fa00ca919e Consistent indentation
Change-Id: Icdba3a86b726fe2096142ccd32a121c326d9686c
2013-10-03 14:46:37 -07:00
Sameer Agarwal 10ac7d8048 Lint cleanup and a bug fix.
Thanks to William Rucklidge.

Change-Id: I963656be661020abacbff792cfc3025623503db8
2013-10-03 14:37:07 -07:00
Sameer Agarwal 5090cb4e8d Fix the broken build.
The changes to the NumericDiffCostFunction API, broke
NumericDiffFunctor. This changes fixes it.

Change-Id: Ibf90bcf9dfc47bd7034c6102f1ef50283dced675
2013-10-03 13:24:45 -07:00
Sameer Agarwal 40df20b4aa Add DynamicNumericDiffCostFunction.
This brings the ability to have numerically differentiated
cost functions to be added with its structure decided on
runtime rather than compile time.

And some minor cleanups.

Two things still need to be done.

a. Update the modeling docs.
b. Remove RuntimeNumericDiffCostFunction in ceres::internal
   and replace its usage with DynamicNumericDiffCostFunction.

Change-Id: Ib771f093f29236c95a99df31c584d579b8e36615
2013-10-03 20:10:18 +00:00
Sameer Agarwal 3a2158d728 NumericDiffCostFunction supports dynamic number of residuals.
1. Update AutoDiffCostFunction template parameters to be consistent
with NumericDiffCostFunction.

2. Update the documentation for NumericDiffCostFunction and
AutoDiffCostFunction.

Change-Id: I113038abb5bedebb0f6f326f2a4ac31480d785fc
2013-10-03 20:09:59 +00:00
Sameer Agarwal ecae1f07ea Lint cleanups.
Thanks to William Rucklidge and Jim Roseborough.

Change-Id: Ibc1a2daf0af878f737ea43e878990ead4e73f63d
2013-09-24 11:20:19 -07:00
Sameer Agarwal c9122c3b7b MUST_USE_RESULT -> CERES_MUST_USE_RESULT
Change-Id: I23dfde2e699b37840a192fa082e932f5a96dd4a9
2013-09-23 22:13:24 -07:00
Tim Langlois 91087e8936 Added some small optimizations to the jet class (initialize values
directly from eigen expressions, instead of creating a temporary). Also
changed several variable names from temp to tmp to be consistent with
the code base.

Change-Id: I3f7b834cedca9c4af8e5e086237b40301dbde619
2013-09-23 20:39:28 +00:00
Sameer Agarwal 11bf5ffb96 Add RequireInitialization = 1 to NumTraits::Jet.
Thanks to Nima Kevian for reporting this.

Change-Id: I9c45f4cabc8d5ce246c2a6ebe102161c6a771df5
2013-09-19 22:46:29 +00:00
Sameer Agarwal 4d2df0cf34 Add IterationSummary::gradient_norm.
Iteration summary now reports the 2-norm of the gradient also.

Change-Id: I1ed7f1456ee4f546c9b42423d7a4ec3079ec078f
2013-09-13 12:54:03 -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 16924168ce Update version from 1.6.0 -> 1.7.0rc1.
Change-Id: I420a8907142bffad0e3aa6c7196541ca2309c099
2013-07-18 13:35:01 -07:00
Sameer Agarwal 5a974716e1 Covariance estimation using SuiteSparseQR.
Change-Id: I70d1686e3288fdde5f9723e832e15ffb857d6d85
2013-07-17 22:56:01 -07:00
Sameer Agarwal 719889b8b7 Minor fixes
1. Typo in c_api.h
2. The stream operator for FunctionSample is now in the ceres::internal namespace.

Change-Id: Id927a7a49c47d8903505535749ecca78cd2e83b3
2013-07-17 11:31:08 -07:00
Alex Stewart 9aa0e3cf72 Adding Wolfe line search algorithm and full BFGS search direction options.
Change-Id: I9d3fb117805bdfa5bc33613368f45ae8f10e0d79
2013-07-17 08:14:20 +00:00
Sameer Agarwal 3c2ad4018c Speed up Automatic differentiation by 7%.
1. Templatize Make1stOrderPerturbation.
2. Convert a hard CHECK into DCHECK.

Change-Id: I02cd67f2b87bc5722f1a090057d55f23e98d2c3b
2013-07-15 08:09:38 -07:00
Keir Mierle 6e8bd501b2 Extend the C API to support loss functions
This extends the C API to support loss functions. Both
user-supplied cost functions as well as the stock Ceres cost
functions (Cauchy, Huber, etc) are supported. In addition, this
adds a simple unit test for the C API.

Supporting loss functions required changing the signature of the
ceres_add_residual_block() function to also take a thunk for the
loss function.

Change-Id: Iefa58cf709adbb8f24588e5eb6aed9aef46b6d73
2013-07-09 06:28:55 +00:00