Commit Graph

203 Commits

Author SHA1 Message Date
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 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
Petter Strandmark 585607171f <iterator> needed for back_insert_iterator
Adding this header was required to make Ceres compile with VS2010.

Change-Id: I000c860da4fd385d625e70695564225bdfd433c7
2013-04-07 01:35:00 +00:00
Sameer Agarwal 2c648dbc43 Make examples independent of ceres internals.
Change-Id: I6b6913e067a86fea713646218c8da1439d349d74
2013-03-05 15:37:15 -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 085cd4a664 Rewrite of the tutorial.
1. Quicker starting point.
2. Better discussion of derivatives.
3. Better hyperlinking to code and class documentation.
4. New robust estimation example.
5. Better naming of example code.
6. Removed dependency on gflags in all the core examples covered
   in the tutorial.

Change-Id: Ibf3c7fe946fa2b4d22f8916a9366df267d34ca26
2013-02-11 13:37:43 -08:00
Sameer Agarwal c0fdc97539 Update nist.cc to better evaluate results.
Ceres beats Minpack and HBN handily.

Change-Id: I7df8a47b753202ed0b53ab128ce48466bf9f8083
2013-02-07 00:44:53 -08:00
Sameer Agarwal e837aeaf9e Documentation update.
Change-Id: Ica8681f4bb58c60349d0dae453c652f2522eebf6
2013-01-21 22:47:46 +00:00
Sameer Agarwal 68b32a941c ordering -> linear_solver_ordering.
Change-Id: If4af72da90725db2a2d4f397f4cb671c2e863a98
2012-10-06 23:16:04 -07:00
Sameer Agarwal ba8d967f8c Generalization of the inner iterations algorithm.
Add automatic recursive independent set decomposition.
Clean up the naming and the API for inner iterations.

Change-Id: I3d7d6babb9756842d7367e14b7279d2df98fb724
2012-10-05 08:35:53 -07:00
Sameer Agarwal 2c94eed50f Move from Ordering to ParameterBlockOrdering.
Change-Id: I9320afff13ee62be407c725f42f41a18f537bcc1
2012-10-01 16:47:26 -07:00
Sameer Agarwal 9123e2f624 An implementation of Ruhe & Wedin's Algorithm II.
A non-linear generalization of Ruhe & Wedin's algorithm
for separable non-linear least squares problem. It is implemented
as coordinate descent on an independent subset of the parameter
blocks at the end of every successful Newton step. The resulting
algorithm has much improved convergence at the cost of some
execution time.

Change-Id: I8fdc5edbd0ba1e702c9658b98041b2c2ae705402
2012-09-25 11:13:39 -07:00
Ricardo Martin f9a7ce831e Correct snavely reprojection error in code and doc.
The snavely reprojection error is wrong both in the sample code and
in the documentation. It should not multiply by the focal length
before calculating the distortion.

Change-Id: I292af962e634506a7cc57af9ce72b08f81ce3425
2012-09-21 12:14:44 -07:00
Keir Mierle 44714e3c31 Add an example Makefile for using Ceres.
Using Ceres in your application involves linking several dependent
libraries, depending on how you compiled Ceres. The example makes
it easier for users to leverage Ceres in their applications.

Change-Id: I6331fd9c6e36c3eac464be2a7a6b905cc76ed843
2012-09-18 12:15:22 -07:00
Sameer Agarwal 65625f7782 Solver::Options::ordering* are dead.
Remove the old ordering API, and modify solver_impl.cc
to use the new API everywhere.

In the process also clean up the linear solver instantion
logic in solver_impl.cc a bit too.

Change-Id: Ia66898abc7f622070b184b21fce8cc6140c4cebf
2012-09-17 15:41:10 -07:00
Sameer Agarwal 91c9bfee33 Start of the new ordering API.
Change-Id: I37b0f39011f590d54962ad3e1da1f42712008f82
2012-09-17 11:21:22 -07:00
Petter Strandmark fce6aebd91 Adding a denoising example using Fields of Experts.
We have permission from Stefan Roth to use the coefficients from his
Matlab toolbox. They have been added as *.foe files.

Change-Id: Ice529e5cab0302b9f27648dd3c8e5ed7b9662aba
2012-09-07 11:54:32 -07:00
Markus Moll 059ad6e1ff Check return status in nist evaluation.
Previously, the return status was ignored, which meant that e.g. a
numerical failure (which returns 0 final error) would be counted as
correct answer (as the final error is at least as good as the certified
error).

Change-Id: Ia627d5fadf9b20100e628519af794ce0c0b195f4
2012-09-07 19:23:09 +02:00
Markus Moll 58b07a61e8 Allow choice of trust region radius in nist.cc
Change-Id: I0a03b7b6da14af22117685d5f31b06ef384a7ced
2012-09-07 10:22:20 +02:00
Sameer Agarwal b329e58537 Numerically robust computation of model_cost_change.
Change-Id: I421df17bab3bfdf782d95285cf352ed37675d835
2012-09-05 11:14:09 -07:00
Sameer Agarwal cbae856193 Various cleanups to nist.cc.
More flexible testing.
Read and parse the certified cost value from the data file.
Remove the ugly hack for computing the certified cost.
Refactored the flags parsing logic

Change-Id: I8f2e6be183b758b2453302fcdc6696bfa0db5eb8
2012-09-04 15:39:18 -07:00
Sameer Agarwal ca0ff62ddb Fix to Roszman1's certified solution.
Extend nist.cc to test more nonlinear and linear solvers.

(Thanks to Markus Moll for finding the Roszman1 bug)

Change-Id: I92b4bab0771de85f7fe711fb0853f155991f4aaf
2012-09-01 14:41:44 -07:00
Markus Moll 43904888cd Fix typo in Misra1c NIST problem.
The exponent is -0.5, not 0.5.

Change-Id: I77c7bd2ed2b9b20e83d830f74c73088c1b3b3435
2012-08-31 22:54:29 +02:00
Sameer Agarwal 552f9f85bb Various minor bug fixes to the solver logic.
1. CostFunction returning false is handled better.
If only the cost is being evaluated, it is possible to
use the false value as an infinite value signal/outside
a region of validity. This allows a weak form of constraint
handling. Useful for example in handling infinities.

2. Changed the way how the slop around zero when model_cost
is larger than the current cost. Relative instead of absolute
tolerances are used. The same logic is propagated how the
corresponding clamping of the model_cost is done.

3. Fixed a minor indexing bug in nist.cc.

4. Some minor logging fixes to nist.cc to make it more
compatible with the rest of ceres.

Together these changes, take the successful solve count from
41/54 to 46/54 and eliminate all NUMERICAL_FAILURE problems.

Change-Id: If94170ea4731af5b243805c0200963dd31aa94a7
2012-08-31 12:24:28 -07:00
Sameer Agarwal 1a89bcc94e Better reporting on the NIST problems.
Change-Id: I7cf774ec3242c0612dbe52fc233c3fc6cff3f031
2012-08-30 15:32:13 -07:00
Sameer Agarwal ea11704857 Basic harness for testing NIST problems.
Change-Id: I5baaa24dbf0506ceedf4a9be4ed17c84974d71a1
2012-08-30 13:48:40 -07:00
Petter Strandmark 87ca1b2ba2 Changing random.h to use cstdlib for Windows compability.
As discussed with Sameer today.

Change-Id: If3d0284830c6591c71cc77b8400cafb45c0da61f
2012-08-28 18:05:20 -07:00
Markus Moll 51cf7cbe3b Add the two-dimensional subspace search to DoglegStrategy
Change-Id: I5163744c100cdf07dd93343d0734ffe0e80364f3
2012-08-20 11:16:41 -07:00
Sameer Agarwal b9f15a5936 Add a dense Cholesky factorization based linear solver.
For problems with a small number of variables, but a large
number of residuals, it is sometimes beneficial to use the
Cholesky factorization on the normal equations, instead of
the dense QR factorization of the Jacobian, even though it
is numerically the better thing to do.

Change-Id: I3506b006195754018deec964e6e190b7e8c9ac8f
2012-08-19 14:47:38 -07:00
Sameer Agarwal 4b0404352d data_fitting.cc should include gflags.
Also fix glog/gflag includes and sorting in examples.

Change-Id: Ie07563b99cbb9172c941bb8f5fb7decb95fbb5d1
2012-08-13 15:09:34 -07:00
Sameer Agarwal 36a3309c84 Add the ability to normalize BALProblem.
Refactor some of the perturbation code so that the
normalization and perturbation code can share the
camera decomposition code.

Change-Id: I084064976804a92f9240d8f5e10d1bb23dcb5ff2
2012-08-13 07:17:14 -07:00
Markus Moll 214561083b Add WriteToFile function to BALProblem.
Change-Id: I1a4f14dad650fbb2103ee8b897889ac6194a084c
2012-08-11 07:01:34 -07:00
Sameer Agarwal a477273604 Make the camera center perturbation consistent.
The camera perturbation is now done so that after
the perturbation, the translation vector can still
be transformed back into the perturbed camera center.

Change-Id: Ib9e854e2456b2b33669724f348bb37c2d3b40dcd
2012-08-10 18:02:15 -07:00
Sameer Agarwal 8d2e922a28 Perturb camera center instead of translation vector.
Change-Id: I636c84566be2596dd7b4eeab0bb511de597be111
2012-08-10 17:04:48 -07:00
Sameer Agarwal 1b7f3b52fb Add ability to log solver execution to file.
Change-Id: I9996ba2fed5229fe5d621fbb1a027d4c360cd59d
2012-08-10 15:55:31 -07:00
Sameer Agarwal faa117a7e9 Fix off by one errors in perturbation code.
Change-Id: I42cfc59b71e13e3163779ed6703073320298f948
2012-08-10 14:30:44 -07:00
Sameer Agarwal 5476df506e Randomly perturb the bundle adjustment problem.
1. Add the ability to perturb the camera pose and the
point positions using user specified parameters.
2. Re-order the flags.
3. Minor name correction.
4. Added Box-Mueller generator to random.h

Change-Id: I2c9ce74c237f5bde9a7299cc71b205d1ca9bc742
2012-08-10 11:33:59 -07:00
Sameer Agarwal a8f87d7943 Non-monotonic trust region algorithm.
Non-monotonic trust region algorithm based on the work of Phil Toint, as
described in

Non-monotone trust region algorithms for nonlinear
optimization subject to convex constraints.
Philippe L. Toint
Mathematical Programming 77 (1997), 69-94.

Change-Id: I199ecc644e8d1a8cb43666052aef66fb93e15569
2012-08-10 11:09:12 -07:00
Markus Moll 82b689a5fd Close the bal_problem file when done reading it.
Change-Id: I2755822cd2caf4019059e5b4a50f30077142e37f
2012-08-10 14:21:43 +02:00
Sameer Agarwal faf33e66ec Conditionally compile gflag dependencies.
Add data_fitting.cc to the cmake file.

Based on a patch by Casey Goodlett.

Change-Id: Iab17ae91e6fe26b3e01d430154e2f5cdbc1abca5
2012-07-16 10:55:40 -07:00
Keir Mierle efe7ac60a0 Port Ceres to Windows
This is a preliminary, but full, port of Ceres to Windows.
Currently all tests compile and run, with only system_test
failing to work correctly due to a path issue.

Change-Id: I4152c1588bf51ffd7f4d9401ef9759f5d28c299c
2012-06-24 23:22:04 -07:00
Sameer Agarwal fa01519c47 Dogleg strategy and timing cleanups.
1. A new dogleg trust region strategy.
2. Consistent naming of all variables taking and reporting
   time. Also all are doubles now.
3. Enum to stringification routines.
4. bundle_adjuster.cc accepts max solver time and trust_region_strategy.
5. Time accounting is pushed into solver_impl.cc and there is now
   postprocessing time accounted for explicitly.
6. IterationCallback now has cumulative time.
7. LoggingCallback logs per iteration and cumulative time.
8. TrustRegionStrategy now allows for Invalid steps to be indicated
   explicitly.
9. Trust region minimizer actually terminates on max_solver_time.

Change-Id: I7e3b82c8beebc17b6b355ea46ddd280754a2d8b2
2012-06-11 22:16:02 -07:00
Sameer Agarwal 7a3c43b847 Block oriented fill reducing orderings.
By virtue of the modeling layer in Ceres being block oriented,
all the matrices used by Ceres are also block oriented.
When doing sparse direct factorization of these matrices, the
fill-reducing ordering algorithms can either be run on the
block or the scalar form of these matrices. Running it on the
block form exposes more of the super-nodal structure of the
matrix to the Cholesky factorization routines. This leads to
substantial gains in factorization performance.

This changelist adds support for approximate minimium degree
orderings to be computed on the block structure of the
Schur complement matrix. This affects, SchurComplementSolver
and VisibilityBasedPreconditioner and SparseNormalCholesky
 when using SuiteSparse.

A bool, use_block_amd has been added to Solver::Options and
bundle_adjuster.cc has been updated to allow testing with it.

When combined with a multithreaded Schur elimination, speed ups
can be seen quite uniformly across the board. For some problems
this can be dramatic, reducing the factorization time from 70
seconds down to 17 seconds.

Change-Id: I15ebb0afcbc85ada032ec8d179ee3a2f7c8d3e46
2012-06-06 22:02:17 -07:00
Sameer Agarwal aa9a83c657 New Trust region loop.
1. New TrustRegionMinimizer and basic tests for it.
2. New TrustRegionStrategy interface.
3. New LevenbergMarquardtStrategy and tests for it.
4. Updates to SolverImpl to reflect this.
5. Changes to Solver::Options and IterationSummary related to this.
6. Deleted levenberg_marquardt.cc/h/_test.cc

Change-Id: I6c1d1a7c774f014856f9f26263a830aa886e1400
2012-05-30 21:44:46 -07:00
Sameer Agarwal d11469093c Better handling of booleans in CMakeLists.txt
Updated the value of the version of cmake needed to build
ceres. Since the way booleans and literals are handled has changed
recently.

Change-Id: If13877f4403705cc29c3cf66c4e66dec26bbb3e9
2012-05-30 09:41:45 -07:00
Sameer Agarwal daa9824e56 1. Changed the semantics of how SuiteSparse dependencies are checked and used. Now SuiteSparse is built by default, only if all of its
2. Corrected a number of typos and reorganized the CMakefile to handle the corner cases better.

3. Moved the various search paths to the top of the CMakefile so that they are more easily accessible.

4. Tests that depend on gflags are only built if gflags support is compiled in.
2012-05-11 11:26:38 -07:00
Sameer Agarwal 82f4b88c34 Extend support writing linear least squares problems to disk.
1. Make the mechanism for writing problems to disk, generic and
controllable using an enum DumpType visible in the API.

2. Instead of single file containing protocol buffers, now matrices can
be written in a matlab/octave friendly format. This is now the default.

3. The support for writing problems to disk is moved into
linear_least_squares_problem.cc/h

4. SparseMatrix now has a ToTextFile virtual method which is
implemented by each of its subclasses to write a (i,j,s) triplets.

5. Minor changes to simple_bundle_adjuster to enable logging at startup.
2012-05-08 17:40:16 -07:00
Keir Mierle e2a6cdc081 Address some of the comments on CGNR patch
- Rename BlockDiagonalPreconditioner to BlockJacobiPreconditioner
- Include the diagonal in the block jacobi preconditioner.
- Better flag help for eta.
- Enable test for CGNR
- Rename CONJUGATE_GRADIENTS to CGNR.
- etc.
2012-05-07 06:39:56 -07:00
Keir Mierle 211812a573 Better error handling in bundle_adjuster.cc 2012-05-07 04:33:50 -07:00