Commit Graph

90 Commits

Author SHA1 Message Date
Sameer Agarwal b766177bab Remove support for Solver::Options::solver_log.
This is not really used and if needed can be implemented
in user code.

Change-Id: I56328d51c9d3788f90c751ff9c3a5937989f6ee0
2014-05-29 21:59:37 +00:00
Sergey Sharybin 36c2ce87d1 Libmv 2D homography estimation example application
Add an example application of homography matrix estimation
from a 2D euclidean correspondences which is done in two
steps:

- Coarse algebraic estimation
- Fine refinement using Ceres minimizer

Nothing terribly exciting apart from an example of how to
use user callbacks.

User callback is used here to stop minimizer when average
of symmetric geometric distance becomes good enough.
This might be arguable whether it's the best way to go
(in some cases you would want to stop minimizer when
maximal symmetric distance is lower than a threshold) but
for a callback usage example it's good enough to stick
to current logic.

Change-Id: I60c8559cb10b001a0eb64ab71920c08bd68455b8
2014-05-15 15:17:14 +02:00
Alex Stewart ea76585068 Adding autogenerated Ceres config.h to #define Ceres compile options.
- Previously we passed all compile options to Ceres via add_definitions
  in CMake.  This was fine for private definitions (used only by Ceres)
  but required additional work for public definitions to ensure they
  were correctly propagated to clients via CMake using
  target_compile_definitions() (>= 2.8.11) or add_definitions().
- A drawback to these approaches is that they did not work for chained
  dependencies on Ceres, as in if in the users project B <- A <- Ceres,
  then although the required Ceres public compile definitions would
  be used when compiling A, they would not be propagated to B.

- This patch replaces the addition of compile definitions via
  add_definitions() with an autogenerated config.h header which
  is installed with Ceres and defines all of the enabled Ceres compile
  options.
- This removes the need for the user to propagate any compile
  definitions in their projects, and additionally allows post-install
  inspect of the options with which Ceres was compiled.

Change-Id: Idbdb6abdad0eb31e7540370e301afe87a07f2260
2014-05-09 10:57:31 +01:00
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
Sameer Agarwal 02db9414fb Fix the documentation for RandNormal.
As pointed out by Jim Roseborough, this is the Marsaglia Polar
method and not the Box-Muller method.

Change-Id: Id5332bcd4b4c23a3885cc296729b44eaa5edd0a8
2014-04-28 08:32:51 -07: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 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
Joydeep Biswas 8e0991381e Added a simplified robotics example for DynamicAutoDiffCostFunction.
Change-Id: I9520e0a9a8d9743285c5114523fbafa6ffa5b0bd
2014-04-25 08:49:27 -04:00
Sameer Agarwal b7373aa07b Add Meyer Function (Problem 10) to more_garbow_hillstrom.cc
Change-Id: Ibec5fb212de55ffe6910a4ca65db75609e7f1545
2014-03-10 08:55:28 -07:00
Sameer Agarwal c926b29640 Fix build breakage.
NOLINT annotations and c++ macros do not mix.

Change-Id: I990bee7190189566eb6e78ebec43ce9f01e305c3
2014-02-24 13:45:24 -08:00
Sameer Agarwal 6e3aad289f Lint cleanup from William Rucklidge.
Change-Id: Ifb36de18f95d521242d8853bb54024b09effb937
2014-02-24 13:35:26 -08:00
Sameer Agarwal 7ad0e54aa8 Add missing gflags and glog logging includes.
Change-Id: I382af4894c5369fe33d78fdf0e8d9cf5435eeda8
2014-02-24 12:06:59 -08:00
Sameer Agarwal 7ea6bb92f4 Fix a type bug in more_garbow_hillstrom.cc.
Change-Id: Ia830db6cdfd15b8e90d7a3655eeab8cf6a463817
2014-02-24 12:02:00 -08:00
Sameer Agarwal 9102bdd831 Add more problems to more_garbow_hillstrom.cc.
Change-Id: Iffef76c22629747909f820be354cf8080da33a69
2014-02-20 21:36:49 -08:00
Sameer Agarwal b14923418e Extend more_garbow_hillstrom to include unconstrained solves.
Change-Id: If855b0fff26898a61b701a1b7fcd02337614d108
2014-02-19 23:33:36 -08:00
Sameer Agarwal 840c89f2d1 Add test problems from More, Garbow and Hillstrom.
Change-Id: I50f1fec377ad020bd1537e65bed5ff08d2d8f4e7
2014-02-19 23:12:17 -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
Petter Strandmark 88a703f44f Fix compilation in Visual C++ 2013.
I had to fix the following things to make Ceres compile in 2013:
 * Not link to 'm' (GNU math library).
 * Excplicitly convert an std::ostream to bool.
 * Include <algorithm> for std::max.

Change-Id: I3ff65413baf8711364360d46dd71fd553fa63e72
2013-10-31 20:59:20 +00: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
Alex Stewart 6a2bcaa1d5 Adding explicit link to libm for pure-C curve fitting example.
- Any pure-C program #including <math.h> will need to link against
  libm, some compilers will let an indirect link slide (via Ceres in
  this case) but some won't.

Change-Id: I6890702fa0d2c3fbb747f0f81fc3fa3631839de4
2013-10-23 20:26:16 +00:00
Alex Stewart 78cc2c4719 Cleaning up exported CeresConfig.cmake.
- Adding FindPackage scripts for all of Ceres dependencies.
- Moving depend.cmake contents to CeresConfig.cmake and cleaning up
  search for Ceres & required dependencies, no longer push Ceres
  options into client.
- Fixing uninstall to remove ceres include root directory.
- Fixing main CMakeLists to install miniglog header if enabled.
- Making miniglog library shared/static with Ceres library.

Change-Id: If926bebd11720230c5136597ccba672394ed9777
2013-10-17 19:13:08 +00: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
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 aee5597acf Minor fix to curve_fitting.c
Change-Id: Ib3669a5c4c73178b088dc1e80141f844f807b179
2013-07-09 23:31:25 -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 1c70ae9aa6 Fix Solver::Summary when line search is used.
Also enable line search in bundle_adjuster.

Change-Id: Ic4343a4334b9f5a6fdeab38d4e3e1f6932bbc601
2013-06-30 12:50:43 -07:00
Arnaud Gelas 044786669d Enforce the read call returns correct value
fix compilation error on Ubuntu 12.0

In file included from /usr/include/fcntl.h:252:0,
                 from /home/ajg23/src/ceres-solver/examples/libmv_bundle_adjuster.cc:91:
/home/ajg23/src/ceres-solver/examples/libmv_bundle_adjuster.cc: In member function ‘T {anonymous}::EndianAwareFileReader::Read() const [with T = unsigned char]’:
/home/ajg23/src/ceres-solver/examples/libmv_bundle_adjuster.cc:300:5: error: ignoring return value of ‘ssize_t read(int, void*, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result]

Change-Id: Ib23ca19778761bbfe0d77bcf32a2181ce6db1a12
2013-06-21 16:05:15 +02:00
Sameer Agarwal 85b7e9d3c1 Fix an uninitialized variable warning when building with GCC.
Change-Id: I6f24553a9c4dfb59e05778f19406aefa058b6342
2013-06-13 23:01:01 -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 0f6161ba60 Add a define for O_BINARY.
Also make libmv_bundle_adjuster more verbose by default.

Change-Id: Ie8c7c4d9eed737681382bcfe61e39174d5e3420d
2013-06-01 16:34:54 -07:00
Sergey Sharybin 9869c3dd44 Libmv bundle adjuster example application
Add example application which is based on bundle
adjustment code from Libmv library, which is heavily
used in Blender.

Apart from bundle adjustment code this commit also
contains real-life optimization problems from VFX
pipeline. This files are created from production
files of Tears of Steel movie.

New code is placed to examples, and could be used
either as an example implementation of BA or for
timing investigation of problems appearing in VFX.
Problems for this application are placed to
data/libmv-ba-problems.

Usage:
  ./libmv_bundle_adjuster --input=/path/to/problem_file.bin

There's also optional flag --refine_intrinsics which
declares explicitly whether intrinscis shall be
refined or not. If this flag is not passed, refinement
will happen for problems stored in image space.

Structure of problem files is described in header
comment of libmv_bundle_adjuster.cc.

Change-Id: I51202848c75dcd7612b707609e5ff3708e01b625
2013-06-01 17:08:31 +00:00
Sergey Sharybin 2a3827e13d Compilation error fixes
- In C you're not allowed to define variables in the middle
  of the block. This was violated in curve_fitting.c by
  calling ceres_init() in the beginning of main() and declaring
  variables later.

- Also ifdef-ed suitesparse stuff in covariance estimation module.
  This solves compilation error when you don't have suitesparse
  compiled/installed.

Change-Id: I22b543c09ea01f55e127079daade99a0b781f789
2013-05-31 20:33:42 +00:00
Sameer Agarwal f9e9d6ef36 Declare the iterator variable outside the loop in curve_fitting.c
Change-Id: I4ce703c8d6a6deb3aebaccd3cd5d916c7aa4f92e
2013-05-24 15:06:53 +00:00
Sameer Agarwal 096d5934a2 Comment cleanup from Jim Roseborough
Change-Id: Id47101fe32e1449e660ec536934ee91fdaf452c7
2013-05-20 08:49:09 -07:00
Joydeep Biswas aa20a6dc1b Updated depend.cmake to follow CMake IF convention.
Change-Id: I1e86cf134d3f40852033ae73f36d9143b389a918
2013-05-19 19:17:50 +00: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 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