Commit Graph

426 Commits

Author SHA1 Message Date
Sameer Agarwal 1693645a67 Add Solver::Options::IsValid.
This provides a user visible way to validate the Solver::Options
before calling Solve.

Change-Id: Ife84fd33532ab2ccb7ac95abe22735843db51fde
2014-05-30 13:00:18 -07:00
Sameer Agarwal 3b73313e2a Use Program::RemoveFixedBlocks.
And get rid of the code and tests related to
SolverImpl::RemovedFixedBlocksFromProgram.

Change-Id: Iccf6501dfe93db737f5a2265bbab0021712be92f
2014-05-30 11:32:08 -07:00
Sameer Agarwal a2df262441 SummarizeOrdering -> OrderingToGroupSizes
Change-Id: I6f852811c6d3812865b1da5cb94272cdf3fa4a38
2014-05-29 22:51:12 -07:00
Sameer Agarwal 3a783ac408 Move Summary related functions into their own file.
Change-Id: Ie063de83e5b5e2b6d93322dd901d23b53e3d4b6a
2014-05-29 22:41:44 -07:00
Keir Mierle 80a85ca53f Replace broken CERES_VERSION macro
This replaces the broken CERES_VERSION and CERES_ABI_VERSION
defines with a different set, including integer versions for
MAJOR/MINOR/etc.

This also adds the Ceres version to Solver::FullReport().

Example report from powell:

Ceres Solver v1.10.0 Solve Report
----------------------------------
                                     Original                  Reduced
Parameter blocks                            4                        4
Parameters                                  4                        4
Residual blocks                             4                        4
Residual                                    4                        4

Minimizer                        TRUST_REGION

Dense linear algebra library            EIGEN
Trust region strategy     LEVENBERG_MARQUARDT

                                        Given                     Used
Linear solver                        DENSE_QR                 DENSE_QR
Threads                                     1                        1
Linear solver threads                       1                        1

Cost:
Initial                          1.075000e+02
Final                            1.791438e-14
Change                           1.075000e+02

Minimizer iterations                       14
Successful steps                           14
Unsuccessful steps                          0

Time (in seconds):
Preprocessor                            0.001

  Residual evaluation                   0.000
  Jacobian evaluation                   0.000
  Linear solver                         0.000
Minimizer                               0.001

Postprocessor                           0.000
Total                                   0.003

Change-Id: I5bf0e8023693e9195276b1f1e881b13121ba1196
Termination:                      CONVERGENCE (Gradient tolerance reached. Gradient max norm: 3.642190e-11 <= 1.000000e-10)
2014-05-30 05:18:36 +00:00
Sameer Agarwal 87a40da145 Refactor Program related functions.
Move

ParameterBlocksAreFinite
IsBoundsConstrained
IsFeasible
RemoveFixedBlocks
IsParameterBlockSetIndependent
CreateJacobianBlockSparsity

from being static methods in SolverImpl to member functions
in the Program class.

Change-Id: I80fa4a429a716ea4371ad6c67864adad438e1553
2014-05-29 21:21:49 -07:00
Sameer Agarwal f5e81b61e7 Move IterationCallbacks into their own file.
1. Merge TrustRegionLoggingCallback and LineSearchLoggingCallback
   into a single callback.
2. Move the callbacks into callback.h
3. Update SolverImpl to use the new callbacks.

Change-Id: I9e82173cf2b828d023d96c57d1cba17f4832aeae
2014-05-29 15:03:10 -07:00
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
Sameer Agarwal 558ee40ee1 Add SuiteSparse::IsConstrainedApproximateMinimumDegreeOrderingAvailable.
This allows checking for the availability of CAMD without depending
on a preprocessor symbol, which can be the source of subtle bugs
if the file defining that symbol was not included.

Change-Id: I6f1ef91a20baeecf68e8dd467ebe707dde8c5f79
2014-05-29 21:58:40 +00:00
Sameer Agarwal ec3a3ceafc Flesh out OrderedGroups.
1. Add the ability to bulk remove elements.
2. Add accessor for elements_to_group.
3. Early exit in Remove if there are no elements.

Change-Id: I3df1f00de05338a42e9907423b674469a022d3bc
2014-05-29 14:55:26 -07:00
Sameer Agarwal 041f27516a Move CompactifyArray to array_utils.
1. Rename it to MapValuesToContiguousRange.
2. Improve implementation to just use a vector.

Change-Id: I2a5e73e3a6fb81694c6f452a00d60df16c0149e6
2014-05-29 14:52:17 -07:00
Björn Piltz d99a3a961e Separate PUBLIC and PRIVATE library dependencies
Do not propagate 3d party libs through
IMPORTED_LINK_INTERFACE_LIBRARIES_[DEBUG/RELEASE] mechanism
when building shared libraries. SuiteSparse, lapack & co
are considered private. Glog still gets propagated since
it is part of the public interface. See documentation of
TARGET_LINK_LIBRARIES().

Change-Id: If0563b0c705b102876f5190e9a86694d10f79283
2014-05-14 12:46:46 +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
Björn Piltz cbf955474a Fixes swapped verboselevel and condition.
Change-Id: I296d86e6bbf415be4bfd19d6a0fe0963e3d36d74
2014-05-07 19:02:41 +00:00
Björn Piltz 3209b04574 Fixed warning : 'va_copy' : macro redefinition
MSVC 2013 has got va_copy
Compare
http://msdn.microsoft.com/en-us/library/kb57fad8(v=vs.110).aspx
and
http://msdn.microsoft.com/en-us/library/kb57fad8.aspx.

Change-Id: If0937c76e8d250cde4b343844f3d35c980bf0921
2014-05-07 19:02:07 +00:00
Sameer Agarwal eca7e1c635 Remove BlockRandomAccessCRSMatrix.
It is not used anywhere.

Change-Id: I2a8ebbdacf788582f21266825ead3f76646da29e
2014-05-06 10:16:19 -07:00
Sameer Agarwal 95cce0834d Remove some errant tabs.
Change-Id: Ie1f7051e99bcb15ad068711b68a9d8f317b12ed7
2014-05-05 08:54:50 -07:00
Sameer Agarwal a536ae76df Lazily initialize the bounds arrays in ParameterBlock.
Problems that do not use bounds do not have to pay the
price of storing bounds constraints.

Also replace the raw pointer access to the upper and
lower bounds arrays with accessors which hides the
lazy initialization from the user.

Change-Id: I0325a35de9c29f853559f891e32e7c777686e537
2014-05-05 07:55:12 -07:00
Sameer Agarwal 633b50b7af Add the (2,4,8) template specialization.
Change-Id: I058bcebdd1725031d573404133b184d6f27dc005
2014-05-02 22:47:52 -07:00
Alex Stewart 5ffe06019a Export Ceres compile definitions to targets compiled against Ceres.
- Previously all Ceres compile definitions were private to Ceres, that
  is they were not exported to users via the CMake export mechanism.
- Now that we use compile definitions in public (installed) Ceres
  headers, we need to export the Ceres compile definitions.
- If we did not do this, then the client's code 'see's' a different
  version of the Ceres headers to those which were in fact compiled,
  or in the case of shared_ptr, may not find the required header.

- This patch makes use of the new, in CMake 2.8.11, function:
  target_compile_definitions() to export all of the Ceres compile
  definitions using CMake's export functionality.
- For CMake versions < 2.8.11, we have to use the blunter instrument of
  calling add_definitions() in CeresConfig.cmake (invoked by a call to
  find_package(Ceres)).  This is messy because it ends up adding the
  Ceres compile definitions to any target declared in the user's code
  after the call to find_package(Ceres).  Although this should do no
  harm as all of our defines are prefaced with CERES_, so any
  unintentional name clashes are unlikely.

Change-Id: I5dea80949190eaf4fb08ea4ac568ce28c32dd4e0
2014-05-02 13:33:24 +00:00
Sameer Agarwal 0e811b0881 Fix a bug in Minimizer::RunCallbacks.
Solver::Summary::message was not being updated when the solver
terminated because of a user's iteration callback indicating
success or failure.

Thanks to Sergey Sharybin for reporting this.

Change-Id: I27e6e5eed086920ddf765461b0159417ac79d7b3
2014-05-01 11:39:37 -07:00
Sameer Agarwal 15c1210a8b Lint cleanup from Jim Roseborough.
Change-Id: I53f4e0d020602443b397387b8c5908f25649403d
2014-04-30 14:32:16 -07:00
Björn Piltz 5d7eed87b4 Suppport for MSVC DLLs.
Change-Id: Ibbcc4ba4e59f5bbf1cb91fe81c7d3b9042d03493
2014-04-28 19:56:24 +00: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
Sameer Agarwal 46ccfb376a Cleanup block_structure.h/cc
1. Remove obsolete Proto conversion functions.
2. Fix a strict weak ordering bug.

Change-Id: I1ce6d4b06e29cf475df1d5bd37c79f66f20f8d93
2014-04-12 21:58:11 -07:00
Richard Bowen 3e60a998ac Added support and tests: row and column blocks for sparse matrix
transpose.

Change-Id: Ife641b08a9e86826478521a405f21ba60667f0e8
2014-04-04 17:56:49 -07:00
Sameer Agarwal 5ecb1c3f1d Add Problem::IsParameterBlockPresent.
This allows the user to query the Problem to see if a
parameter block is already present or not.

Change-Id: If786f6c008cc644f3398597901d718d12a6d865d
2014-04-01 10:04:12 -07:00
Sameer Agarwal 1cfb600bfc Add the (2,4,9) template specialization for PartitionedMatrixView
and SchurEliminator.

Also update the comment inside generate_partitioned_matrix_view_specializations.py

Change-Id: I99a7ab4256091b1da48553da3076e5996a5757ed
2014-03-26 12:59:32 -07:00
Alex Stewart 195e49351b Check validity of residual block before removal in RemoveResidualBlock.
- Breaking change: Problem::Options::enable_fast_parameter_block_removal
  is now Problem::Options::enable_fast_removal, as it now controls
  the behaviour for both parameter and residual blocks.

- Previously we did not check that the specified residual block to
  remove in RemoveResidualBlock actually represented a valid residual
  for the problem.
- This meant that Ceres would die unexpectedly if the user passed an
  uninitialised residual_block, or more likely attempted to remove a
  residual block that had already been removed automatically after
  the user removed a parameter block upon on which it was dependent.
- RemoveResidualBlock now verifies the validity of the given
  residual_block to remove.  Either by checking against a hash set of
  all residuals maintained in ProblemImpl iff enable_fast_removal
  is enabled.  Or by a full scan of the residual blocks if not.

Change-Id: I9ab178e2f68a74135f0a8e20905b16405c77a62b
2014-03-26 17:49:36 +00:00
Alex Stewart 74762b6033 Allow construction of an AutoDiffLocalParameterization with a functor.
- Previously AutoDiffLocalParameterization would internally instantiate
  a functor instance whenever one was required.  This prohibits the
  user passing arguments to the constructor of the functor.
- Now AutoDiffLocalParameterization can take over ownership of an
  allocated functor which the user created.  This mimics the behaviour
  of AutoDiffCostFunction.

Change-Id: I264e1face44ca5d5e71cc20c77cc7654d3f74cc0
2014-03-20 19:32:28 +00:00
Sameer Agarwal 7b3ffe5b8a Import the latest version of gmock and gtest.
Change-Id: Ife624fa9cd758c40c8e458828d7da8a51a14bb92
2014-03-11 10:48:40 -07:00
Johannes Schönberger 8956f561c6 Fix issues related to Clang / LLVM 3.4
There were a few unused variables. The Clang GoldPlugin no longer supports
the -O4 flag; it is now equivalent to -O3 -flto, which is backwards
compatible.

Change-Id: I90a8cfe88d90871de6cf3a175b2ced2806e3fd8e
2014-03-11 17:00:06 +00:00
Björn Piltz e52843c419 Fixed problem_test(Failed on Windows at least). The parantheses made the regex invalid.
Change-Id: I3318149918eee22b003af6b9effba6aa5cc9f970
2014-03-11 13:07:43 +01:00
Sameer Agarwal 4be580dd4b Reorder code in LineSearchMinimizer.
Change the order in which IterationSummary objects are
added to Solver::Summary and when the convergence tests
are done.

Previously there was a bug which prevented the iteration summary
from carrying the correct cost of the current state of the
optimization problem as the convergence test triggers before
the cost can be updated.

Thanks to Thad Hughes for reporting this.

Change-Id: Iba0dbb4cb30c9ec79fbc72ec5cf4602b2a0c207b
2014-02-26 11:44:16 -08:00
Sameer Agarwal 879fc2827a Remove CERES_NO_LINE_SEARCH_MINIMIZER.
Now that the trust region minimizer depends on the line search
minimizer, conditional compilation of the line search minimizer
will lead to build breakages, so this option is now not available.

It is not expected to have as significant impact on users as the
amount of code in the line search minimization algorithm is
rather small to begin with.

Change-Id: I2aa6b6e6e3931b6428dbda654f14faf1ac6dd130
2014-02-25 11:35:54 -08:00
Sameer Agarwal 9bd23f29e8 Update documentation.
1. Reflect the demise of the various FOO_TOLERANCE convergence
types.

2. Update the documentation for Solver::Options::gradient_tolerance.

Change-Id: I6bd11d260d6f8a3222b6a41a62dc4943ec8fcfbf
2014-02-24 22:30:21 -08:00
Sameer Agarwal 3dd7ed7249 Silence LineSearch on demand.
Add LineSearch::Options::is_silent which allows the user to turn
off all LOG(WARNING) logging off.

This is useful when calling LineSearch from the TrustRegionMinimizer
where the verbosity of the line search is of no use.

Change-Id: I4f1855e98f3cf3c3659d92b54586ff88d64e5ebe
2014-02-24 22:01:45 -08:00
Sameer Agarwal 6e3aad289f Lint cleanup from William Rucklidge.
Change-Id: Ifb36de18f95d521242d8853bb54024b09effb937
2014-02-24 13:35:26 -08:00
Sameer Agarwal 1da9292016 Changes to how gradient based convergence is diagnosed.
The original implementation for computing the norm of the gradient was

gradient_norm = norm(gradient)

when the gradient vector lies in the same space as the parameter
vector, this value is meaningful. When there is a local parameterization
involved, interpreting this value and diagnosing convergence using it
is hard.

Further, this expression does not respect the bounds constraints
on the parmeters. Measuring the norm of the gradient only makes
sense when the optimization being performed is unconstrained.

A better solution, used by LANCELOT is the expression
gradient_norm = norm(x - P(x - gradient))

Here, P is the projection operator onto the bounds constraints.
x - gradient is computed by computing Plus(x, -gradient), thus the
actual expression becomes

gradient_norm = norm(x - P(Plus(x, -gradient)));

Which in the case where there are no bounds constraints, and there
are no local parameterizations, reduces to the usual Euclidean
expression from above, since

Plus(x, -gradient) = x - gradient

and P(x - gradient) = x - gradient.

This change implements this change. Further, the convergence
test using the gradient tolerance now uses an absolute measure
rather than a relative measure. This is a forward looking change
as we start implementing the Augmented Lagrangian solver.

Last but not the least, various "Terminating: Foo" messages
have been changed so that "Terminating: " is logged but is
not part of the Solver::Summary::message string as it is
pointless.

Change-Id: I943146f71a1da47c8c7592986039b4112781b99b
2014-02-24 10:54:46 -08:00
Sameer Agarwal b5f6ca84ce Add tests for feasibility testing of bounds constrained problems.
Change-Id: Ib86f73cc121c893d4bcfa1c8e393ef2ddddfe348
2014-02-19 15:22:40 -08:00
Sameer Agarwal d789b00219 Improve infeasibility detection for constant and
variable parameter blocks.

1. Check if constant parameter blocks have infeasible values.
2. Check if variable parameter blocks have impossible bounds.

Change-Id: I0a58bc3eba42f0655fe90b58ea6ee21fae8c8f61
2014-02-19 00:32:58 -08:00
Sameer Agarwal a482ab8ad5 Add Problem::SetParameterLowerBound and Problem::SetParameterUpperBound.
These two methods allow the user to associate upper and lower bounds
with individual parameters inside parameter blocks.

Change-Id: I68dc37f20b64408da510ba06b89a4f08df54ddad
2014-02-19 00:06:41 -08:00
Sameer Agarwal fc827de385 Deal with bounds constrained problems in the Solver.
1. Detect if the problem is bounds constrained.
2. Detect if the problem is infeasible due to
   constant infeasible parameter blocks.
3. Simplify the interface to TrustRegionMinimize and
   LineSearchMinimize. In the process fix a bug related
   to early return and the way user state pointers
   were being dealt with in parameter blocks.

Change-Id: Ie7e70862029d3e0734636882c21ea594516119d1
2014-02-19 00:01:29 -08:00
Sameer Agarwal 5cf867be49 Add support for bounds to ParameterBlock.
Add setters and getters for lower and upper bounds.
Generalize the Plus operation to include projection onto the
hypercube implied by the bounds.

Change-Id: I1e4028a9886c4064f31bbc5b7c22b0341a56c15d
2014-02-18 21:15:59 -08:00
Sameer Agarwal 978d931ba8 Add line search to the trust region minimizer.
If enabled, the TrustRegionMinimizer can now further improve the
quality of the step with a Armijo line search.

This is the first step towards adding support for bounds on
variables.

Change-Id: I453b42853cfa6ca4f75812900c13d286a473c2df
2014-02-18 15:33:57 -08:00
Sameer Agarwal f949bab440 Add Problem::GetParameterization.
This allows the user to query the local parameterization associated
with a parameter block.

Change-Id: I3ab274aa88221c8e2def7c463825bf3927b1fdc9
2014-02-18 10:11:02 -08:00
Sameer Agarwal e5d62197b9 Remove all references to int16.
Change-Id: Iab87463dd32f64ee371e6cc7d1f5e30128412a10
2014-02-15 15:02:26 -08:00
Sameer Agarwal 5e8321c39a Validate ParameterBlocks before solve.
Ensure that all parameter blocks have finite values
before the minimizer is called.

Change-Id: I15fd9c487247989626f799496bb8f5ea8728d6f0
2014-02-05 11:12:16 -08:00
Sameer Agarwal 63cff485b6 Fix a leak in SchurComplementSolver.
cholmod_lhs was not being freed before
the SolveImpl function returned if the
underlying linear solver failed.

Change-Id: Id45db4f69a2821e43dc00fc975718584d426f44d
2014-02-03 11:27:39 -08:00