blob: bff6a298d7ddbc69e59058de27a0809eeb340240 [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001.. default-domain:: cpp
2
3.. cpp:namespace:: ceres
4
5.. _chapter-on_derivatives:
6
7==============
8On Derivatives
9==============
10
11Ceres Solver, like all gradient based optimization algorithms, depends
12on being able to evaluate the objective function and its derivatives
13at arbitrary points in its domain. Indeed, defining the objective
14function and its `Jacobian
15<https://en.wikipedia.org/wiki/Jacobian_matrix_and_determinant>`_ is
16the principal task that the user is required to perform when solving
17an optimization problem using Ceres Solver. The correct and efficient
18computation of the Jacobian is the key to good performance.
19
20Ceres Solver offers considerable flexibility in how the user can
21provide 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
34Which of these three approaches (alone or in combination) should be
35used depends on the situation and the tradeoffs the user is willing to
36make. Unfortunately, numerical optimization textbooks rarely discuss
37these issues in detail and the user is left to her own devices.
38
39The aim of this article is to fill this gap and describe each of these
40three approaches in the context of Ceres Solver with sufficient detail
41that the user can make an informed choice.
42
43For 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
51For 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