modeling_faqs.rst 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. .. _chapter-modeling_faqs:
  2. .. default-domain:: cpp
  3. .. cpp:namespace:: ceres
  4. ========
  5. Modeling
  6. ========
  7. #. Use analytical/automatic derivatives.
  8. This is the single most important piece of advice we can give to
  9. you. It is tempting to take the easy way out and use numeric
  10. differentiation. This is a bad idea. Numeric differentiation is
  11. slow, ill-behaved, hard to get right, and results in poor
  12. convergence behaviour.
  13. Ceres allows the user to define templated functors which will
  14. be automatically differentiated. For most situations this is enough
  15. and we recommend using this facility. In some cases the derivatives
  16. are simple enough or the performance considerations are such that
  17. the overhead of automatic differentiation is too much. In such
  18. cases, analytic derivatives are recommended.
  19. The use of numerical derivatives should be a measure of last
  20. resort, where it is simply not possible to write a templated
  21. implementation of the cost function.
  22. In many cases it is not possible to do analytic or automatic
  23. differentiation of the entire cost function, but it is generally
  24. the case that it is possible to decompose the cost function into
  25. parts that need to be numerically differentiated and parts that can
  26. be automatically or analytically differentiated.
  27. To this end, Ceres has extensive support for mixing analytic,
  28. automatic and numeric differentiation. See
  29. :class:`CostFunctionToFunctor`.
  30. #. When using Quaternions, consider using :class:`QuaternionManifold`.
  31. `Quaternions <https://en.wikipedia.org/wiki/Quaternion>`_ are a
  32. four dimensional parameterization of the space of three dimensional
  33. rotations :math:`SO(3)`. However, the :math:`SO(3)` is a three
  34. dimensional set, and so is the tangent space of a
  35. Quaternion. Therefore, it is sometimes (not always) beneficial to
  36. associate a local parameterization with parameter blocks
  37. representing a Quaternion. Assuming that the order of entries in
  38. your parameter block is :math:`w,x,y,z`, you can use
  39. :class:`QuaternionManifold`.
  40. .. NOTE::
  41. If you are using `Eigen's Quaternion
  42. <http://eigen.tuxfamily.org/dox/classEigen_1_1Quaternion.html>`_
  43. object, whose layout is :math:`x,y,z,w`, then you should use
  44. :class:`EigenQuaternionManifold`.
  45. #. How do I solve problems with general linear & non-linear
  46. **inequality** constraints with Ceres Solver?
  47. Currently, Ceres Solver only supports upper and lower bounds
  48. constraints on the parameter blocks.
  49. A crude way of dealing with inequality constraints is have one or
  50. more of your cost functions check if the inequalities you are
  51. interested in are satisfied, and if not return false instead of
  52. true. This will prevent the solver from ever stepping into an
  53. infeasible region.
  54. This requires that the starting point for the optimization be a
  55. feasible point. You also risk pre-mature convergence using this
  56. method.
  57. #. How do I solve problems with general linear & non-linear **equality**
  58. constraints with Ceres Solver?
  59. There is no built in support in ceres for solving problems with
  60. equality constraints. Currently, Ceres Solver only supports upper
  61. and lower bounds constraints on the parameter blocks.
  62. The trick described above for dealing with inequality
  63. constraints will **not** work for equality constraints.
  64. #. How do I set one or more components of a parameter block constant?
  65. Using :class:`SubsetManifold`.