Commit Graph

196 Commits

Author SHA1 Message Date
Keir Mierle d4a0bf86d6 Fix threading build on Windows.
On Windows, including the "windows.h" header defines an enormous number of
symbols; some of which are macros with common names. In particular, "ERROR" and
"min" and "max" get defined. This causes clashes when user code references
these names in a context other than the intended use in windows.h.

To deal with this, the Microsoft engineers added the ability to control the
definition of these symbols by adding extra defines. In particular, including
windows.h in the following way

  #define NOGDI
  #define NOMINMAX

will reduce the number of macros defined. This way they will not conflict with
other uses in Ceres. For example, numeric_limits<double>::max() is impossible
to call without defining NOMINMAX.

Change-Id: I166f5d3bb6dc0e2e4b2ebf800fb19e49206f7874
2013-02-24 10:40:03 -08: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
Sameer Agarwal 9a88bd7c4b Minor bug fixes
Change-Id: I94e4521adf76a6c77db954c4a8955168e9d37b55
2013-02-19 13:09:12 -08:00
Sameer Agarwal 956ed7e8f2 Various minor fixes.
1. Unused variable warnings and fixes.
2. Minor documentation update.

Change-Id: I815588a5806df1030a7c8750f4fb594c503f8998
2013-02-19 09:13:50 -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
Markus Moll be418a336c Fix evaluation of initial cost and corresponding test
Commit f102a68e41 seems to have introduced
a bug in both solver_impl.cc and solver_impl_test.cc
solver_impl_test showed 3 errors, where two were due to ceres NOT
failing when the test expected that, and one was due to the initial cost
being wrong (-1 instead of 0.5)
Ceres now does not attempt to evaluate the initial cost if
options.return_initial_xxx is not set. It therefore did not fail in
the tests.
It also seems that the CERES_EVALUATE macro erroneously always sets
final_cost, even when called with 'initial' as argument.

Change-Id: Ia3c3eeb476e7023a3f80b201124010d6c67e9824
2013-02-15 17:19:28 +01: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 c58e6dc3ea More refined event logging in solver_impl.cc
Change-Id: Ie3061c921c006d2600d16185c690f52ccf816f68
2013-02-11 18:23:27 -08:00
Sameer Agarwal f102a68e41 Remove extraneous initial and final evals.
Change-Id: I80ed87435f399cbf452c68be7ea1e7139696aa4a
2013-02-11 15:19:21 -08:00
Sameer Agarwal 0593747ee0 Fix a memory leak in cxsparse.cc
Thanks to Alexander Mordvintsev for reporting it.

Change-Id: Ia872be42ce80209e46722fc16a928496cf97e256
2013-02-11 14:03:26 -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 71c8058478 Remove ExecutionSummary from Evaluator and LinearSolver
Change-Id: If4dbaf516a8b14e0a79e1a2116ce66a99ed4a592
2013-01-31 17:33:01 -08:00
Sameer Agarwal bdd87c03ed Add an ExecutionSummary object that the Evaluator and LinearSolver can use to
report execution statistics of all kinds.

Currently a single map which maps arbitrary strings to doubles is supported,
which allows for precise timing information to be communicated.

Change-Id: Ibd930aca5c9e6cae89bcfeffe9b13e2887644881
2013-01-29 16:24:31 -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 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
Sameer Agarwal 2fc0ed6143 Change NumericDiffCostFunction to accept variadic functors.
The interface for NumericDiffCostFunction and AutoDiffCostFunction
are not comparable. They both accept variadic functors.

The change is backward compatible, as it still supports numeric
differentiation of CostFunction objects.

Some refactoring of documentation and code in auto_diff_cost_function
and its relatives was also done to make things consistent.

Change-Id: Ib5f230a1d4a85738eb187803b9c1cd7166bb3b92
2013-01-18 13:06:31 -08:00
Sameer Agarwal 9c5acce674 Add CostFunctionToFunctor.
CostFunctionToFunctor wraps a CostFunction, and makes it available
as a templated functor that can be called from other templated
functors. This is useful for when one wants to mix automatic,
numeric and analytic differentiated functions.

Also a bug fix in autodiff.h

Change-Id: If8ba281a89fda976ef2ce10a5844a74c4ac7b84a
2013-01-18 11:43:48 -08:00
Sameer Agarwal c89ea4b9de Minor corrections based on Jim Roseborough's comments
Change-Id: I4a8c7a454ddf038a3ed2567c101f9aee582044bf
2013-01-09 16:15:09 -08:00
Keir Mierle 00c8a06192 Fix bug in DenseSparseMatrix::ToDenseMatrix().
Change-Id: I74a1a03149d74fbc4268ec3ce9d20e09746a7227
2012-12-01 13:28:41 -08:00
Sameer Agarwal bcac4de5b7 Speedup corrector.cc
Add a specialization for the common case where the residual block
outputs exactly one residual.

The matrix routines used by Corrector can be then specialized to
a scalar and be made considerably faster.

For denoising upto 400% speedup is observed.

Change-Id: I8e3f24b8ba41caa8e62ad97c5f5e96ab6ea47150
2012-11-30 23:11:26 -08:00
Sameer Agarwal 9883fc396b Refactoring of the LineSearchMinimizer.
1. New LineSearchDirection interface, factory and instances.
2. Cleanup of LineSearchMinimizer to use the State and Direction objects.
3. LBFGS -> LowRankInverseHessian.
4. Refactoring of the RunCallbacks function and share it across
   LineSearchMinimizer and TrustRegionMinimizer.

Change-Id: I19354afc6f5d6567b28918710c2012dc30ef8f32
2012-11-30 18:37:42 -08:00
Sameer Agarwal aed99615c0 Expose lbfgs rank in solver.h
Change-Id: Ibc184b1a2f94a4057fa6569d539ca3a55d6d6098
2012-11-29 15:54:34 -08:00
Sameer Agarwal 1afd498f50 String to and from enum conversion routines.
Update types.h/cc with stringication and unstringication
routines for the newly introduced enums.

Change-Id: I0fe2842b5b1c75ba351f4ab87ec9fa60af2f9ed2
2012-11-29 10:33:37 -08:00
Sameer Agarwal 3e8d192f28 Add a rough implementation of LBFGS.
Change-Id: I2bc816adfe0c02773a23035ea31de3cddc1322a4
2012-11-28 18:26:41 -08:00
Sameer Agarwal f4d0164607 Add a line search based minimizer.
1. Add a line search based minimization loop.
2. Currently this loop supports steepest descent and three
   kinds of non-linear conjugate gradient algorithms.
3. Update SolverImpl to talk to LineSearchMinimizer.
4. Update IterationCallback to carry information about
   line search.
5. Update LineSearch to take the initial point as input,
   saving on one function evaluation.
6. Updates to the external API.

Change-Id: I901a0e89fc948451ab34c743e70f3dec57c9405e
2012-11-28 16:18:01 -08:00
Sameer Agarwal 0b5df70e33 Bug fix in solver_impl_test.
One of the tests CreateLinearSolverNoSuiteSparse, fails
when no sparse backend is present. This was a failure
in running tests with all possible sparse backend settings.

Thanks to Sebastian Fabbro for reporting this.

Change-Id: I0ab98632ae7dd33f18d67cb9f490e74c034ce03d
2012-11-28 15:53:07 -08:00
Sameer Agarwal 86f6ea68b8 Fix a variadic evaluation bug in AutoDiff.
Thanks to Julien Michot for reporting.

Change-Id: I322cd177e85c18ba3fbee56149696d4140f79c68
2012-11-28 15:13:21 -08:00
Sameer Agarwal 9895a4f50c Update comment in trust_region_minimizer.h.
Update comment to better reflect the Minimizer API.

Change-Id: Icca1d41fdea1f8dacde2e1af3239486820ef2b7f
2012-11-26 16:48:32 -08:00
Sameer Agarwal 1d11be9d38 Armijo line search.
An interface for line search and an initial implementation of
Armijo line search with and without interpolation.

Change-Id: I234da141be36172819a6df87ce5625aa8b58ed47
2012-11-26 12:14:22 -08:00
Sameer Agarwal 31432aeec4 Fix an initialization bug in ProgramEvaluator.
The buffers used to store the per thread value of the gradient
were not set to zero at the beginning of each call to evaluate.

Change-Id: I9c8afea54a4e2e0b805164025da3023166a309af
2012-11-25 18:36:04 -08:00
Sameer Agarwal e7295c246b Add polynomial interpolation and minimization.
1. polynomial_solver* -> polynomial*.
2. Added support for differentiating polynomials.
2. Added support for interpolating polynomials from function
   values and gradients.
3. Added support for minimizing polynomials by solving
   for the roots of their derivatives in an interval.
4. Added support for finding the minimum of a polynomial
   that interpolates function values and gradients in
   an interval.

Change-Id: Id7e6764ad4db09c3edd60f1378c7f50f20dd08dc
2012-11-25 16:53:05 -08:00
Sameer Agarwal 747845fc82 Add the GradientChecker.
The GradientChecker is a utility class written by
William Rucklidge that can be used to check that the
derivatives returned by a cost function match those
returned by numerically differentiating the residuals
returned by the same cost function.

This is useful when developing CostFunction objects
and testing them before plugging them into an optimization
problem.

Change-Id: Ic60f859b48b6246406448555d25556784e097b81
2012-11-08 10:40:18 -08:00
Sameer Agarwal bdabc29d90 Change LOG(ERROR) to LOG(WARNING) in schur_complement_solver.cc
Change-Id: Ie248989b230ec2357a00a15ef35087e85682315c
2012-11-07 11:26:32 -08:00
Sameer Agarwal d779b04eb4 Sort filenames in internal/CMakeList.txt
Change-Id: Id86f998ae0a1261e62d940e8e664102ff7526ec3
2012-11-02 11:05:42 -07:00
Sameer Agarwal 3dadfb78b7 static cast to force Eigen::Index to long conversion.
Change-Id: I11945c455eb3fef9bfb952f5a30d657542fbccae
2012-10-30 17:41:50 -07:00
Fisher 12626e8cba Add support for up to 10 parameters in Problem
Following the last commit, which extends the number of parameters blocks autodiff can accept, the interface of Problem::AddResidualBlock is extended to accept up to 10 parameter blocks.

Change-Id: I162c3d1b1868fdda32c1522d57e9a211a9c02f90
2012-10-21 14:26:30 -04:00
Keir Mierle f1e67cc90b Add support for up to 10 parameters in autodiff.
Supporting only 6 parameters in autodiff was enough for most
cases, but 6 was not always sufficient. This extends the
current implementation to work with up to 10 parameters.
This also increases the number of parameters supported in
SizedCostFunction to 10.

Change-Id: Ic783602f93e6ddf4af24fa34eff37c0a4b775dc1
2012-10-19 11:00:46 -07:00
Sameer Agarwal a45046a4e2 Remove verbose logging from DenseQRSolver
Change-Id: I37999657443697440afc6908ed3c05911419314d
2012-10-15 17:59:23 -07:00
Keir Mierle 27dd0d3307 Fix the Ceres Android NDK build.
The NDK build of Ceres was broken; this fixes it and also
disables a useless warning that shows up in NDK 8b.

Change-Id: I54cfb3de7ccea4a0864385f7ffdb55d8f3431f34
2012-10-15 13:54:10 -07:00
Sameer Agarwal 67a107b2f4 SolverImpl refactoring.
Improve the logic with which various corner cases like
constant program, failures to evaluate initial and final
cost etc are handled.

Change-Id: Id43d45ebe46b65918909d47201d6fb7b89ebbd57
2012-10-11 17:44:23 -07:00
Sameer Agarwal 66fcc7d5da Fix a memory leak in trust_region_minimizer_test.cc
Change-Id: I46dff90485a8106c154cbd72493acda64971e94a
2012-10-08 09:54:16 -07:00
Sameer Agarwal 76e8bb532c Add a missing OpenMP ifdef to coordinate_descent_minimizer.cc
Change-Id: I4eb74ab0cba86eee65a0ccfa2373c8e108f53758
2012-10-08 09:12:52 -07:00
Sameer Agarwal 68b32a941c ordering -> linear_solver_ordering.
Change-Id: If4af72da90725db2a2d4f397f4cb671c2e863a98
2012-10-06 23:16:04 -07:00
Sameer Agarwal c1ffad6009 Schur ordering was operating on the original program.
Thanks to Ricardo Martin for reporting this.

Change-Id: Iacf44f672287e4d76633878c7051694a39b3056f
2012-10-05 16:58:32 -07:00
Sameer Agarwal e3c5570b05 Petter's MSVC fixes
Change-Id: I13a2f6e1046136ce240c22dadd1b7547f56d4493
2012-10-05 14:08:42 -07:00