Commit Graph

115 Commits

Author SHA1 Message Date
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
Sameer Agarwal 9f9488b162 Add iteration and time reporting for inner iterations.
Also

1. Remove an inadvertent LOG(INFO) from trust_region_minimizer.cc
2. Refactor some of the code in FullReport to reduce duplication
   across line search and trust region minimizers.
3. Consistent capitalization.

Change-Id: I9078b1704efab23d2858530636f524e60c7d9016
2013-05-23 21:03:31 +00:00
Sameer Agarwal d4cb94b6d6 Add adaptive stopping to inner iterations.
Change-Id: I83c909b8b87f1320aa30dcc80ac43a63765b9181
2013-05-22 20:04:57 +00:00
Sameer Agarwal 45ac14fac7 Add destructor to Covariance.
This allows CovarianceImpl to be forward declared without
scoped_ptr freaking out.

Thanks to Nima Keivan for reporting this.

Change-Id: Icd5aa766b3aab70246055225231a4b971c6b7b90
2013-05-20 09:16:28 -07:00
Sameer Agarwal 02706c1906 Sparse covariance estimation.
Add a Covariance object to the API.

Given a Problem object and a set of parameter block pairs the
Covariance object computes a sparse covariance matrix corresponding
to those block pairs and provides random access to them.

Constant parameter blocks and parameter blocks with local parameterizations
are correctly handled.

Sparse and dense implementations are provided. With the dense implementation
rank deficient Jacobians can also be handled.

Parts of the code are threaded using OpenMP if available.

Change-Id: I5b49583b3d79579df3e0f334c22567acb23ed4ad
2013-05-18 23:33:02 -07:00
Keir Mierle f956615ef1 Proof of concept C API for Ceres
This introduces a simple C API for a subset of Ceres. This opens the door to
using languages like Python to call Ceres, since it is much easier to bind to C
than it is to bind to C++. It will mean giving up the native Ceres autodiff.

The implementation in this patch does not attempt to do everything but is only
just enough to get started. Subsequent patches will increase the surface area
of Ceres that is covered by the C API.

Change-Id: Ic51804bac6865e1a2e476553248aabc91dff3409
2013-05-19 06:29:18 +00:00
Sameer Agarwal a1eaa262ea Update glog path
Change-Id: I47a69cb267c71a9f8f3350c4f645e8cf83e44cc9
2013-05-09 10:09:38 -07:00
Sameer Agarwal 01fb8a3133 Add documentation about CostFunction::Evaluate.
Change-Id: I1df42c14f20c7c03f2a8ae21e75dda98cc592214
2013-04-30 21:04:24 -07:00
Sameer Agarwal 937777a5ac Miscellanous fixes in preparation for 1.6.0
1. Bug fix in NumericDiffCostFunction (Thanks to Nicolas Brodu).
2. Minor documentation update in solver.h
3. Version history update.
4. Bump the version and ABI version.

Change-Id: I951574ddd0b2c4c03b9c79ff33eb9bea549071e7
2013-04-29 15:58:54 -07:00
Sameer Agarwal cbdeb79e91 Lint cleanup from William Rucklidge
Change-Id: Id8b99a2f557efe3744e95a3947f26cdc0c9c269e
2013-04-22 10:18:18 -07:00
Sameer Agarwal 9189f4ea4b Enable pre-ordering for SPARSE_NORMAL_CHOLESKY.
Sparse Cholesky factorization algorithms use a fill-reducing
ordering to permute the columns of the Jacobian matrix. There
are two ways of doing this.

1. Compute the Jacobian matrix in some order and then have the
   factorization algorithm permute the columns of the Jacobian.

2. Compute the Jacobian with its columns already permuted.

The first option incurs a significant memory penalty. The
factorization algorithm has to make a copy of the permuted
Jacobian matrix.

Starting with this change Ceres pre-permutes the columns of the
Jacobian matrix and generally speaking, there is no performance
penalty for doing so.

In some rare cases, it is worth using a more complicated
reordering algorithm which has slightly better runtime
performance at the expense of an extra copy of the Jacobian
matrix. Setting Solver::Options::use_postordering to true
enables this tradeoff.

This change also removes Solver::Options::use_block_amd
as an option. All matrices are ordered using their block
structure. The ability to order them by their scalar
sparsity structure has been removed.

Here is what performance on looks like on some BAL problems.

Memory
======
                                     HEAD         pre-ordering
16-22106                      137957376.0          113516544.0
49-7776                        56688640.0           46628864.0
245-198739                   1718005760.0         1383550976.0
257-65132                     387715072.0          319512576.0
356-226730                   2014826496.0         1626087424.0
744-543562                   4903358464.0         3957878784.0
1024-110968                   968626176.0          822071296.0

Time
====
                                     HEAD         pre-ordering
16-22106                              3.8                  3.7
49-7776                               1.9                  1.8
245-198739                           82.6                 81.9
257-65132                            14.0                 13.4
356-226730                           98.8                 95.8
744-543562                          325.2                301.6
1024-110968                          42.1                 37.1

Change-Id: I6b2e25f3fed7310f88905386a7898ac94d37467e
2013-04-19 19:27:23 -07:00
Sameer Agarwal 7823cf23c7 Fix a typo in problem.h
Thanks as usual to William Rucklidge.

Change-Id: If6e8628841ee7fa8978ec56918a80d60b4ff660e
2013-04-18 16:13:56 -07:00
Sameer Agarwal 3d9546963d Add the ability to query the Problem about parameter blocks.
Change-Id: Ieda1aefa28e7a1d18fe6c8d1665882e4d9c274f2
2013-04-18 22:43:56 +00:00
Sameer Agarwal e6707b2411 Lint fixes from William Rucklidge.
Change-Id: I57a6383bb875b24083cd9b7049333292d26f718c
2013-04-16 15:44:23 -07:00
Joydeep Biswas faa72ace9a Update to compile with stricter gcc checks.
Change-Id: Iecb37cbe7201a4d4f42b21b427fa1d35d0183b1b
2013-04-16 10:49:10 -04:00
Sameer Agarwal 487250eb27 Minor cleanups.
1. Further BLAS and heap allocation cleanups in  schur_eliminator_impl.h
2. Modularize blas.h using macros.
3. Lint cleanups from William Rucklidge.
4. Small changes to jet.h
5. ResidualBlock now uses blas.h

Performance improvements:

For static and dynamic sized blocks, the peformance is not changed much.

-use_quaternions -ordering user -linear_solver sparse_schur

                                        master         change
problem: 16-22106
gcc                                        3.4            3.3
clang                                      2.8            2.7

problem: 49-7776
gcc                                        1.7            1.7
clang                                      1.4            1.4

problem: 245-198739
gcc                                       80.1           79.6
clang                                     80.6           76.2

problem: 257-65132
gcc                                       12.2           12.0
clang                                     10.4           10.2

problem: 356-226730
gcc                                       99.0           96.8
clang                                     88.9           88.3

problem: 744-543562
gcc                                      361.5          356.2
clang                                    352.7          343.5

problem: 1024-110968
gcc                                       45.9           45.6
clang                                     42.6           42.1

However, performance when using local parameterizations is
significantly improved due to residual_block.cc using blas.h

-use_quaternions -use_local_parameterization -ordering user -linear_solver sparse_schur

                                        master         change
problem: 16-22106
gcc                                        3.6            3.3
clang                                      3.5            2.8

problem: 49-7776
gcc                                        1.8            1.6
clang                                      1.7            1.4

problem: 245-198739
gcc                                       79.7           76.1
clang                                     79.7           73.0

problem: 257-65132
gcc                                       12.8           11.9
clang                                     12.3            9.8

problem: 356-226730
gcc                                      101.9           93.5
clang                                    105.0           86.8

problem: 744-543562
gcc                                      367.9          350.5
clang                                    355.3          323.1

problem: 1024-110968
gcc                                       43.0           40.3
clang                                     41.0           37.5

Change-Id: I6dcf7476ddaa77cb116558d112a9cf1e832f5fc9
2013-04-14 09:33:11 -07:00
Sergey Sharybin eeedd3a592 Autodiff local parameterization class
This class is used to create local parameterization
with Jacobians computed via automatic differentiation.

To get an auto differentiated local parameterization,
class with a templated operator() (a functor) that
computes

 plus_delta = Plus(x, delta);

shall be defined.

Then given such functor, the auto differentiated local
parameterization can be constructed as

 LocalParameterization* local_parameterization =
   new AutoDiffLocalParameterization<PlusFunctor, 4, 3>;
                                                  |  |
                       Global Size ---------------+  |
                       Local Size -------------------+

See autodiff_local_parameterization.h for more information
and usage example.

Initial implementation by Keir Mierle, finished by self
and integrated into Ceres and covered with unit tests
by Sameer Agarwal.

Change-Id: I1b3e48ae89f81e0cf1f51416c5696e18223f4b21
2013-04-11 03:07:09 +06:00
Sameer Agarwal 25ac54807e Speed up Jets.
Change-Id: I101bac1b1a1cf72ca49ffcf843b73c0ef5a6dfcb
2013-04-03 18:51:27 -07:00
Sameer Agarwal 58b8c68f29 Clean up rotation.h
Change-Id: I3370c9883728cda068c9650a2c2a50641fd8299c
2013-03-09 17:17:43 -08:00
Sameer Agarwal 5e7ce8a950 Fix Problem::Evaluate documentation
Change-Id: I8c70a24743cff2d9cface99ef0f5d34c78f769c6
2013-03-06 11:38:41 -08:00
Taylor Braun-Jones 0a4f5f8f74 Fix operator() signature in several sections of the documentation
Change-Id: I73f9d150a738f7b136fbc1f98fc60b0f306bd7f9
2013-03-06 05:10:57 +00:00
Sameer Agarwal 31730ef55d DenseSparseMatrix is now column-major.
1. Introduce new typdefs in eigen.h to allow for column
   major matrices.

2. Clean up old unused typedefs, and the aligned typedefs
   since they do not actually add any real performance.

3. Made eigen.h conform to the google style guide by removing
   the using directives. They were polluting the ceres namespace.

4. Made the template specialization generator work again.

Change-Id: Ic2268c784534b737ebd6e1a043e2a327adaeca37
2013-03-03 17:08:32 -08:00
Sameer Agarwal 039ff07dd1 Evaluate ResidualBlocks without LossFunction if needed.
1. Add the ability to evaluate the problem without loss function.
2. Remove static Evaluator::Evaluate
3. Refactor the common code from problem_test.cc and
   evaluator_test.cc into evaluator_test_utils.cc

Change-Id: I1aa841580afe91d288fbb65288b0ffdd1e43e827
2013-02-27 05:38:28 +00:00
Keir Mierle ba9442160d Add the number of effective parameters to the final report.
Here is an example report, obtained by running:

  bin/Debug/bundle_adjuster \
  --input=../ceres-solver/data/problem-16-22106-pre.txt \
  --linear_solver=iterative_schur \
  --num_iterations=1 \
  --alsologtostderr \
  --use_local_parameterization \
  --use_quaternions

Note that effective parameters is less than parameters by 16, which is the
number of cameras. In this case the local parameterization has a 3 dimensional
tangent space for the 4-dimensional quaternions.

Ceres Solver Report
-------------------
                                     Original                  Reduced
Parameter blocks                        22138                    22138
Parameters                              66478                    66478
Effective parameters                    66462                    66462
Residual blocks                         83718                    83718
Residual                               167436                   167436

Minimizer                        TRUST_REGION
Trust Region Strategy     LEVENBERG_MARQUARDT

                                        Given                     Used
Linear solver                 ITERATIVE_SCHUR          ITERATIVE_SCHUR
Preconditioner                         JACOBI                   JACOBI
Threads:                                    1                        1
Linear solver threads                       1                        1
Linear solver ordering              AUTOMATIC                22106, 32

Cost:
Initial                          4.185660e+06
Final                            7.221647e+04
Change                           4.113443e+06

Number of iterations:
Successful                                  1
Unsuccessful                                0
Total                                       1

Time (in seconds):
Preprocessor                            0.697

  Residual Evaluations                  0.063
  Jacobian Evaluations                 27.608
  Linear Solver                        13.360
Minimizer                              43.973

Postprocessor                           0.004
Total                                  44.756

Termination:                   NO_CONVERGENCE

Change-Id: I6b6b8ac24f71bd187e67d95651290917642be74f
2013-02-25 12:49:13 -08:00
Sameer Agarwal 931c309b27 Cleanup based on comments by William Rucklidge
Change-Id: If269ba8e388965a8ea32260fd6f17a133a19ab9b
2013-02-25 10:13:29 -08:00
Sameer Agarwal 509f68cfe3 Problem::Evaluate implementation.
1. Add Problem::Evaluate and tests.
2. Remove Solver::Summary::initial/final_*
3. Remove Solver::Options::return_* members.
4. Various cpplint cleanups.

Change-Id: I4266de53489896f72d9c6798c5efde6748d68a47
2013-02-24 19:04:21 +00:00
Sameer Agarwal beb4505311 Minor fixes
Based on William Rucklidge's review, including
a nasty bug in parameter block removal.

Change-Id: I3a692e589f600ff560ecae9fa85bb0b76063d403
2013-02-22 13:37:05 -08:00
Keir Mierle 3e2c4ef9ad Add adapters for column/row-major matrices to rotation.h
This patch introduces a matrix wrapper (MatrixAdapter) that allows to
transparently pass pointers to row-major or column-major matrices
to the conversion functions.

Change-Id: I7f1683a8722088cffcc542f593ce7eb46fca109b
2013-02-19 08:40:09 +00:00
Keir Mierle 04938efe4b Add support for removing parameter and residual blocks.
This adds support for removing parameter and residual blocks.
There are two modes of operation: in the first, removals of
paremeter blocks are expensive, since each remove requires
scanning all residual blocks to find ones that depend on the
removed parameter. In the other, extra memory is sacrificed to
maintain a list of the residuals a parameter block depends on,
removing the need to scan. In both cases, removing residual blocks
is fast.

As a caveat, any removals destroys the ordering of the parameters,
so the residuals or jacobian returned from Solver::Solve() is
meaningless. There is some debate on the best way to handle this;
the details remain for a future change.

This also adds some overhead, even in the case that fast removals
are not requested:

- 1 int32 to each residual, to track its position in the program.
- 1 pointer to each parameter, to store the dependent residuals.

Change-Id: I71dcac8656679329a15ee7fc12c0df07030c12af
2013-02-18 15:00:30 -08:00
Sameer Agarwal 290b975d1d Preconditioner refactoring.
1. Added a Preconditioner interface.
2. SCHUR_JACOBI is now its own class and is independent of
SuiteSparse.

Change-Id: Id912ab19cf3736e61d1b90ddaf5bfba33e877ec4
2013-02-17 23:20:41 -08:00
Sameer Agarwal d010de5435 Solver::Summary::FullReport() supports line search now.
Change-Id: Ib08d300198b85d9732cfb5785af4235ca4bd5226
2013-02-16 01:32:44 +00:00
Sameer Agarwal 8e1f83c4c4 Speed up Problem construction and destruction.
Change-Id: I3147b0b60eedf40f8453d5a39ff04a572c445a2f
2013-02-15 09:13:14 -08:00
Sameer Agarwal efb47f39c3 Documentation update
Change-Id: I0fec43bff4fe0ea6cd2d2a8b34dac2330a517da0
2013-02-15 17:10:50 +00:00
Sameer Agarwal 974513a41f Bug fix in DynamicAutoDiffCostFunction
Add handling of constant parameter blocks.

Change-Id: I8b2ea79f47e190604fc4bed27705798240689f71
2013-02-12 14:59:04 -08:00
Keir Mierle 3130b3cea4 Add support for dynamic autodiff
Change-Id: I17d573696172ab691a9653db99a620e4bc1bd0d0
2013-02-11 22:47:10 -08:00
Sameer Agarwal 42a84b87fa Expand reporting of timing information.
1. Add an ExecutionSummary object to record execution
   information about Ceres objects.
2. Add an EventLogger object to log events in a function call.
3. Add a ScopedExecutionTimer object to log times in ExecutionSummary.
4. Instrument ProgramEvaluator and all the linear solvers
   to report their timing statistics.
5. Connect the timing statistics to Summary::FullReport.
6. Add high precision timer on unix systems using
   gettimeofday() call.
7. Various minor clean ups all around.

Change-Id: I5e09804b730b09535484124be7dbc1c58eccd1d4
2013-02-06 01:00:38 -08:00
Sameer Agarwal fa1c31eee3 Correct the documentation for crs_matrix.h
Thanks to Joydeep Biswas for reporting this.

Change-Id: Iae5fc2274644aab40f2f922a671f65da15ae71fc
2013-01-30 08:50:41 -08:00
Sameer Agarwal 977be7cac3 Add support for reporting linear solver and inner iteration
orderings.

Change-Id: I0588a4285e0925ce689e47bd48ddcc61ce596a1f
2013-01-26 16:02:33 -08:00
Sameer Agarwal 146b9acb4d Update include/ceres.h to export headers.
Update the ABI version.

Change-Id: I5c1c4f110cddc816bbb5a737634f55b4cbea98e1
2013-01-22 10:40:56 -08:00
Sameer Agarwal 2f0d7249cc NumericDiffFunctor.
A wrapper class that takes a variadic functor evaluating a
function, numerically differentiates it and makes it available as a
templated functor so that it can be easily used as part of Ceres'
automatic differentiation framework.

The tests for NumericDiffCostFunction and NumericDiffFunctor have
a lot of stuff that is common, so refactor them to reduce code.

Change-Id: I83b01e58b05e575fb2530d15cbd611928298646a
2013-01-18 14:01:47 -08:00