Imported Upstream version ceres 1.13.0
[platform/upstream/ceres-solver.git] / docs / source / derivatives.rst
1 .. default-domain:: cpp
2
3 .. cpp:namespace:: ceres
4
5 .. _chapter-on_derivatives:
6
7 ==============
8 On Derivatives
9 ==============
10
11 Ceres Solver, like all gradient based optimization algorithms, depends
12 on being able to evaluate the objective function and its derivatives
13 at arbitrary points in its domain. Indeed, defining the objective
14 function and its `Jacobian
15 <https://en.wikipedia.org/wiki/Jacobian_matrix_and_determinant>`_ is
16 the principal task that the user is required to perform when solving
17 an optimization problem using Ceres Solver. The correct and efficient
18 computation of the Jacobian is the key to good performance.
19
20 Ceres Solver offers considerable flexibility in how the user can
21 provide derivatives to the solver. She can use:
22
23 #. :ref:`chapter-analytical_derivatives`: The user figures out the
24    derivatives herself, by hand or using a tool like `Maple
25    <https://www.maplesoft.com/products/maple/>`_ or `Mathematica
26    <https://www.wolfram.com/mathematica/>`_, and implements them in a
27    :class:`CostFunction`.
28 #. :ref:`chapter-numerical_derivatives`: Ceres numerically computes
29    the derivative using finite differences.
30 #. :ref:`chapter-automatic_derivatives`: Ceres automatically computes
31    the analytic derivative using C++ templates and operator
32    overloading.
33
34 Which of these three approaches (alone or in combination) should be
35 used depends on the situation and the tradeoffs the user is willing to
36 make. Unfortunately, numerical optimization textbooks rarely discuss
37 these issues in detail and the user is left to her own devices.
38
39 The aim of this article is to fill this gap and describe each of these
40 three approaches in the context of Ceres Solver with sufficient detail
41 that the user can make an informed choice.
42
43 For the impatient amongst you, here is some high level advice:
44
45 #. Use :ref:`chapter-automatic_derivatives`.
46 #. In some cases it maybe worth using
47    :ref:`chapter-analytical_derivatives`.
48 #. Avoid :ref:`chapter-numerical_derivatives`. Use it as a measure of
49    last resort, mostly to interface with external libraries.
50
51 For the rest, read on.
52
53 .. toctree::
54    :maxdepth: 1
55
56    spivak_notation
57    analytical_derivatives
58    numerical_derivatives
59    automatic_derivatives
60    interfacing_with_autodiff