Commit Graph

154 Commits

Author SHA1 Message Date
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
Sameer Agarwal eeedd2e191 Rationalize some of the variable names in Solver::Options.
lm_max_diagonal -> max_lm_diagonal
lm_min_diagonal -> min_lm_diagonal
linear_solver_max_num_iterations -> max_linear_solver_iterations
linear_solver_min_num_iterations -> min_linear_solver_iterations

This follows the pattern for the other parameters in Solver::Options
where, the max/min is the first word followed by the name of the
parameter.

Change-Id: I0893610fceb6b7983fdb458a65522ba7079596a7
2013-07-07 23:04:31 -07:00
Sameer Agarwal 67ccb7379e Fix broken build.
Change-Id: Ieb122bb96d5776f962fff6d6e9345dfc855bfed7
2013-07-03 06:28:34 -07:00
Sameer Agarwal 4f010b2db0 Improve Summary::FullReport when line search is used.
Disable reporting of preconditioner when direct factorization
is being used.

Change-Id: Id264d2292c5cab608724a6a8fab5d588db950468
2013-07-01 08:01:01 -07:00
Sameer Agarwal 09244015e3 Expose line search parameters in Solver::Options.
Change-Id: Ifc52980976e7bac73c8164d80518a5a19db1b79d
2013-06-30 22:51:21 -07:00
Sameer Agarwal 79d9353036 Remove Protocol Buffers support.
Change-Id: I451c543c82cdfb566736aab94d836abcfb5c689d
2013-06-24 14:28:40 -07:00
Richard Stebbing 6dd18563a1 Fix DynamicAutoDiffCostFunction
Changed DynamicAutoDiffCostFunction to handle multiple derivative
sections as opposed to just a single contiguous block.

In the previous implementation it was assumed that non-constant
parameters occur in a single contiguous block so that constant
parameters could NOT lie between non-constant parameters. Previously,
start_derivative_section was first set as soon as the first
non-constant parameter block (marked by jacobians[i] != NULL) was
encountered. After this, entries in input_jets[parameter_cursor].v were
accessed with `parameter_cursor - start_derivative_section`. For
contiguous non-constant parameter blocks this is fine, but if constant
parameter blocks fall between then this indexing is incorrect because
`parameter_cursor - start_derivative_section` can go out of bounds.

For a concrete example, take a cost function with three parameter
blocks, each of size 1 and with the center block fixed. Assume that
Stride=1 so that two passes are required. On the first pass
start_derivative_section=0, and the first variable block is handled
correctly. At the end of the first pass end_derivative_section=1, so
for the second pass start_derivative_section=1. Now comes the problem.
When parameter_cursor=1, parameter_cursor >= start_derivative_section
so jacobian[1] is checked to be NULL. Since it is NULL (second
parameter block is constant) then nothing is done and
active_parameter_count is NOT incremented. Next, when
parameter_cursor=2, parameter_cursor >= start_derivative_section and
jacobian[2] is checked. Since it is not NULL then
input_jets[parameter_cursor].v[parameter_cursor -
start_derivative_section] is set to 1.0, BUT parameter_cursor -
start_derivative_section = 2 - 1 = 1 which is out of bounds
(input_jets[parameter_cursor].v is only of size Stride=1).

The proposed solution records the start of each contiguous block of
non-constant parameters and indexing into
input_jets[parameter_cursor].v is independent of parameter_cursor.

Change-Id: I388ab6a0bafa35d317491135ec6fe980453ff888
2013-06-19 02:24:31 +01:00
Sameer Agarwal c4a329155c Enable support for dumping trust region minimizer problems.
This support was broken due to the TrustRegionMinimizer refactoring.
It is now enabled again, with the responsibilty for dumping the
problem shifted to the individual TrustRegionStrategy.

There is however one wrinkle, which is perhaps an indication of
poor design to start with. The LinearLeastSquaresProblemProto
carries in it num_eliminate_blocks, something which does not
exist anymore. More importantly, the TrustRegionStrategy does not
have access to this quantity anymore.

Dealing with this will be the subject of a future change.

Change-Id: I358adf6a2e386f4940b617bf950d6c7e87d2635d
2013-06-13 22:00:48 -07:00
Sameer Agarwal 1f17f56c4e Add Covariance documentation to html docs.
Change-Id: I11ddc9f7069964596760c6ea4d85c44312c0a67a
2013-06-09 23:23:38 -07:00
Sameer Agarwal f3e1267aa1 Update the documentation for Covariance.
Remove some of the dire warnings about instability
as the implementation is reasonably stable.

Change-Id: I3b64cab04e4cda54c671fcf8a2ca5d95c15037bf
2013-06-04 21:52:12 -07:00
Sameer Agarwal 8f7e8963cb Multithread covariance estimation.
1. Multithread the inversion of J'J.
2. Simplify the dense rank truncation loop.
3. Minor correction to building documentation.

Change-Id: Ide932811c0f28dc6c253809339fb2caa083865b5
2013-06-04 16:19:45 -07:00
Sameer Agarwal 4437639e9b Documentation updates.
1. Further tightening of the Covariance documentation.
2. Documented minimizer progress output.
3. Lint cleanup from William Rucklidge.
4. Updated version history.

Change-Id: I8bc28484675d4edf89a7c050b6379dbac6c39e91
2013-06-03 09:41:27 -07:00
Sameer Agarwal 7129cd3157 Pay attention to condition number in covariance estimation.
1. Sparse covariance estimation now uses cholmod_rcond to
detect singular Jacobians.

2. Dense covariance estimation now uses relative magnitude
of singular/eigen values to compute the pseudoinverse.

3. Truncation logic is now unified with Solver::Options::null_space_rank.

Change-Id: I095bd737510c836b4251255926190a7f31d64bce
2013-06-02 23:36:27 -07:00
Sameer Agarwal f0b071bac4 Lint and other fixes from William Rucklidge
Change-Id: Ic18561a5cdadccc75e97818fa4422bb5d9d43df9
2013-05-31 13:22:51 -07:00
Sameer Agarwal 0939632c57 More documentation updates
Change-Id: I762bd28b4ebc327d39a572990e02157ef55ad617
2013-05-30 07:39:38 +00:00
Johannes Schönberger a8d38d438a Add sinh, cosh, tanh and tan functions to automatic differentiation
Change-Id: I6eb43fe9b340d4074ed3eed1461dda315f6e8ce8
2013-05-30 00:39:43 +02:00
Sameer Agarwal ebbb984db8 Various corrections and enhancements to the documentation.
Change-Id: I03519bfccf4367b36d36006f1450d5fbcbbf8621
2013-05-28 10:37:01 -07:00