nnls_solving.rst 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431
  1. .. default-domain:: cpp
  2. .. highlight:: c++
  3. .. cpp:namespace:: ceres
  4. .. _chapter-nnls_solving:
  5. ================================
  6. Solving Non-linear Least Squares
  7. ================================
  8. Introduction
  9. ============
  10. Effective use of Ceres requires some familiarity with the basic
  11. components of a non-linear least squares solver, so before we describe
  12. how to configure and use the solver, we will take a brief look at how
  13. some of the core optimization algorithms in Ceres work.
  14. Let :math:`x \in \mathbb{R}^n` be an :math:`n`-dimensional vector of
  15. variables, and
  16. :math:`F(x) = \left[f_1(x), ... , f_{m}(x) \right]^{\top}` be a
  17. :math:`m`-dimensional function of :math:`x`. We are interested in
  18. solving the optimization problem [#f1]_
  19. .. math:: \arg \min_x \frac{1}{2}\|F(x)\|^2\ . \\
  20. L \le x \le U
  21. :label: nonlinsq
  22. Where, :math:`L` and :math:`U` are lower and upper bounds on the
  23. parameter vector :math:`x`.
  24. Since the efficient global minimization of :eq:`nonlinsq` for
  25. general :math:`F(x)` is an intractable problem, we will have to settle
  26. for finding a local minimum.
  27. In the following, the Jacobian :math:`J(x)` of :math:`F(x)` is an
  28. :math:`m\times n` matrix, where :math:`J_{ij}(x) = \partial_j f_i(x)`
  29. and the gradient vector is :math:`g(x) = \nabla \frac{1}{2}\|F(x)\|^2
  30. = J(x)^\top F(x)`.
  31. The general strategy when solving non-linear optimization problems is
  32. to solve a sequence of approximations to the original problem
  33. [NocedalWright]_. At each iteration, the approximation is solved to
  34. determine a correction :math:`\Delta x` to the vector :math:`x`. For
  35. non-linear least squares, an approximation can be constructed by using
  36. the linearization :math:`F(x+\Delta x) \approx F(x) + J(x)\Delta x`,
  37. which leads to the following linear least squares problem:
  38. .. math:: \min_{\Delta x} \frac{1}{2}\|J(x)\Delta x + F(x)\|^2
  39. :label: linearapprox
  40. Unfortunately, naively solving a sequence of these problems and
  41. updating :math:`x \leftarrow x+ \Delta x` leads to an algorithm that
  42. may not converge. To get a convergent algorithm, we need to control
  43. the size of the step :math:`\Delta x`. Depending on how the size of
  44. the step :math:`\Delta x` is controlled, non-linear optimization
  45. algorithms can be divided into two major categories [NocedalWright]_.
  46. 1. **Trust Region** The trust region approach approximates the
  47. objective function using a model function (often a quadratic) over
  48. a subset of the search space known as the trust region. If the
  49. model function succeeds in minimizing the true objective function
  50. the trust region is expanded; conversely, otherwise it is
  51. contracted and the model optimization problem is solved again.
  52. 2. **Line Search** The line search approach first finds a descent
  53. direction along which the objective function will be reduced and
  54. then computes a step size that decides how far should move along
  55. that direction. The descent direction can be computed by various
  56. methods, such as gradient descent, Newton's method and Quasi-Newton
  57. method. The step size can be determined either exactly or
  58. inexactly.
  59. Trust region methods are in some sense dual to line search methods:
  60. trust region methods first choose a step size (the size of the trust
  61. region) and then a step direction while line search methods first
  62. choose a step direction and then a step size. Ceres implements
  63. multiple algorithms in both categories.
  64. .. _section-trust-region-methods:
  65. Trust Region Methods
  66. ====================
  67. The basic trust region algorithm looks something like this.
  68. 1. Given an initial point :math:`x` and a trust region radius :math:`\mu`.
  69. 2. Solve
  70. .. math::
  71. \arg \min_{\Delta x}& \frac{1}{2}\|J(x)\Delta x + F(x)\|^2 \\
  72. \text{such that} &\|D(x)\Delta x\|^2 \le \mu\\
  73. &L \le x + \Delta x \le U.
  74. 3. :math:`\rho = \frac{\displaystyle \|F(x + \Delta x)\|^2 -
  75. \|F(x)\|^2}{\displaystyle \|J(x)\Delta x + F(x)\|^2 -
  76. \|F(x)\|^2}`
  77. 4. if :math:`\rho > \epsilon` then :math:`x = x + \Delta x`.
  78. 5. if :math:`\rho > \eta_1` then :math:`\mu = 2 \mu`
  79. 6. else if :math:`\rho < \eta_2` then :math:`\mu = 0.5 * \mu`
  80. 7. Go to 2.
  81. Here, :math:`\mu` is the trust region radius, :math:`D(x)` is some
  82. matrix used to define a metric on the domain of :math:`F(x)` and
  83. :math:`\rho` measures the quality of the step :math:`\Delta x`, i.e.,
  84. how well did the linear model predict the decrease in the value of the
  85. non-linear objective. The idea is to increase or decrease the radius
  86. of the trust region depending on how well the linearization predicts
  87. the behavior of the non-linear objective, which in turn is reflected
  88. in the value of :math:`\rho`.
  89. The key computational step in a trust-region algorithm is the solution
  90. of the constrained optimization problem
  91. .. math::
  92. \arg \min_{\Delta x}&\quad \frac{1}{2}\|J(x)\Delta x + F(x)\|^2 \\
  93. \text{such that} &\quad \|D(x)\Delta x\|^2 \le \mu\\
  94. &\quad L \le x + \Delta x \le U.
  95. :label: trp
  96. There are a number of different ways of solving this problem, each
  97. giving rise to a different concrete trust-region algorithm. Currently,
  98. Ceres implements two trust-region algorithms - Levenberg-Marquardt
  99. and Dogleg, each of which is augmented with a line search if bounds
  100. constraints are present [Kanzow]_. The user can choose between them by
  101. setting :member:`Solver::Options::trust_region_strategy_type`.
  102. .. rubric:: Footnotes
  103. .. [#f1] At the level of the non-linear solver, the block structure is
  104. not relevant, therefore our discussion here is in terms of an
  105. optimization problem defined over a state vector of size
  106. :math:`n`. Similarly the presence of loss functions is also
  107. ignored as the problem is internally converted into a pure
  108. non-linear least squares problem.
  109. .. _section-levenberg-marquardt:
  110. Levenberg-Marquardt
  111. -------------------
  112. The Levenberg-Marquardt algorithm [Levenberg]_ [Marquardt]_ is the
  113. most popular algorithm for solving non-linear least squares problems.
  114. It was also the first trust region algorithm to be developed
  115. [Levenberg]_ [Marquardt]_. Ceres implements an exact step [Madsen]_
  116. and an inexact step variant of the Levenberg-Marquardt algorithm
  117. [WrightHolt]_ [NashSofer]_.
  118. It can be shown, that the solution to :eq:`trp` can be obtained by
  119. solving an unconstrained optimization of the form
  120. .. math:: \arg\min_{\Delta x} \frac{1}{2}\|J(x)\Delta x + F(x)\|^2 +\lambda \|D(x)\Delta x\|^2
  121. Where, :math:`\lambda` is a Lagrange multiplier that is inverse
  122. related to :math:`\mu`. In Ceres, we solve for
  123. .. math:: \arg\min_{\Delta x} \frac{1}{2}\|J(x)\Delta x + F(x)\|^2 + \frac{1}{\mu} \|D(x)\Delta x\|^2
  124. :label: lsqr
  125. The matrix :math:`D(x)` is a non-negative diagonal matrix, typically
  126. the square root of the diagonal of the matrix :math:`J(x)^\top J(x)`.
  127. Before going further, let us make some notational simplifications. We
  128. will assume that the matrix :math:`\frac{1}{\sqrt{\mu}} D` has been concatenated
  129. at the bottom of the matrix :math:`J` and similarly a vector of zeros
  130. has been added to the bottom of the vector :math:`f` and the rest of
  131. our discussion will be in terms of :math:`J` and :math:`F`, i.e, the
  132. linear least squares problem.
  133. .. math:: \min_{\Delta x} \frac{1}{2} \|J(x)\Delta x + F(x)\|^2 .
  134. :label: simple
  135. For all but the smallest problems the solution of :eq:`simple` in
  136. each iteration of the Levenberg-Marquardt algorithm is the dominant
  137. computational cost in Ceres. Ceres provides a number of different
  138. options for solving :eq:`simple`. There are two major classes of
  139. methods - factorization and iterative.
  140. The factorization methods are based on computing an exact solution of
  141. :eq:`lsqr` using a Cholesky or a QR factorization and lead to an exact
  142. step Levenberg-Marquardt algorithm. But it is not clear if an exact
  143. solution of :eq:`lsqr` is necessary at each step of the LM algorithm
  144. to solve :eq:`nonlinsq`. In fact, we have already seen evidence
  145. that this may not be the case, as :eq:`lsqr` is itself a regularized
  146. version of :eq:`linearapprox`. Indeed, it is possible to
  147. construct non-linear optimization algorithms in which the linearized
  148. problem is solved approximately. These algorithms are known as inexact
  149. Newton or truncated Newton methods [NocedalWright]_.
  150. An inexact Newton method requires two ingredients. First, a cheap
  151. method for approximately solving systems of linear
  152. equations. Typically an iterative linear solver like the Conjugate
  153. Gradients method is used for this
  154. purpose [NocedalWright]_. Second, a termination rule for
  155. the iterative solver. A typical termination rule is of the form
  156. .. math:: \|H(x) \Delta x + g(x)\| \leq \eta_k \|g(x)\|.
  157. :label: inexact
  158. Here, :math:`k` indicates the Levenberg-Marquardt iteration number and
  159. :math:`0 < \eta_k <1` is known as the forcing sequence. [WrightHolt]_
  160. prove that a truncated Levenberg-Marquardt algorithm that uses an
  161. inexact Newton step based on :eq:`inexact` converges for any
  162. sequence :math:`\eta_k \leq \eta_0 < 1` and the rate of convergence
  163. depends on the choice of the forcing sequence :math:`\eta_k`.
  164. Ceres supports both exact and inexact step solution strategies. When
  165. the user chooses a factorization based linear solver, the exact step
  166. Levenberg-Marquardt algorithm is used. When the user chooses an
  167. iterative linear solver, the inexact step Levenberg-Marquardt
  168. algorithm is used.
  169. .. _section-dogleg:
  170. Dogleg
  171. ------
  172. Another strategy for solving the trust region problem :eq:`trp` was
  173. introduced by M. J. D. Powell. The key idea there is to compute two
  174. vectors
  175. .. math::
  176. \Delta x^{\text{Gauss-Newton}} &= \arg \min_{\Delta x}\frac{1}{2} \|J(x)\Delta x + f(x)\|^2.\\
  177. \Delta x^{\text{Cauchy}} &= -\frac{\|g(x)\|^2}{\|J(x)g(x)\|^2}g(x).
  178. Note that the vector :math:`\Delta x^{\text{Gauss-Newton}}` is the
  179. solution to :eq:`linearapprox` and :math:`\Delta
  180. x^{\text{Cauchy}}` is the vector that minimizes the linear
  181. approximation if we restrict ourselves to moving along the direction
  182. of the gradient. Dogleg methods finds a vector :math:`\Delta x`
  183. defined by :math:`\Delta x^{\text{Gauss-Newton}}` and :math:`\Delta
  184. x^{\text{Cauchy}}` that solves the trust region problem. Ceres
  185. supports two variants that can be chose by setting
  186. :member:`Solver::Options::dogleg_type`.
  187. ``TRADITIONAL_DOGLEG`` as described by Powell, constructs two line
  188. segments using the Gauss-Newton and Cauchy vectors and finds the point
  189. farthest along this line shaped like a dogleg (hence the name) that is
  190. contained in the trust-region. For more details on the exact reasoning
  191. and computations, please see Madsen et al [Madsen]_.
  192. ``SUBSPACE_DOGLEG`` is a more sophisticated method that considers the
  193. entire two dimensional subspace spanned by these two vectors and finds
  194. the point that minimizes the trust region problem in this subspace
  195. [ByrdSchnabel]_.
  196. The key advantage of the Dogleg over Levenberg-Marquardt is that if
  197. the step computation for a particular choice of :math:`\mu` does not
  198. result in sufficient decrease in the value of the objective function,
  199. Levenberg-Marquardt solves the linear approximation from scratch with
  200. a smaller value of :math:`\mu`. Dogleg on the other hand, only needs
  201. to compute the interpolation between the Gauss-Newton and the Cauchy
  202. vectors, as neither of them depend on the value of :math:`\mu`.
  203. The Dogleg method can only be used with the exact factorization based
  204. linear solvers.
  205. .. _section-inner-iterations:
  206. Inner Iterations
  207. ----------------
  208. Some non-linear least squares problems have additional structure in
  209. the way the parameter blocks interact that it is beneficial to modify
  210. the way the trust region step is computed. For example, consider the
  211. following regression problem
  212. .. math:: y = a_1 e^{b_1 x} + a_2 e^{b_3 x^2 + c_1}
  213. Given a set of pairs :math:`\{(x_i, y_i)\}`, the user wishes to estimate
  214. :math:`a_1, a_2, b_1, b_2`, and :math:`c_1`.
  215. Notice that the expression on the left is linear in :math:`a_1` and
  216. :math:`a_2`, and given any value for :math:`b_1, b_2` and :math:`c_1`,
  217. it is possible to use linear regression to estimate the optimal values
  218. of :math:`a_1` and :math:`a_2`. It's possible to analytically
  219. eliminate the variables :math:`a_1` and :math:`a_2` from the problem
  220. entirely. Problems like these are known as separable least squares
  221. problem and the most famous algorithm for solving them is the Variable
  222. Projection algorithm invented by Golub & Pereyra [GolubPereyra]_.
  223. Similar structure can be found in the matrix factorization with
  224. missing data problem. There the corresponding algorithm is known as
  225. Wiberg's algorithm [Wiberg]_.
  226. Ruhe & Wedin present an analysis of various algorithms for solving
  227. separable non-linear least squares problems and refer to *Variable
  228. Projection* as Algorithm I in their paper [RuheWedin]_.
  229. Implementing Variable Projection is tedious and expensive. Ruhe &
  230. Wedin present a simpler algorithm with comparable convergence
  231. properties, which they call Algorithm II. Algorithm II performs an
  232. additional optimization step to estimate :math:`a_1` and :math:`a_2`
  233. exactly after computing a successful Newton step.
  234. This idea can be generalized to cases where the residual is not
  235. linear in :math:`a_1` and :math:`a_2`, i.e.,
  236. .. math:: y = f_1(a_1, e^{b_1 x}) + f_2(a_2, e^{b_3 x^2 + c_1})
  237. In this case, we solve for the trust region step for the full problem,
  238. and then use it as the starting point to further optimize just `a_1`
  239. and `a_2`. For the linear case, this amounts to doing a single linear
  240. least squares solve. For non-linear problems, any method for solving
  241. the :math:`a_1` and :math:`a_2` optimization problems will do. The
  242. only constraint on :math:`a_1` and :math:`a_2` (if they are two
  243. different parameter block) is that they do not co-occur in a residual
  244. block.
  245. This idea can be further generalized, by not just optimizing
  246. :math:`(a_1, a_2)`, but decomposing the graph corresponding to the
  247. Hessian matrix's sparsity structure into a collection of
  248. non-overlapping independent sets and optimizing each of them.
  249. Setting :member:`Solver::Options::use_inner_iterations` to ``true``
  250. enables the use of this non-linear generalization of Ruhe & Wedin's
  251. Algorithm II. This version of Ceres has a higher iteration
  252. complexity, but also displays better convergence behavior per
  253. iteration.
  254. Setting :member:`Solver::Options::num_threads` to the maximum number
  255. possible is highly recommended.
  256. .. _section-non-monotonic-steps:
  257. Non-monotonic Steps
  258. -------------------
  259. Note that the basic trust-region algorithm described in
  260. :ref:`section-trust-region-methods` is a descent algorithm in that it
  261. only accepts a point if it strictly reduces the value of the objective
  262. function.
  263. Relaxing this requirement allows the algorithm to be more efficient in
  264. the long term at the cost of some local increase in the value of the
  265. objective function.
  266. This is because allowing for non-decreasing objective function values
  267. in a principled manner allows the algorithm to *jump over boulders* as
  268. the method is not restricted to move into narrow valleys while
  269. preserving its convergence properties.
  270. Setting :member:`Solver::Options::use_nonmonotonic_steps` to ``true``
  271. enables the non-monotonic trust region algorithm as described by Conn,
  272. Gould & Toint in [Conn]_.
  273. Even though the value of the objective function may be larger
  274. than the minimum value encountered over the course of the
  275. optimization, the final parameters returned to the user are the
  276. ones corresponding to the minimum cost over all iterations.
  277. The option to take non-monotonic steps is available for all trust
  278. region strategies.
  279. .. _section-line-search-methods:
  280. Line Search Methods
  281. ===================
  282. The line search method in Ceres Solver cannot handle bounds
  283. constraints right now, so it can only be used for solving
  284. unconstrained problems.
  285. Line search algorithms
  286. 1. Given an initial point :math:`x`
  287. 2. :math:`\Delta x = -H^{-1}(x) g(x)`
  288. 3. :math:`\arg \min_\mu \frac{1}{2} \| F(x + \mu \Delta x) \|^2`
  289. 4. :math:`x = x + \mu \Delta x`
  290. 5. Goto 2.
  291. Here :math:`H(x)` is some approximation to the Hessian of the
  292. objective function, and :math:`g(x)` is the gradient at
  293. :math:`x`. Depending on the choice of :math:`H(x)` we get a variety of
  294. different search directions :math:`\Delta x`.
  295. Step 4, which is a one dimensional optimization or `Line Search` along
  296. :math:`\Delta x` is what gives this class of methods its name.
  297. Different line search algorithms differ in their choice of the search
  298. direction :math:`\Delta x` and the method used for one dimensional
  299. optimization along :math:`\Delta x`. The choice of :math:`H(x)` is the
  300. primary source of computational complexity in these
  301. methods. Currently, Ceres Solver supports three choices of search
  302. directions, all aimed at large scale problems.
  303. 1. ``STEEPEST_DESCENT`` This corresponds to choosing :math:`H(x)` to
  304. be the identity matrix. This is not a good search direction for
  305. anything but the simplest of the problems. It is only included here
  306. for completeness.
  307. 2. ``NONLINEAR_CONJUGATE_GRADIENT`` A generalization of the Conjugate
  308. Gradient method to non-linear functions. The generalization can be
  309. performed in a number of different ways, resulting in a variety of
  310. search directions. Ceres Solver currently supports
  311. ``FLETCHER_REEVES``, ``POLAK_RIBIERE`` and ``HESTENES_STIEFEL``
  312. directions.
  313. 3. ``BFGS`` A generalization of the Secant method to multiple
  314. dimensions in which a full, dense approximation to the inverse
  315. Hessian is maintained and used to compute a quasi-Newton step
  316. [NocedalWright]_. BFGS is currently the best known general
  317. quasi-Newton algorithm.
  318. 4. ``LBFGS`` A limited memory approximation to the full ``BFGS``
  319. method in which the last `M` iterations are used to approximate the
  320. inverse Hessian used to compute a quasi-Newton step [Nocedal]_,
  321. [ByrdNocedal]_.
  322. Currently Ceres Solver supports both a backtracking and interpolation
  323. based Armijo line search algorithm, and a sectioning / zoom
  324. interpolation (strong) Wolfe condition line search algorithm.
  325. However, note that in order for the assumptions underlying the
  326. ``BFGS`` and ``LBFGS`` methods to be guaranteed to be satisfied the
  327. Wolfe line search algorithm should be used.
  328. .. _section-linear-solver:
  329. LinearSolver
  330. ============
  331. Recall that in both of the trust-region methods described above, the
  332. key computational cost is the solution of a linear least squares
  333. problem of the form
  334. .. math:: \min_{\Delta x} \frac{1}{2} \|J(x)\Delta x + f(x)\|^2 .
  335. :label: simple2
  336. Let :math:`H(x)= J(x)^\top J(x)` and :math:`g(x) = -J(x)^\top
  337. f(x)`. For notational convenience let us also drop the dependence on
  338. :math:`x`. Then it is easy to see that solving :eq:`simple2` is
  339. equivalent to solving the *normal equations*.
  340. .. math:: H \Delta x = g
  341. :label: normal
  342. Ceres provides a number of different options for solving :eq:`normal`.
  343. .. _section-qr:
  344. ``DENSE_QR``
  345. ------------
  346. For small problems (a couple of hundred parameters and a few thousand
  347. residuals) with relatively dense Jacobians, ``DENSE_QR`` is the method
  348. of choice [Bjorck]_. Let :math:`J = QR` be the QR-decomposition of
  349. :math:`J`, where :math:`Q` is an orthonormal matrix and :math:`R` is
  350. an upper triangular matrix [TrefethenBau]_. Then it can be shown that
  351. the solution to :eq:`normal` is given by
  352. .. math:: \Delta x^* = -R^{-1}Q^\top f
  353. Ceres uses ``Eigen`` 's dense QR factorization routines.
  354. .. _section-cholesky:
  355. ``DENSE_NORMAL_CHOLESKY`` & ``SPARSE_NORMAL_CHOLESKY``
  356. ------------------------------------------------------
  357. Large non-linear least square problems are usually sparse. In such
  358. cases, using a dense QR factorization is inefficient. Let :math:`H =
  359. R^\top R` be the Cholesky factorization of the normal equations, where
  360. :math:`R` is an upper triangular matrix, then the solution to
  361. :eq:`normal` is given by
  362. .. math::
  363. \Delta x^* = R^{-1} R^{-\top} g.
  364. The observant reader will note that the :math:`R` in the Cholesky
  365. factorization of :math:`H` is the same upper triangular matrix
  366. :math:`R` in the QR factorization of :math:`J`. Since :math:`Q` is an
  367. orthonormal matrix, :math:`J=QR` implies that :math:`J^\top J = R^\top
  368. Q^\top Q R = R^\top R`. There are two variants of Cholesky
  369. factorization -- sparse and dense.
  370. ``DENSE_NORMAL_CHOLESKY`` as the name implies performs a dense
  371. Cholesky factorization of the normal equations. Ceres uses
  372. ``Eigen`` 's dense LDLT factorization routines.
  373. ``SPARSE_NORMAL_CHOLESKY``, as the name implies performs a sparse
  374. Cholesky factorization of the normal equations. This leads to
  375. substantial savings in time and memory for large sparse problems. The
  376. use of this linear solver requires that Ceres is compiled with support
  377. for at least one of:
  378. 1. SuiteSparse
  379. 2. Apple's Accelerate framework.
  380. 3. Eigen's sparse linear solvers.
  381. .. _section-cgnr:
  382. ``CGNR``
  383. --------
  384. For general sparse problems, if the problem is too large for
  385. ``CHOLMOD`` or a sparse linear algebra library is not linked into
  386. Ceres, another option is the ``CGNR`` solver. This solver uses the
  387. Conjugate Gradients solver on the *normal equations*, but without
  388. forming the normal equations explicitly. It exploits the relation
  389. .. math::
  390. H x = J^\top J x = J^\top(J x)
  391. The convergence of Conjugate Gradients depends on the conditioner
  392. number :math:`\kappa(H)`. Usually :math:`H` is poorly conditioned and
  393. a :ref:`section-preconditioner` must be used to get reasonable
  394. performance. Currently only the ``JACOBI`` preconditioner is available
  395. for use with ``CGNR``. It uses the block diagonal of :math:`H` to
  396. precondition the normal equations.
  397. When the user chooses ``CGNR`` as the linear solver, Ceres
  398. automatically switches from the exact step algorithm to an inexact
  399. step algorithm.
  400. .. _section-schur:
  401. ``DENSE_SCHUR`` & ``SPARSE_SCHUR``
  402. ----------------------------------
  403. While it is possible to use ``SPARSE_NORMAL_CHOLESKY`` to solve bundle
  404. adjustment problems, bundle adjustment problem have a special
  405. structure, and a more efficient scheme for solving :eq:`normal`
  406. can be constructed.
  407. Suppose that the SfM problem consists of :math:`p` cameras and
  408. :math:`q` points and the variable vector :math:`x` has the block
  409. structure :math:`x = [y_{1}, ... ,y_{p},z_{1}, ... ,z_{q}]`. Where,
  410. :math:`y` and :math:`z` correspond to camera and point parameters,
  411. respectively. Further, let the camera blocks be of size :math:`c` and
  412. the point blocks be of size :math:`s` (for most problems :math:`c` =
  413. :math:`6`--`9` and :math:`s = 3`). Ceres does not impose any constancy
  414. requirement on these block sizes, but choosing them to be constant
  415. simplifies the exposition.
  416. A key characteristic of the bundle adjustment problem is that there is
  417. no term :math:`f_{i}` that includes two or more point blocks. This in
  418. turn implies that the matrix :math:`H` is of the form
  419. .. math:: H = \left[ \begin{matrix} B & E\\ E^\top & C \end{matrix} \right]\ ,
  420. :label: hblock
  421. where :math:`B \in \mathbb{R}^{pc\times pc}` is a block sparse matrix
  422. with :math:`p` blocks of size :math:`c\times c` and :math:`C \in
  423. \mathbb{R}^{qs\times qs}` is a block diagonal matrix with :math:`q` blocks
  424. of size :math:`s\times s`. :math:`E \in \mathbb{R}^{pc\times qs}` is a
  425. general block sparse matrix, with a block of size :math:`c\times s`
  426. for each observation. Let us now block partition :math:`\Delta x =
  427. [\Delta y,\Delta z]` and :math:`g=[v,w]` to restate :eq:`normal`
  428. as the block structured linear system
  429. .. math:: \left[ \begin{matrix} B & E\\ E^\top & C \end{matrix}
  430. \right]\left[ \begin{matrix} \Delta y \\ \Delta z
  431. \end{matrix} \right] = \left[ \begin{matrix} v\\ w
  432. \end{matrix} \right]\ ,
  433. :label: linear2
  434. and apply Gaussian elimination to it. As we noted above, :math:`C` is
  435. a block diagonal matrix, with small diagonal blocks of size
  436. :math:`s\times s`. Thus, calculating the inverse of :math:`C` by
  437. inverting each of these blocks is cheap. This allows us to eliminate
  438. :math:`\Delta z` by observing that :math:`\Delta z = C^{-1}(w - E^\top
  439. \Delta y)`, giving us
  440. .. math:: \left[B - EC^{-1}E^\top\right] \Delta y = v - EC^{-1}w\ .
  441. :label: schur
  442. The matrix
  443. .. math:: S = B - EC^{-1}E^\top
  444. is the Schur complement of :math:`C` in :math:`H`. It is also known as
  445. the *reduced camera matrix*, because the only variables
  446. participating in :eq:`schur` are the ones corresponding to the
  447. cameras. :math:`S \in \mathbb{R}^{pc\times pc}` is a block structured
  448. symmetric positive definite matrix, with blocks of size :math:`c\times
  449. c`. The block :math:`S_{ij}` corresponding to the pair of images
  450. :math:`i` and :math:`j` is non-zero if and only if the two images
  451. observe at least one common point.
  452. Now, :eq:`linear2` can be solved by first forming :math:`S`, solving for
  453. :math:`\Delta y`, and then back-substituting :math:`\Delta y` to
  454. obtain the value of :math:`\Delta z`. Thus, the solution of what was
  455. an :math:`n\times n`, :math:`n=pc+qs` linear system is reduced to the
  456. inversion of the block diagonal matrix :math:`C`, a few matrix-matrix
  457. and matrix-vector multiplies, and the solution of block sparse
  458. :math:`pc\times pc` linear system :eq:`schur`. For almost all
  459. problems, the number of cameras is much smaller than the number of
  460. points, :math:`p \ll q`, thus solving :eq:`schur` is
  461. significantly cheaper than solving :eq:`linear2`. This is the
  462. *Schur complement trick* [Brown]_.
  463. This still leaves open the question of solving :eq:`schur`. The
  464. method of choice for solving symmetric positive definite systems
  465. exactly is via the Cholesky factorization [TrefethenBau]_ and
  466. depending upon the structure of the matrix, there are, in general, two
  467. options. The first is direct factorization, where we store and factor
  468. :math:`S` as a dense matrix [TrefethenBau]_. This method has
  469. :math:`O(p^2)` space complexity and :math:`O(p^3)` time complexity and
  470. is only practical for problems with up to a few hundred cameras. Ceres
  471. implements this strategy as the ``DENSE_SCHUR`` solver.
  472. But, :math:`S` is typically a fairly sparse matrix, as most images
  473. only see a small fraction of the scene. This leads us to the second
  474. option: Sparse Direct Methods. These methods store :math:`S` as a
  475. sparse matrix, use row and column re-ordering algorithms to maximize
  476. the sparsity of the Cholesky decomposition, and focus their compute
  477. effort on the non-zero part of the factorization [Chen]_. Sparse
  478. direct methods, depending on the exact sparsity structure of the Schur
  479. complement, allow bundle adjustment algorithms to significantly scale
  480. up over those based on dense factorization. Ceres implements this
  481. strategy as the ``SPARSE_SCHUR`` solver.
  482. .. _section-iterative_schur:
  483. ``ITERATIVE_SCHUR``
  484. -------------------
  485. Another option for bundle adjustment problems is to apply
  486. Preconditioned Conjugate Gradients to the reduced camera matrix
  487. :math:`S` instead of :math:`H`. One reason to do this is that
  488. :math:`S` is a much smaller matrix than :math:`H`, but more
  489. importantly, it can be shown that :math:`\kappa(S)\leq \kappa(H)`.
  490. Ceres implements Conjugate Gradients on :math:`S` as the
  491. ``ITERATIVE_SCHUR`` solver. When the user chooses ``ITERATIVE_SCHUR``
  492. as the linear solver, Ceres automatically switches from the exact step
  493. algorithm to an inexact step algorithm.
  494. The key computational operation when using Conjuagate Gradients is the
  495. evaluation of the matrix vector product :math:`Sx` for an arbitrary
  496. vector :math:`x`. There are two ways in which this product can be
  497. evaluated, and this can be controlled using
  498. ``Solver::Options::use_explicit_schur_complement``. Depending on the
  499. problem at hand, the performance difference between these two methods
  500. can be quite substantial.
  501. 1. **Implicit** This is default. Implicit evaluation is suitable for
  502. large problems where the cost of computing and storing the Schur
  503. Complement :math:`S` is prohibitive. Because PCG only needs
  504. access to :math:`S` via its product with a vector, one way to
  505. evaluate :math:`Sx` is to observe that
  506. .. math:: x_1 &= E^\top x\\
  507. x_2 &= C^{-1} x_1\\
  508. x_3 &= Ex_2\\
  509. x_4 &= Bx\\
  510. Sx &= x_4 - x_3
  511. :label: schurtrick1
  512. Thus, we can run PCG on :math:`S` with the same computational
  513. effort per iteration as PCG on :math:`H`, while reaping the
  514. benefits of a more powerful preconditioner. In fact, we do not
  515. even need to compute :math:`H`, :eq:`schurtrick1` can be
  516. implemented using just the columns of :math:`J`.
  517. Equation :eq:`schurtrick1` is closely related to *Domain
  518. Decomposition methods* for solving large linear systems that
  519. arise in structural engineering and partial differential
  520. equations. In the language of Domain Decomposition, each point in
  521. a bundle adjustment problem is a domain, and the cameras form the
  522. interface between these domains. The iterative solution of the
  523. Schur complement then falls within the sub-category of techniques
  524. known as Iterative Sub-structuring [Saad]_ [Mathew]_.
  525. 2. **Explicit** The complexity of implicit matrix-vector product
  526. evaluation scales with the number of non-zeros in the
  527. Jacobian. For small to medium sized problems, the cost of
  528. constructing the Schur Complement is small enough that it is
  529. better to construct it explicitly in memory and use it to
  530. evaluate the product :math:`Sx`.
  531. When the user chooses ``ITERATIVE_SCHUR`` as the linear solver, Ceres
  532. automatically switches from the exact step algorithm to an inexact
  533. step algorithm.
  534. .. NOTE::
  535. In exact arithmetic, the choice of implicit versus explicit Schur
  536. complement would have no impact on solution quality. However, in
  537. practice if the Jacobian is poorly conditioned, one may observe
  538. (usually small) differences in solution quality. This is a
  539. natural consequence of performing computations in finite arithmetic.
  540. .. _section-preconditioner:
  541. Preconditioner
  542. ==============
  543. The convergence rate of Conjugate Gradients for
  544. solving :eq:`normal` depends on the distribution of eigenvalues
  545. of :math:`H` [Saad]_. A useful upper bound is
  546. :math:`\sqrt{\kappa(H)}`, where, :math:`\kappa(H)` is the condition
  547. number of the matrix :math:`H`. For most bundle adjustment problems,
  548. :math:`\kappa(H)` is high and a direct application of Conjugate
  549. Gradients to :eq:`normal` results in extremely poor performance.
  550. The solution to this problem is to replace :eq:`normal` with a
  551. *preconditioned* system. Given a linear system, :math:`Ax =b` and a
  552. preconditioner :math:`M` the preconditioned system is given by
  553. :math:`M^{-1}Ax = M^{-1}b`. The resulting algorithm is known as
  554. Preconditioned Conjugate Gradients algorithm (PCG) and its worst case
  555. complexity now depends on the condition number of the *preconditioned*
  556. matrix :math:`\kappa(M^{-1}A)`.
  557. The computational cost of using a preconditioner :math:`M` is the cost
  558. of computing :math:`M` and evaluating the product :math:`M^{-1}y` for
  559. arbitrary vectors :math:`y`. Thus, there are two competing factors to
  560. consider: How much of :math:`H`'s structure is captured by :math:`M`
  561. so that the condition number :math:`\kappa(HM^{-1})` is low, and the
  562. computational cost of constructing and using :math:`M`. The ideal
  563. preconditioner would be one for which :math:`\kappa(M^{-1}A)
  564. =1`. :math:`M=A` achieves this, but it is not a practical choice, as
  565. applying this preconditioner would require solving a linear system
  566. equivalent to the unpreconditioned problem. It is usually the case
  567. that the more information :math:`M` has about :math:`H`, the more
  568. expensive it is use. For example, Incomplete Cholesky factorization
  569. based preconditioners have much better convergence behavior than the
  570. Jacobi preconditioner, but are also much more expensive.
  571. For a survey of the state of the art in preconditioning linear least
  572. squares problems with general sparsity structure see [GouldScott]_.
  573. Ceres Solver comes with an number of preconditioners suited for
  574. problems with general sparsity as well as the special sparsity
  575. structure encountered in bundle adjustment problems.
  576. ``JACOBI``
  577. ----------
  578. The simplest of all preconditioners is the diagonal or Jacobi
  579. preconditioner, i.e., :math:`M=\operatorname{diag}(A)`, which for
  580. block structured matrices like :math:`H` can be generalized to the
  581. block Jacobi preconditioner. The ``JACOBI`` preconditioner in Ceres
  582. when used with :ref:`section-cgnr` refers to the block diagonal of
  583. :math:`H` and when used with :ref:`section-iterative_schur` refers to
  584. the block diagonal of :math:`B` [Mandel]_. For detailed performance
  585. data about the performance of ``JACOBI`` on bundle adjustment problems
  586. see [Agarwal]_.
  587. ``SCHUR_JACOBI``
  588. ----------------
  589. Another obvious choice for :ref:`section-iterative_schur` is the block
  590. diagonal of the Schur complement matrix :math:`S`, i.e, the block
  591. Jacobi preconditioner for :math:`S`. In Ceres we refer to it as the
  592. ``SCHUR_JACOBI`` preconditioner. For detailed performance data about
  593. the performance of ``SCHUR_JACOBI`` on bundle adjustment problems see
  594. [Agarwal]_.
  595. ``CLUSTER_JACOBI`` and ``CLUSTER_TRIDIAGONAL``
  596. ----------------------------------------------
  597. For bundle adjustment problems arising in reconstruction from
  598. community photo collections, more effective preconditioners can be
  599. constructed by analyzing and exploiting the camera-point visibility
  600. structure of the scene.
  601. The key idea is to cluster the cameras based on the visibility
  602. structure of the scene. The similarity between a pair of cameras
  603. :math:`i` and :math:`j` is given by:
  604. .. math:: S_{ij} = \frac{|V_i \cap V_j|}{|V_i| |V_j|}
  605. Here :math:`V_i` is the set of scene points visible in camera
  606. :math:`i`. This idea was first exploited by [KushalAgarwal]_ to create
  607. the ``CLUSTER_JACOBI`` and the ``CLUSTER_TRIDIAGONAL`` preconditioners
  608. which Ceres implements.
  609. The performance of these two preconditioners depends on the speed and
  610. clustering quality of the clustering algorithm used when building the
  611. preconditioner. In the original paper, [KushalAgarwal]_ used the
  612. Canonical Views algorithm [Simon]_, which while producing high quality
  613. clusterings can be quite expensive for large graphs. So, Ceres
  614. supports two visibility clustering algorithms - ``CANONICAL_VIEWS``
  615. and ``SINGLE_LINKAGE``. The former is as the name implies Canonical
  616. Views algorithm of [Simon]_. The latter is the the classic `Single
  617. Linkage Clustering
  618. <https://en.wikipedia.org/wiki/Single-linkage_clustering>`_
  619. algorithm. The choice of clustering algorithm is controlled by
  620. :member:`Solver::Options::visibility_clustering_type`.
  621. ``SUBSET``
  622. ----------
  623. This is a preconditioner for problems with general sparsity. Given a
  624. subset of residual blocks of a problem, it uses the corresponding
  625. subset of the rows of the Jacobian to construct a preconditioner
  626. [Dellaert]_.
  627. Suppose the Jacobian :math:`J` has been horizontally partitioned as
  628. .. math:: J = \begin{bmatrix} P \\ Q \end{bmatrix}
  629. Where, :math:`Q` is the set of rows corresponding to the residual
  630. blocks in
  631. :member:`Solver::Options::residual_blocks_for_subset_preconditioner`. The
  632. preconditioner is the matrix :math:`(Q^\top Q)^{-1}`.
  633. The efficacy of the preconditioner depends on how well the matrix
  634. :math:`Q` approximates :math:`J^\top J`, or how well the chosen
  635. residual blocks approximate the full problem.
  636. .. _section-ordering:
  637. Ordering
  638. ========
  639. The order in which variables are eliminated in a linear solver can
  640. have a significant of impact on the efficiency and accuracy of the
  641. method. For example when doing sparse Cholesky factorization, there
  642. are matrices for which a good ordering will give a Cholesky factor
  643. with :math:`O(n)` storage, whereas a bad ordering will result in an
  644. completely dense factor.
  645. Ceres allows the user to provide varying amounts of hints to the
  646. solver about the variable elimination ordering to use. This can range
  647. from no hints, where the solver is free to decide the best possible
  648. ordering based on the user's choices like the linear solver being
  649. used, to an exact order in which the variables should be eliminated,
  650. and a variety of possibilities in between.
  651. Instances of the :class:`ParameterBlockOrdering` class are used to
  652. communicate this information to Ceres.
  653. Formally an ordering is an ordered partitioning of the
  654. parameter blocks, i.e, each parameter block belongs to exactly
  655. one group, and each group has a unique non-negative integer
  656. associated with it, that determines its order in the set of
  657. groups.
  658. e.g. Consider the linear system
  659. .. math::
  660. x + y &= 3 \\
  661. 2x + 3y &= 7
  662. There are two ways in which it can be solved. First eliminating
  663. :math:`x` from the two equations, solving for :math:`y` and then back
  664. substituting for :math:`x`, or first eliminating :math:`y`, solving
  665. for :math:`x` and back substituting for :math:`y`. The user can
  666. construct three orderings here.
  667. 1. :math:`\{0: x\}, \{1: y\}` - eliminate :math:`x` first.
  668. 2. :math:`\{0: y\}, \{1: x\}` - eliminate :math:`y` first.
  669. 3. :math:`\{0: x, y\}` - Solver gets to decide the elimination order.
  670. Thus, to have Ceres determine the ordering automatically, put all the
  671. variables in group 0 and to control the ordering for every variable,
  672. create groups :math:`0 \dots N-1`, one per variable, in the desired
  673. order.
  674. ``linear_solver_ordering == nullptr`` and an ordering where all the
  675. parameter blocks are in one elimination group mean the same thing -
  676. the solver is free to choose what it thinks is the best elimination
  677. ordering. Therefore in the following we will only consider the case
  678. where ``linear_solver_ordering != nullptr``.
  679. The exact interpretation of the ``linear_solver_ordering depeneds`` on
  680. the values of ``Solver::Options::linear_solver_ordering_type``,
  681. ``Solver::Options::linear_solver_type``,
  682. ``Solver::Options::preconditioner_type`` and
  683. ``Solver::Options::sparse_linear_algebra_type`` as we will explain
  684. below.
  685. Bundle Adjustment
  686. -----------------
  687. If the user is using one of the Schur solvers (DENSE_SCHUR,
  688. SPARSE_SCHUR, ITERATIVE_SCHUR) and chooses to specify an ordering, it
  689. must have one important property. The lowest numbered elimination
  690. group must form an independent set in the graph corresponding to the
  691. Hessian, or in other words, no two parameter blocks in the first
  692. elimination group should co-occur in the same residual block. For the
  693. best performance, this elimination group should be as large as
  694. possible. For standard bundle adjustment problems, this corresponds to
  695. the first elimination group containing all the 3d points, and the
  696. second containing the parameter blocks for all the cameras.
  697. If the user leaves the choice to Ceres, then the solver uses an
  698. approximate maximum independent set algorithm to identify the first
  699. elimination group [LiSaad]_.
  700. sparse_linear_algebra_library_type = SUITE_SPARSE
  701. -------------------------------------------------
  702. **linear_solver_ordering_type = AMD**
  703. A constrained Approximate Minimum Degree (CAMD) ordering used where
  704. the parameter blocks in the lowest numbered group are eliminated
  705. first, and then the parameter blocks in the next lowest numbered group
  706. and so on. Within each group, CAMD is free to order the parameter blocks
  707. as it chooses.
  708. **linear_solver_ordering_type = NESDIS**
  709. a. ``linear_solver_type = SPARSE_NORMAL_CHOLESKY`` or
  710. ``linear_solver_type = CGNR`` and ``preconditioner_type = SUBSET``
  711. The value of linear_solver_ordering is ignored and a Nested
  712. Dissection algorithm is used to compute a fill reducing ordering.
  713. b. ``linear_solver_type = SPARSE_SCHUR/DENSE_SCHUR/ITERATIVE_SCHUR``
  714. ONLY the lowest group are used to compute the Schur complement, and
  715. Nested Dissection is used to compute a fill reducing ordering for
  716. the Schur Complement (or its preconditioner).
  717. sparse_linear_algebra_library_type = EIGEN_SPARSE or ACCELERATE_SPARSE
  718. ----------------------------------------------------------------------
  719. a. ``linear_solver_type = SPARSE_NORMAL_CHOLESKY`` or
  720. ``linear_solver_type = CGNR`` and ``preconditioner_type = SUBSET``
  721. The value of linear_solver_ordering is ignored and ``AMD`` or
  722. ``NESDIS`` is used to compute a fill reducing ordering as requested
  723. by the user.
  724. b. ``linear_solver_type = SPARSE_SCHUR/DENSE_SCHUR/ITERATIVE_SCHUR``
  725. ONLY the lowest group are used to compute the Schur complement, and
  726. ``AMD`` or ``NESID`` is used to compute a fill reducing ordering
  727. for the Schur Complement (or its preconditioner).
  728. .. _section-solver-options:
  729. :class:`Solver::Options`
  730. ========================
  731. .. class:: Solver::Options
  732. :class:`Solver::Options` controls the overall behavior of the
  733. solver. We list the various settings and their default values below.
  734. .. function:: bool Solver::Options::IsValid(string* error) const
  735. Validate the values in the options struct and returns true on
  736. success. If there is a problem, the method returns false with
  737. ``error`` containing a textual description of the cause.
  738. .. member:: MinimizerType Solver::Options::minimizer_type
  739. Default: ``TRUST_REGION``
  740. Choose between ``LINE_SEARCH`` and ``TRUST_REGION`` algorithms. See
  741. :ref:`section-trust-region-methods` and
  742. :ref:`section-line-search-methods` for more details.
  743. .. member:: LineSearchDirectionType Solver::Options::line_search_direction_type
  744. Default: ``LBFGS``
  745. Choices are ``STEEPEST_DESCENT``, ``NONLINEAR_CONJUGATE_GRADIENT``,
  746. ``BFGS`` and ``LBFGS``.
  747. .. member:: LineSearchType Solver::Options::line_search_type
  748. Default: ``WOLFE``
  749. Choices are ``ARMIJO`` and ``WOLFE`` (strong Wolfe conditions).
  750. Note that in order for the assumptions underlying the ``BFGS`` and
  751. ``LBFGS`` line search direction algorithms to be guaranteed to be
  752. satisfied, the ``WOLFE`` line search should be used.
  753. .. member:: NonlinearConjugateGradientType Solver::Options::nonlinear_conjugate_gradient_type
  754. Default: ``FLETCHER_REEVES``
  755. Choices are ``FLETCHER_REEVES``, ``POLAK_RIBIERE`` and
  756. ``HESTENES_STIEFEL``.
  757. .. member:: int Solver::Options::max_lbfgs_rank
  758. Default: 20
  759. The L-BFGS hessian approximation is a low rank approximation to the
  760. inverse of the Hessian matrix. The rank of the approximation
  761. determines (linearly) the space and time complexity of using the
  762. approximation. Higher the rank, the better is the quality of the
  763. approximation. The increase in quality is however is bounded for a
  764. number of reasons.
  765. 1. The method only uses secant information and not actual
  766. derivatives.
  767. 2. The Hessian approximation is constrained to be positive
  768. definite.
  769. So increasing this rank to a large number will cost time and space
  770. complexity without the corresponding increase in solution
  771. quality. There are no hard and fast rules for choosing the maximum
  772. rank. The best choice usually requires some problem specific
  773. experimentation.
  774. .. member:: bool Solver::Options::use_approximate_eigenvalue_bfgs_scaling
  775. Default: ``false``
  776. As part of the ``BFGS`` update step / ``LBFGS`` right-multiply
  777. step, the initial inverse Hessian approximation is taken to be the
  778. Identity. However, [Oren]_ showed that using instead :math:`I *
  779. \gamma`, where :math:`\gamma` is a scalar chosen to approximate an
  780. eigenvalue of the true inverse Hessian can result in improved
  781. convergence in a wide variety of cases. Setting
  782. ``use_approximate_eigenvalue_bfgs_scaling`` to true enables this
  783. scaling in ``BFGS`` (before first iteration) and ``LBFGS`` (at each
  784. iteration).
  785. Precisely, approximate eigenvalue scaling equates to
  786. .. math:: \gamma = \frac{y_k' s_k}{y_k' y_k}
  787. With:
  788. .. math:: y_k = \nabla f_{k+1} - \nabla f_k
  789. .. math:: s_k = x_{k+1} - x_k
  790. Where :math:`f()` is the line search objective and :math:`x` the
  791. vector of parameter values [NocedalWright]_.
  792. It is important to note that approximate eigenvalue scaling does
  793. **not** *always* improve convergence, and that it can in fact
  794. *significantly* degrade performance for certain classes of problem,
  795. which is why it is disabled by default. In particular it can
  796. degrade performance when the sensitivity of the problem to different
  797. parameters varies significantly, as in this case a single scalar
  798. factor fails to capture this variation and detrimentally downscales
  799. parts of the Jacobian approximation which correspond to
  800. low-sensitivity parameters. It can also reduce the robustness of the
  801. solution to errors in the Jacobians.
  802. .. member:: LineSearchIterpolationType Solver::Options::line_search_interpolation_type
  803. Default: ``CUBIC``
  804. Degree of the polynomial used to approximate the objective
  805. function. Valid values are ``BISECTION``, ``QUADRATIC`` and
  806. ``CUBIC``.
  807. .. member:: double Solver::Options::min_line_search_step_size
  808. The line search terminates if:
  809. .. math:: \|\Delta x_k\|_\infty < \text{min_line_search_step_size}
  810. where :math:`\|\cdot\|_\infty` refers to the max norm, and
  811. :math:`\Delta x_k` is the step change in the parameter values at
  812. the :math:`k`-th iteration.
  813. .. member:: double Solver::Options::line_search_sufficient_function_decrease
  814. Default: ``1e-4``
  815. Solving the line search problem exactly is computationally
  816. prohibitive. Fortunately, line search based optimization algorithms
  817. can still guarantee convergence if instead of an exact solution,
  818. the line search algorithm returns a solution which decreases the
  819. value of the objective function sufficiently. More precisely, we
  820. are looking for a step size s.t.
  821. .. math:: f(\text{step_size}) \le f(0) + \text{sufficient_decrease} * [f'(0) * \text{step_size}]
  822. This condition is known as the Armijo condition.
  823. .. member:: double Solver::Options::max_line_search_step_contraction
  824. Default: ``1e-3``
  825. In each iteration of the line search,
  826. .. math:: \text{new_step_size} >= \text{max_line_search_step_contraction} * \text{step_size}
  827. Note that by definition, for contraction:
  828. .. math:: 0 < \text{max_step_contraction} < \text{min_step_contraction} < 1
  829. .. member:: double Solver::Options::min_line_search_step_contraction
  830. Default: ``0.6``
  831. In each iteration of the line search,
  832. .. math:: \text{new_step_size} <= \text{min_line_search_step_contraction} * \text{step_size}
  833. Note that by definition, for contraction:
  834. .. math:: 0 < \text{max_step_contraction} < \text{min_step_contraction} < 1
  835. .. member:: int Solver::Options::max_num_line_search_step_size_iterations
  836. Default: ``20``
  837. Maximum number of trial step size iterations during each line
  838. search, if a step size satisfying the search conditions cannot be
  839. found within this number of trials, the line search will stop.
  840. The minimum allowed value is 0 for trust region minimizer and 1
  841. otherwise. If 0 is specified for the trust region minimizer, then
  842. line search will not be used when solving constrained optimization
  843. problems.
  844. As this is an 'artificial' constraint (one imposed by the user, not
  845. the underlying math), if ``WOLFE`` line search is being used, *and*
  846. points satisfying the Armijo sufficient (function) decrease
  847. condition have been found during the current search (in :math:`<=`
  848. ``max_num_line_search_step_size_iterations``). Then, the step size
  849. with the lowest function value which satisfies the Armijo condition
  850. will be returned as the new valid step, even though it does *not*
  851. satisfy the strong Wolfe conditions. This behaviour protects
  852. against early termination of the optimizer at a sub-optimal point.
  853. .. member:: int Solver::Options::max_num_line_search_direction_restarts
  854. Default: ``5``
  855. Maximum number of restarts of the line search direction algorithm
  856. before terminating the optimization. Restarts of the line search
  857. direction algorithm occur when the current algorithm fails to
  858. produce a new descent direction. This typically indicates a
  859. numerical failure, or a breakdown in the validity of the
  860. approximations used.
  861. .. member:: double Solver::Options::line_search_sufficient_curvature_decrease
  862. Default: ``0.9``
  863. The strong Wolfe conditions consist of the Armijo sufficient
  864. decrease condition, and an additional requirement that the
  865. step size be chosen s.t. the *magnitude* ('strong' Wolfe
  866. conditions) of the gradient along the search direction
  867. decreases sufficiently. Precisely, this second condition
  868. is that we seek a step size s.t.
  869. .. math:: \|f'(\text{step_size})\| <= \text{sufficient_curvature_decrease} * \|f'(0)\|
  870. Where :math:`f()` is the line search objective and :math:`f'()` is the derivative
  871. of :math:`f` with respect to the step size: :math:`\frac{d f}{d~\text{step size}}`.
  872. .. member:: double Solver::Options::max_line_search_step_expansion
  873. Default: ``10.0``
  874. During the bracketing phase of a Wolfe line search, the step size
  875. is increased until either a point satisfying the Wolfe conditions
  876. is found, or an upper bound for a bracket containing a point
  877. satisfying the conditions is found. Precisely, at each iteration
  878. of the expansion:
  879. .. math:: \text{new_step_size} <= \text{max_step_expansion} * \text{step_size}
  880. By definition for expansion
  881. .. math:: \text{max_step_expansion} > 1.0
  882. .. member:: TrustRegionStrategyType Solver::Options::trust_region_strategy_type
  883. Default: ``LEVENBERG_MARQUARDT``
  884. The trust region step computation algorithm used by
  885. Ceres. Currently ``LEVENBERG_MARQUARDT`` and ``DOGLEG`` are the two
  886. valid choices. See :ref:`section-levenberg-marquardt` and
  887. :ref:`section-dogleg` for more details.
  888. .. member:: DoglegType Solver::Options::dogleg_type
  889. Default: ``TRADITIONAL_DOGLEG``
  890. Ceres supports two different dogleg strategies.
  891. ``TRADITIONAL_DOGLEG`` method by Powell and the ``SUBSPACE_DOGLEG``
  892. method described by [ByrdSchnabel]_ . See :ref:`section-dogleg`
  893. for more details.
  894. .. member:: bool Solver::Options::use_nonmonotonic_steps
  895. Default: ``false``
  896. Relax the requirement that the trust-region algorithm take strictly
  897. decreasing steps. See :ref:`section-non-monotonic-steps` for more
  898. details.
  899. .. member:: int Solver::Options::max_consecutive_nonmonotonic_steps
  900. Default: ``5``
  901. The window size used by the step selection algorithm to accept
  902. non-monotonic steps.
  903. .. member:: int Solver::Options::max_num_iterations
  904. Default: ``50``
  905. Maximum number of iterations for which the solver should run.
  906. .. member:: double Solver::Options::max_solver_time_in_seconds
  907. Default: ``1e6``
  908. Maximum amount of time for which the solver should run.
  909. .. member:: int Solver::Options::num_threads
  910. Default: ``1``
  911. Number of threads used by Ceres to evaluate the Jacobian.
  912. .. member:: double Solver::Options::initial_trust_region_radius
  913. Default: ``1e4``
  914. The size of the initial trust region. When the
  915. ``LEVENBERG_MARQUARDT`` strategy is used, the reciprocal of this
  916. number is the initial regularization parameter.
  917. .. member:: double Solver::Options::max_trust_region_radius
  918. Default: ``1e16``
  919. The trust region radius is not allowed to grow beyond this value.
  920. .. member:: double Solver::Options::min_trust_region_radius
  921. Default: ``1e-32``
  922. The solver terminates, when the trust region becomes smaller than
  923. this value.
  924. .. member:: double Solver::Options::min_relative_decrease
  925. Default: ``1e-3``
  926. Lower threshold for relative decrease before a trust-region step is
  927. accepted.
  928. .. member:: double Solver::Options::min_lm_diagonal
  929. Default: ``1e-6``
  930. The ``LEVENBERG_MARQUARDT`` strategy, uses a diagonal matrix to
  931. regularize the trust region step. This is the lower bound on
  932. the values of this diagonal matrix.
  933. .. member:: double Solver::Options::max_lm_diagonal
  934. Default: ``1e32``
  935. The ``LEVENBERG_MARQUARDT`` strategy, uses a diagonal matrix to
  936. regularize the trust region step. This is the upper bound on
  937. the values of this diagonal matrix.
  938. .. member:: int Solver::Options::max_num_consecutive_invalid_steps
  939. Default: ``5``
  940. The step returned by a trust region strategy can sometimes be
  941. numerically invalid, usually because of conditioning
  942. issues. Instead of crashing or stopping the optimization, the
  943. optimizer can go ahead and try solving with a smaller trust
  944. region/better conditioned problem. This parameter sets the number
  945. of consecutive retries before the minimizer gives up.
  946. .. member:: double Solver::Options::function_tolerance
  947. Default: ``1e-6``
  948. Solver terminates if
  949. .. math:: \frac{|\Delta \text{cost}|}{\text{cost}} <= \text{function_tolerance}
  950. where, :math:`\Delta \text{cost}` is the change in objective
  951. function value (up or down) in the current iteration of
  952. Levenberg-Marquardt.
  953. .. member:: double Solver::Options::gradient_tolerance
  954. Default: ``1e-10``
  955. Solver terminates if
  956. .. math:: \|x - \Pi \boxplus(x, -g(x))\|_\infty <= \text{gradient_tolerance}
  957. where :math:`\|\cdot\|_\infty` refers to the max norm, :math:`\Pi`
  958. is projection onto the bounds constraints and :math:`\boxplus` is
  959. Plus operation for the overall manifold associated with the
  960. parameter vector.
  961. .. member:: double Solver::Options::parameter_tolerance
  962. Default: ``1e-8``
  963. Solver terminates if
  964. .. math:: \|\Delta x\| <= (\|x\| + \text{parameter_tolerance}) * \text{parameter_tolerance}
  965. where :math:`\Delta x` is the step computed by the linear solver in
  966. the current iteration.
  967. .. member:: LinearSolverType Solver::Options::linear_solver_type
  968. Default: ``SPARSE_NORMAL_CHOLESKY`` / ``DENSE_QR``
  969. Type of linear solver used to compute the solution to the linear
  970. least squares problem in each iteration of the Levenberg-Marquardt
  971. algorithm. If Ceres is built with support for ``SuiteSparse`` or
  972. ``Accelerate`` or ``Eigen``'s sparse Cholesky factorization, the
  973. default is ``SPARSE_NORMAL_CHOLESKY``, it is ``DENSE_QR``
  974. otherwise.
  975. .. member:: PreconditionerType Solver::Options::preconditioner_type
  976. Default: ``JACOBI``
  977. The preconditioner used by the iterative linear solver. The default
  978. is the block Jacobi preconditioner. Valid values are (in increasing
  979. order of complexity) ``IDENTITY``, ``JACOBI``, ``SCHUR_JACOBI``,
  980. ``CLUSTER_JACOBI`` and ``CLUSTER_TRIDIAGONAL``. See
  981. :ref:`section-preconditioner` for more details.
  982. .. member:: VisibilityClusteringType Solver::Options::visibility_clustering_type
  983. Default: ``CANONICAL_VIEWS``
  984. Type of clustering algorithm to use when constructing a visibility
  985. based preconditioner. The original visibility based preconditioning
  986. paper and implementation only used the canonical views algorithm.
  987. This algorithm gives high quality results but for large dense
  988. graphs can be particularly expensive. As its worst case complexity
  989. is cubic in size of the graph.
  990. Another option is to use ``SINGLE_LINKAGE`` which is a simple
  991. thresholded single linkage clustering algorithm that only pays
  992. attention to tightly coupled blocks in the Schur complement. This
  993. is a fast algorithm that works well.
  994. The optimal choice of the clustering algorithm depends on the
  995. sparsity structure of the problem, but generally speaking we
  996. recommend that you try ``CANONICAL_VIEWS`` first and if it is too
  997. expensive try ``SINGLE_LINKAGE``.
  998. .. member:: std::unordered_set<ResidualBlockId> residual_blocks_for_subset_preconditioner
  999. ``SUBSET`` preconditioner is a preconditioner for problems with
  1000. general sparsity. Given a subset of residual blocks of a problem,
  1001. it uses the corresponding subset of the rows of the Jacobian to
  1002. construct a preconditioner.
  1003. Suppose the Jacobian :math:`J` has been horizontally partitioned as
  1004. .. math:: J = \begin{bmatrix} P \\ Q \end{bmatrix}
  1005. Where, :math:`Q` is the set of rows corresponding to the residual
  1006. blocks in
  1007. :member:`Solver::Options::residual_blocks_for_subset_preconditioner`. The
  1008. preconditioner is the matrix :math:`(Q^\top Q)^{-1}`.
  1009. The efficacy of the preconditioner depends on how well the matrix
  1010. :math:`Q` approximates :math:`J^\top J`, or how well the chosen
  1011. residual blocks approximate the full problem.
  1012. If ``Solver::Options::preconditioner_type == SUBSET``, then
  1013. ``residual_blocks_for_subset_preconditioner`` must be non-empty.
  1014. .. member:: DenseLinearAlgebraLibrary Solver::Options::dense_linear_algebra_library_type
  1015. Default:``EIGEN``
  1016. Ceres supports using multiple dense linear algebra libraries for
  1017. dense matrix factorizations. Currently ``EIGEN``, ``LAPACK`` and
  1018. ``CUDA`` are the valid choices. ``EIGEN`` is always available,
  1019. ``LAPACK`` refers to the system ``BLAS + LAPACK`` library which may
  1020. or may not be available. ``CUDA`` refers to Nvidia's GPU based
  1021. dense linear algebra library which may or may not be available.
  1022. This setting affects the ``DENSE_QR``, ``DENSE_NORMAL_CHOLESKY``
  1023. and ``DENSE_SCHUR`` solvers. For small to moderate sized problem
  1024. ``EIGEN`` is a fine choice but for large problems, an optimized
  1025. ``LAPACK + BLAS`` or ``CUDA`` implementation can make a substantial
  1026. difference in performance.
  1027. .. member:: SparseLinearAlgebraLibrary Solver::Options::sparse_linear_algebra_library_type
  1028. Default: The highest available according to: ``SUITE_SPARSE`` >
  1029. ``ACCELERATE_SPARSE`` > ``EIGEN_SPARSE`` > ``NO_SPARSE``
  1030. Ceres supports the use of three sparse linear algebra libraries,
  1031. ``SuiteSparse``, which is enabled by setting this parameter to
  1032. ``SUITE_SPARSE``, ``Acclerate``, which can be selected by setting
  1033. this parameter to ``ACCELERATE_SPARSE`` and ``Eigen`` which is
  1034. enabled by setting this parameter to ``EIGEN_SPARSE``. Lastly,
  1035. ``NO_SPARSE`` means that no sparse linear solver should be used;
  1036. note that this is irrespective of whether Ceres was compiled with
  1037. support for one.
  1038. ``SuiteSparse`` is a sophisticated sparse linear algebra library
  1039. and should be used in general. On MacOS you may want to use the
  1040. ``Accelerate`` framework.
  1041. If your needs/platforms prevent you from using ``SuiteSparse``,
  1042. consider using the sparse linear algebra routines in ``Eigen``. The
  1043. sparse Cholesky algorithms currently included with ``Eigen`` are
  1044. not as sophisticated as the ones in ``SuiteSparse`` and
  1045. ``Accelerate`` and as a result its performance is considerably
  1046. worse.
  1047. .. member:: LinearSolverOrderingType Solver::Options::linear_solver_ordering_type
  1048. Default: ``AMD``
  1049. The order in which variables are eliminated in a linear solver can
  1050. have a significant impact on the efficiency and accuracy of the
  1051. method. e.g., when doing sparse Cholesky factorization, there are
  1052. matrices for which a good ordering will give a Cholesky factor
  1053. with :math:`O(n)` storage, where as a bad ordering will result in
  1054. an completely dense factor.
  1055. Sparse direct solvers like ``SPARSE_NORMAL_CHOLESKY`` and
  1056. ``SPARSE_SCHUR`` use a fill reducing ordering of the columns and
  1057. rows of the matrix being factorized before computing the numeric
  1058. factorization.
  1059. This enum controls the type of algorithm used to compute this fill
  1060. reducing ordering. There is no single algorithm that works on all
  1061. matrices, so determining which algorithm works better is a matter
  1062. of empirical experimentation.
  1063. .. member:: shared_ptr<ParameterBlockOrdering> Solver::Options::linear_solver_ordering
  1064. Default: ``nullptr``
  1065. An instance of the ordering object informs the solver about the
  1066. desired order in which parameter blocks should be eliminated by the
  1067. linear solvers.
  1068. If ``nullptr``, the solver is free to choose an ordering that it
  1069. thinks is best.
  1070. See :ref:`section-ordering` for more details.
  1071. .. member:: bool Solver::Options::use_explicit_schur_complement
  1072. Default: ``false``
  1073. Use an explicitly computed Schur complement matrix with
  1074. ``ITERATIVE_SCHUR``.
  1075. By default this option is disabled and ``ITERATIVE_SCHUR``
  1076. evaluates evaluates matrix-vector products between the Schur
  1077. complement and a vector implicitly by exploiting the algebraic
  1078. expression for the Schur complement.
  1079. The cost of this evaluation scales with the number of non-zeros in
  1080. the Jacobian.
  1081. For small to medium sized problems there is a sweet spot where
  1082. computing the Schur complement is cheap enough that it is much more
  1083. efficient to explicitly compute it and use it for evaluating the
  1084. matrix-vector products.
  1085. Enabling this option tells ``ITERATIVE_SCHUR`` to use an explicitly
  1086. computed Schur complement. This can improve the performance of the
  1087. ``ITERATIVE_SCHUR`` solver significantly.
  1088. .. NOTE::
  1089. This option can only be used with the ``SCHUR_JACOBI``
  1090. preconditioner.
  1091. .. member:: bool Solver::Options::dynamic_sparsity
  1092. Some non-linear least squares problems are symbolically dense but
  1093. numerically sparse. i.e. at any given state only a small number of
  1094. Jacobian entries are non-zero, but the position and number of
  1095. non-zeros is different depending on the state. For these problems
  1096. it can be useful to factorize the sparse jacobian at each solver
  1097. iteration instead of including all of the zero entries in a single
  1098. general factorization.
  1099. If your problem does not have this property (or you do not know),
  1100. then it is probably best to keep this false, otherwise it will
  1101. likely lead to worse performance.
  1102. This setting only affects the `SPARSE_NORMAL_CHOLESKY` solver.
  1103. .. member:: bool Solver::Options::use_mixed_precision_solves
  1104. Default: ``false``
  1105. .. NOTE::
  1106. This feature is EXPERIMENTAL and under development, use at your
  1107. own risk!
  1108. If true, the Gauss-Newton matrix is computed in *double* precision, but
  1109. its factorization is computed in **single** precision. This can result in
  1110. significant time and memory savings at the cost of some accuracy in the
  1111. Gauss-Newton step. Iterative refinement is used to recover some
  1112. of this accuracy back.
  1113. If ``use_mixed_precision_solves`` is true, we recommend setting
  1114. ``max_num_refinement_iterations`` to 2-3.
  1115. This option is currently only available if
  1116. ``sparse_linear_algebra_library_type`` is ``EIGEN_SPARSE`` or
  1117. ``ACCELERATE_SPARSE``, and ``linear_solver_type`` is
  1118. ``SPARSE_NORMAL_CHOLESKY`` or ``SPARSE_SCHUR``.
  1119. .. member:: int Solver::Options::max_num_refinement_iterations
  1120. Default: ``0``
  1121. Number steps of the iterative refinement process to run when
  1122. computing the Gauss-Newton step, see ``use_mixed_precision_solves``.
  1123. .. member:: int Solver::Options::min_linear_solver_iterations
  1124. Default: ``0``
  1125. Minimum number of iterations used by the linear solver. This only
  1126. makes sense when the linear solver is an iterative solver, e.g.,
  1127. ``ITERATIVE_SCHUR`` or ``CGNR``.
  1128. .. member:: int Solver::Options::max_linear_solver_iterations
  1129. Default: ``500``
  1130. Minimum number of iterations used by the linear solver. This only
  1131. makes sense when the linear solver is an iterative solver, e.g.,
  1132. ``ITERATIVE_SCHUR`` or ``CGNR``.
  1133. .. member:: double Solver::Options::eta
  1134. Default: ``1e-1``
  1135. Forcing sequence parameter. The truncated Newton solver uses this
  1136. number to control the relative accuracy with which the Newton step
  1137. is computed. This constant is passed to
  1138. ``ConjugateGradientsSolver`` which uses it to terminate the
  1139. iterations when
  1140. .. math:: \frac{Q_i - Q_{i-1}}{Q_i} < \frac{\eta}{i}
  1141. .. member:: bool Solver::Options::jacobi_scaling
  1142. Default: ``true``
  1143. ``true`` means that the Jacobian is scaled by the norm of its
  1144. columns before being passed to the linear solver. This improves the
  1145. numerical conditioning of the normal equations.
  1146. .. member:: bool Solver::Options::use_inner_iterations
  1147. Default: ``false``
  1148. Use a non-linear version of a simplified variable projection
  1149. algorithm. Essentially this amounts to doing a further optimization
  1150. on each Newton/Trust region step using a coordinate descent
  1151. algorithm. For more details, see :ref:`section-inner-iterations`.
  1152. **Note** Inner iterations cannot be used with :class:`Problem`
  1153. objects that have an :class:`EvaluationCallback` associated with
  1154. them.
  1155. .. member:: double Solver::Options::inner_iteration_tolerance
  1156. Default: ``1e-3``
  1157. Generally speaking, inner iterations make significant progress in
  1158. the early stages of the solve and then their contribution drops
  1159. down sharply, at which point the time spent doing inner iterations
  1160. is not worth it.
  1161. Once the relative decrease in the objective function due to inner
  1162. iterations drops below ``inner_iteration_tolerance``, the use of
  1163. inner iterations in subsequent trust region minimizer iterations is
  1164. disabled.
  1165. .. member:: shared_ptr<ParameterBlockOrdering> Solver::Options::inner_iteration_ordering
  1166. Default: ``nullptr``
  1167. If :member:`Solver::Options::use_inner_iterations` true, then the
  1168. user has two choices.
  1169. 1. Let the solver heuristically decide which parameter blocks to
  1170. optimize in each inner iteration. To do this, set
  1171. :member:`Solver::Options::inner_iteration_ordering` to ``nullptr``.
  1172. 2. Specify a collection of of ordered independent sets. The lower
  1173. numbered groups are optimized before the higher number groups
  1174. during the inner optimization phase. Each group must be an
  1175. independent set. Not all parameter blocks need to be included in
  1176. the ordering.
  1177. See :ref:`section-ordering` for more details.
  1178. .. member:: LoggingType Solver::Options::logging_type
  1179. Default: ``PER_MINIMIZER_ITERATION``
  1180. .. member:: bool Solver::Options::minimizer_progress_to_stdout
  1181. Default: ``false``
  1182. By default the :class:`Minimizer` progress is logged to ``STDERR``
  1183. depending on the ``vlog`` level. If this flag is set to true, and
  1184. :member:`Solver::Options::logging_type` is not ``SILENT``, the logging
  1185. output is sent to ``STDOUT``.
  1186. For ``TRUST_REGION_MINIMIZER`` the progress display looks like
  1187. .. code-block:: bash
  1188. iter cost cost_change |gradient| |step| tr_ratio tr_radius ls_iter iter_time total_time
  1189. 0 4.185660e+06 0.00e+00 1.09e+08 0.00e+00 0.00e+00 1.00e+04 0 7.59e-02 3.37e-01
  1190. 1 1.062590e+05 4.08e+06 8.99e+06 5.36e+02 9.82e-01 3.00e+04 1 1.65e-01 5.03e-01
  1191. 2 4.992817e+04 5.63e+04 8.32e+06 3.19e+02 6.52e-01 3.09e+04 1 1.45e-01 6.48e-01
  1192. Here
  1193. #. ``cost`` is the value of the objective function.
  1194. #. ``cost_change`` is the change in the value of the objective
  1195. function if the step computed in this iteration is accepted.
  1196. #. ``|gradient|`` is the max norm of the gradient.
  1197. #. ``|step|`` is the change in the parameter vector.
  1198. #. ``tr_ratio`` is the ratio of the actual change in the objective
  1199. function value to the change in the value of the trust
  1200. region model.
  1201. #. ``tr_radius`` is the size of the trust region radius.
  1202. #. ``ls_iter`` is the number of linear solver iterations used to
  1203. compute the trust region step. For direct/factorization based
  1204. solvers it is always 1, for iterative solvers like
  1205. ``ITERATIVE_SCHUR`` it is the number of iterations of the
  1206. Conjugate Gradients algorithm.
  1207. #. ``iter_time`` is the time take by the current iteration.
  1208. #. ``total_time`` is the total time taken by the minimizer.
  1209. For ``LINE_SEARCH_MINIMIZER`` the progress display looks like
  1210. .. code-block:: bash
  1211. 0: f: 2.317806e+05 d: 0.00e+00 g: 3.19e-01 h: 0.00e+00 s: 0.00e+00 e: 0 it: 2.98e-02 tt: 8.50e-02
  1212. 1: f: 2.312019e+05 d: 5.79e+02 g: 3.18e-01 h: 2.41e+01 s: 1.00e+00 e: 1 it: 4.54e-02 tt: 1.31e-01
  1213. 2: f: 2.300462e+05 d: 1.16e+03 g: 3.17e-01 h: 4.90e+01 s: 2.54e-03 e: 1 it: 4.96e-02 tt: 1.81e-01
  1214. Here
  1215. #. ``f`` is the value of the objective function.
  1216. #. ``d`` is the change in the value of the objective function if
  1217. the step computed in this iteration is accepted.
  1218. #. ``g`` is the max norm of the gradient.
  1219. #. ``h`` is the change in the parameter vector.
  1220. #. ``s`` is the optimal step length computed by the line search.
  1221. #. ``it`` is the time take by the current iteration.
  1222. #. ``tt`` is the total time taken by the minimizer.
  1223. .. member:: vector<int> Solver::Options::trust_region_minimizer_iterations_to_dump
  1224. Default: ``empty``
  1225. List of iterations at which the trust region minimizer should dump
  1226. the trust region problem. Useful for testing and benchmarking. If
  1227. ``empty``, no problems are dumped.
  1228. .. member:: string Solver::Options::trust_region_problem_dump_directory
  1229. Default: ``/tmp``
  1230. Directory to which the problems should be written to. Should be
  1231. non-empty if
  1232. :member:`Solver::Options::trust_region_minimizer_iterations_to_dump` is
  1233. non-empty and
  1234. :member:`Solver::Options::trust_region_problem_dump_format_type` is not
  1235. ``CONSOLE``.
  1236. .. member:: DumpFormatType Solver::Options::trust_region_problem_dump_format
  1237. Default: ``TEXTFILE``
  1238. The format in which trust region problems should be logged when
  1239. :member:`Solver::Options::trust_region_minimizer_iterations_to_dump`
  1240. is non-empty. There are three options:
  1241. * ``CONSOLE`` prints the linear least squares problem in a human
  1242. readable format to ``stderr``. The Jacobian is printed as a
  1243. dense matrix. The vectors :math:`D`, :math:`x` and :math:`f` are
  1244. printed as dense vectors. This should only be used for small
  1245. problems.
  1246. * ``TEXTFILE`` Write out the linear least squares problem to the
  1247. directory pointed to by
  1248. :member:`Solver::Options::trust_region_problem_dump_directory` as
  1249. text files which can be read into ``MATLAB/Octave``. The Jacobian
  1250. is dumped as a text file containing :math:`(i,j,s)` triplets, the
  1251. vectors :math:`D`, `x` and `f` are dumped as text files
  1252. containing a list of their values.
  1253. A ``MATLAB/Octave`` script called
  1254. ``ceres_solver_iteration_???.m`` is also output, which can be
  1255. used to parse and load the problem into memory.
  1256. .. member:: bool Solver::Options::check_gradients
  1257. Default: ``false``
  1258. Check all Jacobians computed by each residual block with finite
  1259. differences. This is expensive since it involves computing the
  1260. derivative by normal means (e.g. user specified, autodiff, etc),
  1261. then also computing it using finite differences. The results are
  1262. compared, and if they differ substantially, the optimization fails
  1263. and the details are stored in the solver summary.
  1264. .. member:: double Solver::Options::gradient_check_relative_precision
  1265. Default: ``1e-8``
  1266. Precision to check for in the gradient checker. If the relative
  1267. difference between an element in a Jacobian exceeds this number,
  1268. then the Jacobian for that cost term is dumped.
  1269. .. member:: double Solver::Options::gradient_check_numeric_derivative_relative_step_size
  1270. Default: ``1e-6``
  1271. .. NOTE::
  1272. This option only applies to the numeric differentiation used for
  1273. checking the user provided derivatives when when
  1274. `Solver::Options::check_gradients` is true. If you are using
  1275. :class:`NumericDiffCostFunction` and are interested in changing
  1276. the step size for numeric differentiation in your cost function,
  1277. please have a look at :class:`NumericDiffOptions`.
  1278. Relative shift used for taking numeric derivatives when
  1279. `Solver::Options::check_gradients` is `true`.
  1280. For finite differencing, each dimension is evaluated at slightly
  1281. shifted values, e.g., for forward differences, the numerical
  1282. derivative is
  1283. .. math::
  1284. \delta &= gradient\_check\_numeric\_derivative\_relative\_step\_size\\
  1285. \Delta f &= \frac{f((1 + \delta) x) - f(x)}{\delta x}
  1286. The finite differencing is done along each dimension. The reason to
  1287. use a relative (rather than absolute) step size is that this way,
  1288. numeric differentiation works for functions where the arguments are
  1289. typically large (e.g. :math:`10^9`) and when the values are small
  1290. (e.g. :math:`10^{-5}`). It is possible to construct *torture cases*
  1291. which break this finite difference heuristic, but they do not come
  1292. up often in practice.
  1293. .. member:: bool Solver::Options::update_state_every_iteration
  1294. Default: ``false``
  1295. If ``update_state_every_iteration`` is ``true``, then Ceres Solver
  1296. will guarantee that at the end of every iteration and before any
  1297. user :class:`IterationCallback` is called, the parameter blocks are
  1298. updated to the current best solution found by the solver. Thus the
  1299. IterationCallback can inspect the values of the parameter blocks
  1300. for purposes of computation, visualization or termination.
  1301. If ``update_state_every_iteration`` is ``false`` then there is no
  1302. such guarantee, and user provided :class:`IterationCallback` s
  1303. should not expect to look at the parameter blocks and interpret
  1304. their values.
  1305. .. member:: vector<IterationCallback> Solver::Options::callbacks
  1306. Callbacks that are executed at the end of each iteration of the
  1307. :class:`Minimizer`. They are executed in the order that they are
  1308. specified in this vector.
  1309. By default, parameter blocks are updated only at the end of the
  1310. optimization, i.e., when the :class:`Minimizer` terminates. This
  1311. means that by default, if an :class:`IterationCallback` inspects
  1312. the parameter blocks, they will not see them changing in the course
  1313. of the optimization.
  1314. To tell Ceres to update the parameter blocks at the end of each
  1315. iteration and before calling the user's callback, set
  1316. :member:`Solver::Options::update_state_every_iteration` to
  1317. ``true``.
  1318. The solver does NOT take ownership of these pointers.
  1319. :class:`ParameterBlockOrdering`
  1320. ===============================
  1321. .. class:: ParameterBlockOrdering
  1322. ``ParameterBlockOrdering`` is a class for storing and manipulating
  1323. an ordered collection of groups/sets with the following semantics:
  1324. Group IDs are non-negative integer values. Elements are any type
  1325. that can serve as a key in a map or an element of a set.
  1326. An element can only belong to one group at a time. A group may
  1327. contain an arbitrary number of elements.
  1328. Groups are ordered by their group id.
  1329. .. function:: bool ParameterBlockOrdering::AddElementToGroup(const double* element, const int group)
  1330. Add an element to a group. If a group with this id does not exist,
  1331. one is created. This method can be called any number of times for
  1332. the same element. Group ids should be non-negative numbers. Return
  1333. value indicates if adding the element was a success.
  1334. .. function:: void ParameterBlockOrdering::Clear()
  1335. Clear the ordering.
  1336. .. function:: bool ParameterBlockOrdering::Remove(const double* element)
  1337. Remove the element, no matter what group it is in. If the element
  1338. is not a member of any group, calling this method will result in a
  1339. crash. Return value indicates if the element was actually removed.
  1340. .. function:: void ParameterBlockOrdering::Reverse()
  1341. Reverse the order of the groups in place.
  1342. .. function:: int ParameterBlockOrdering::GroupId(const double* element) const
  1343. Return the group id for the element. If the element is not a member
  1344. of any group, return -1.
  1345. .. function:: bool ParameterBlockOrdering::IsMember(const double* element) const
  1346. True if there is a group containing the parameter block.
  1347. .. function:: int ParameterBlockOrdering::GroupSize(const int group) const
  1348. This function always succeeds, i.e., implicitly there exists a
  1349. group for every integer.
  1350. .. function:: int ParameterBlockOrdering::NumElements() const
  1351. Number of elements in the ordering.
  1352. .. function:: int ParameterBlockOrdering::NumGroups() const
  1353. Number of groups with one or more elements.
  1354. :class:`IterationSummary`
  1355. ==========================
  1356. .. class:: IterationSummary
  1357. :class:`IterationSummary` describes the state of the minimizer at
  1358. the end of each iteration.
  1359. .. member:: int IterationSummary::iteration
  1360. Current iteration number.
  1361. .. member:: bool IterationSummary::step_is_valid
  1362. Step was numerically valid, i.e., all values are finite and the
  1363. step reduces the value of the linearized model.
  1364. **Note**: :member:`IterationSummary::step_is_valid` is `false`
  1365. when :member:`IterationSummary::iteration` = 0.
  1366. .. member:: bool IterationSummary::step_is_nonmonotonic
  1367. Step did not reduce the value of the objective function
  1368. sufficiently, but it was accepted because of the relaxed
  1369. acceptance criterion used by the non-monotonic trust region
  1370. algorithm.
  1371. **Note**: :member:`IterationSummary::step_is_nonmonotonic` is
  1372. `false` when when :member:`IterationSummary::iteration` = 0.
  1373. .. member:: bool IterationSummary::step_is_successful
  1374. Whether or not the minimizer accepted this step or not.
  1375. If the ordinary trust region algorithm is used, this means that the
  1376. relative reduction in the objective function value was greater than
  1377. :member:`Solver::Options::min_relative_decrease`. However, if the
  1378. non-monotonic trust region algorithm is used
  1379. (:member:`Solver::Options::use_nonmonotonic_steps` = `true`), then
  1380. even if the relative decrease is not sufficient, the algorithm may
  1381. accept the step and the step is declared successful.
  1382. **Note**: :member:`IterationSummary::step_is_successful` is `false`
  1383. when when :member:`IterationSummary::iteration` = 0.
  1384. .. member:: double IterationSummary::cost
  1385. Value of the objective function.
  1386. .. member:: double IterationSummary::cost_change
  1387. Change in the value of the objective function in this
  1388. iteration. This can be positive or negative.
  1389. .. member:: double IterationSummary::gradient_max_norm
  1390. Infinity norm of the gradient vector.
  1391. .. member:: double IterationSummary::gradient_norm
  1392. 2-norm of the gradient vector.
  1393. .. member:: double IterationSummary::step_norm
  1394. 2-norm of the size of the step computed in this iteration.
  1395. .. member:: double IterationSummary::relative_decrease
  1396. For trust region algorithms, the ratio of the actual change in cost
  1397. and the change in the cost of the linearized approximation.
  1398. This field is not used when a linear search minimizer is used.
  1399. .. member:: double IterationSummary::trust_region_radius
  1400. Size of the trust region at the end of the current iteration. For
  1401. the Levenberg-Marquardt algorithm, the regularization parameter is
  1402. 1.0 / :member:`IterationSummary::trust_region_radius`.
  1403. .. member:: double IterationSummary::eta
  1404. For the inexact step Levenberg-Marquardt algorithm, this is the
  1405. relative accuracy with which the step is solved. This number is
  1406. only applicable to the iterative solvers capable of solving linear
  1407. systems inexactly. Factorization-based exact solvers always have an
  1408. eta of 0.0.
  1409. .. member:: double IterationSummary::step_size
  1410. Step sized computed by the line search algorithm.
  1411. This field is not used when a trust region minimizer is used.
  1412. .. member:: int IterationSummary::line_search_function_evaluations
  1413. Number of function evaluations used by the line search algorithm.
  1414. This field is not used when a trust region minimizer is used.
  1415. .. member:: int IterationSummary::linear_solver_iterations
  1416. Number of iterations taken by the linear solver to solve for the
  1417. trust region step.
  1418. Currently this field is not used when a line search minimizer is
  1419. used.
  1420. .. member:: double IterationSummary::iteration_time_in_seconds
  1421. Time (in seconds) spent inside the minimizer loop in the current
  1422. iteration.
  1423. .. member:: double IterationSummary::step_solver_time_in_seconds
  1424. Time (in seconds) spent inside the trust region step solver.
  1425. .. member:: double IterationSummary::cumulative_time_in_seconds
  1426. Time (in seconds) since the user called Solve().
  1427. :class:`IterationCallback`
  1428. ==========================
  1429. .. class:: IterationCallback
  1430. Interface for specifying callbacks that are executed at the end of
  1431. each iteration of the minimizer.
  1432. .. code-block:: c++
  1433. class IterationCallback {
  1434. public:
  1435. virtual ~IterationCallback() {}
  1436. virtual CallbackReturnType operator()(const IterationSummary& summary) = 0;
  1437. };
  1438. The solver uses the return value of ``operator()`` to decide whether
  1439. to continue solving or to terminate. The user can return three
  1440. values.
  1441. #. ``SOLVER_ABORT`` indicates that the callback detected an abnormal
  1442. situation. The solver returns without updating the parameter
  1443. blocks (unless ``Solver::Options::update_state_every_iteration`` is
  1444. set true). Solver returns with ``Solver::Summary::termination_type``
  1445. set to ``USER_FAILURE``.
  1446. #. ``SOLVER_TERMINATE_SUCCESSFULLY`` indicates that there is no need
  1447. to optimize anymore (some user specified termination criterion
  1448. has been met). Solver returns with
  1449. ``Solver::Summary::termination_type``` set to ``USER_SUCCESS``.
  1450. #. ``SOLVER_CONTINUE`` indicates that the solver should continue
  1451. optimizing.
  1452. For example, the following :class:`IterationCallback` is used
  1453. internally by Ceres to log the progress of the optimization.
  1454. .. code-block:: c++
  1455. class LoggingCallback : public IterationCallback {
  1456. public:
  1457. explicit LoggingCallback(bool log_to_stdout)
  1458. : log_to_stdout_(log_to_stdout) {}
  1459. ~LoggingCallback() {}
  1460. CallbackReturnType operator()(const IterationSummary& summary) {
  1461. const char* kReportRowFormat =
  1462. "% 4d: f:% 8e d:% 3.2e g:% 3.2e h:% 3.2e "
  1463. "rho:% 3.2e mu:% 3.2e eta:% 3.2e li:% 3d";
  1464. string output = StringPrintf(kReportRowFormat,
  1465. summary.iteration,
  1466. summary.cost,
  1467. summary.cost_change,
  1468. summary.gradient_max_norm,
  1469. summary.step_norm,
  1470. summary.relative_decrease,
  1471. summary.trust_region_radius,
  1472. summary.eta,
  1473. summary.linear_solver_iterations);
  1474. if (log_to_stdout_) {
  1475. cout << output << endl;
  1476. } else {
  1477. VLOG(1) << output;
  1478. }
  1479. return SOLVER_CONTINUE;
  1480. }
  1481. private:
  1482. const bool log_to_stdout_;
  1483. };
  1484. :class:`CRSMatrix`
  1485. ==================
  1486. .. class:: CRSMatrix
  1487. A compressed row sparse matrix used primarily for communicating the
  1488. Jacobian matrix to the user.
  1489. .. member:: int CRSMatrix::num_rows
  1490. Number of rows.
  1491. .. member:: int CRSMatrix::num_cols
  1492. Number of columns.
  1493. .. member:: vector<int> CRSMatrix::rows
  1494. :member:`CRSMatrix::rows` is a :member:`CRSMatrix::num_rows` + 1
  1495. sized array that points into the :member:`CRSMatrix::cols` and
  1496. :member:`CRSMatrix::values` array.
  1497. .. member:: vector<int> CRSMatrix::cols
  1498. :member:`CRSMatrix::cols` contain as many entries as there are
  1499. non-zeros in the matrix.
  1500. For each row ``i``, ``cols[rows[i]]`` ... ``cols[rows[i + 1] - 1]``
  1501. are the indices of the non-zero columns of row ``i``.
  1502. .. member:: vector<int> CRSMatrix::values
  1503. :member:`CRSMatrix::values` contain as many entries as there are
  1504. non-zeros in the matrix.
  1505. For each row ``i``,
  1506. ``values[rows[i]]`` ... ``values[rows[i + 1] - 1]`` are the values
  1507. of the non-zero columns of row ``i``.
  1508. e.g., consider the 3x4 sparse matrix
  1509. .. code-block:: c++
  1510. 0 10 0 4
  1511. 0 2 -3 2
  1512. 1 2 0 0
  1513. The three arrays will be:
  1514. .. code-block:: c++
  1515. -row0- ---row1--- -row2-
  1516. rows = [ 0, 2, 5, 7]
  1517. cols = [ 1, 3, 1, 2, 3, 0, 1]
  1518. values = [10, 4, 2, -3, 2, 1, 2]
  1519. :class:`Solver::Summary`
  1520. ========================
  1521. .. class:: Solver::Summary
  1522. Summary of the various stages of the solver after termination.
  1523. .. function:: string Solver::Summary::BriefReport() const
  1524. A brief one line description of the state of the solver after
  1525. termination.
  1526. .. function:: string Solver::Summary::FullReport() const
  1527. A full multiline description of the state of the solver after
  1528. termination.
  1529. .. function:: bool Solver::Summary::IsSolutionUsable() const
  1530. Whether the solution returned by the optimization algorithm can be
  1531. relied on to be numerically sane. This will be the case if
  1532. `Solver::Summary:termination_type` is set to `CONVERGENCE`,
  1533. `USER_SUCCESS` or `NO_CONVERGENCE`, i.e., either the solver
  1534. converged by meeting one of the convergence tolerances or because
  1535. the user indicated that it had converged or it ran to the maximum
  1536. number of iterations or time.
  1537. .. member:: MinimizerType Solver::Summary::minimizer_type
  1538. Type of minimization algorithm used.
  1539. .. member:: TerminationType Solver::Summary::termination_type
  1540. The cause of the minimizer terminating.
  1541. .. member:: string Solver::Summary::message
  1542. Reason why the solver terminated.
  1543. .. member:: double Solver::Summary::initial_cost
  1544. Cost of the problem (value of the objective function) before the
  1545. optimization.
  1546. .. member:: double Solver::Summary::final_cost
  1547. Cost of the problem (value of the objective function) after the
  1548. optimization.
  1549. .. member:: double Solver::Summary::fixed_cost
  1550. The part of the total cost that comes from residual blocks that
  1551. were held fixed by the preprocessor because all the parameter
  1552. blocks that they depend on were fixed.
  1553. .. member:: vector<IterationSummary> Solver::Summary::iterations
  1554. :class:`IterationSummary` for each minimizer iteration in order.
  1555. .. member:: int Solver::Summary::num_successful_steps
  1556. Number of minimizer iterations in which the step was
  1557. accepted. Unless :member:`Solver::Options::use_non_monotonic_steps`
  1558. is `true` this is also the number of steps in which the objective
  1559. function value/cost went down.
  1560. .. member:: int Solver::Summary::num_unsuccessful_steps
  1561. Number of minimizer iterations in which the step was rejected
  1562. either because it did not reduce the cost enough or the step was
  1563. not numerically valid.
  1564. .. member:: int Solver::Summary::num_inner_iteration_steps
  1565. Number of times inner iterations were performed.
  1566. .. member:: int Solver::Summary::num_line_search_steps
  1567. Total number of iterations inside the line search algorithm across
  1568. all invocations. We call these iterations "steps" to distinguish
  1569. them from the outer iterations of the line search and trust region
  1570. minimizer algorithms which call the line search algorithm as a
  1571. subroutine.
  1572. .. member:: double Solver::Summary::preprocessor_time_in_seconds
  1573. Time (in seconds) spent in the preprocessor.
  1574. .. member:: double Solver::Summary::minimizer_time_in_seconds
  1575. Time (in seconds) spent in the Minimizer.
  1576. .. member:: double Solver::Summary::postprocessor_time_in_seconds
  1577. Time (in seconds) spent in the post processor.
  1578. .. member:: double Solver::Summary::total_time_in_seconds
  1579. Time (in seconds) spent in the solver.
  1580. .. member:: double Solver::Summary::linear_solver_time_in_seconds
  1581. Time (in seconds) spent in the linear solver computing the trust
  1582. region step.
  1583. .. member:: int Solver::Summary::num_linear_solves
  1584. Number of times the Newton step was computed by solving a linear
  1585. system. This does not include linear solves used by inner
  1586. iterations.
  1587. .. member:: double Solver::Summary::residual_evaluation_time_in_seconds
  1588. Time (in seconds) spent evaluating the residual vector.
  1589. .. member:: int Solver::Summary::num_residual_evaluations
  1590. Number of times only the residuals were evaluated.
  1591. .. member:: double Solver::Summary::jacobian_evaluation_time_in_seconds
  1592. Time (in seconds) spent evaluating the Jacobian matrix.
  1593. .. member:: int Solver::Summary::num_jacobian_evaluations
  1594. Number of times only the Jacobian and the residuals were evaluated.
  1595. .. member:: double Solver::Summary::inner_iteration_time_in_seconds
  1596. Time (in seconds) spent doing inner iterations.
  1597. .. member:: int Solver::Summary::num_parameter_blocks
  1598. Number of parameter blocks in the problem.
  1599. .. member:: int Solver::Summary::num_parameters
  1600. Number of parameters in the problem.
  1601. .. member:: int Solver::Summary::num_effective_parameters
  1602. Dimension of the tangent space of the problem (or the number of
  1603. columns in the Jacobian for the problem). This is different from
  1604. :member:`Solver::Summary::num_parameters` if a parameter block is
  1605. associated with a :class:`Manifold`.
  1606. .. member:: int Solver::Summary::num_residual_blocks
  1607. Number of residual blocks in the problem.
  1608. .. member:: int Solver::Summary::num_residuals
  1609. Number of residuals in the problem.
  1610. .. member:: int Solver::Summary::num_parameter_blocks_reduced
  1611. Number of parameter blocks in the problem after the inactive and
  1612. constant parameter blocks have been removed. A parameter block is
  1613. inactive if no residual block refers to it.
  1614. .. member:: int Solver::Summary::num_parameters_reduced
  1615. Number of parameters in the reduced problem.
  1616. .. member:: int Solver::Summary::num_effective_parameters_reduced
  1617. Dimension of the tangent space of the reduced problem (or the
  1618. number of columns in the Jacobian for the reduced problem). This is
  1619. different from :member:`Solver::Summary::num_parameters_reduced` if
  1620. a parameter block in the reduced problem is associated with a
  1621. :class:`Manifold`.
  1622. .. member:: int Solver::Summary::num_residual_blocks_reduced
  1623. Number of residual blocks in the reduced problem.
  1624. .. member:: int Solver::Summary::num_residuals_reduced
  1625. Number of residuals in the reduced problem.
  1626. .. member:: int Solver::Summary::num_threads_given
  1627. Number of threads specified by the user for Jacobian and residual
  1628. evaluation.
  1629. .. member:: int Solver::Summary::num_threads_used
  1630. Number of threads actually used by the solver for Jacobian and
  1631. residual evaluation.
  1632. .. member:: LinearSolverType Solver::Summary::linear_solver_type_given
  1633. Type of the linear solver requested by the user.
  1634. .. member:: LinearSolverType Solver::Summary::linear_solver_type_used
  1635. Type of the linear solver actually used. This may be different from
  1636. :member:`Solver::Summary::linear_solver_type_given` if Ceres
  1637. determines that the problem structure is not compatible with the
  1638. linear solver requested or if the linear solver requested by the
  1639. user is not available, e.g. The user requested
  1640. `SPARSE_NORMAL_CHOLESKY` but no sparse linear algebra library was
  1641. available.
  1642. .. member:: vector<int> Solver::Summary::linear_solver_ordering_given
  1643. Size of the elimination groups given by the user as hints to the
  1644. linear solver.
  1645. .. member:: vector<int> Solver::Summary::linear_solver_ordering_used
  1646. Size of the parameter groups used by the solver when ordering the
  1647. columns of the Jacobian. This maybe different from
  1648. :member:`Solver::Summary::linear_solver_ordering_given` if the user
  1649. left :member:`Solver::Summary::linear_solver_ordering_given` blank
  1650. and asked for an automatic ordering, or if the problem contains
  1651. some constant or inactive parameter blocks.
  1652. .. member:: std::string Solver::Summary::schur_structure_given
  1653. For Schur type linear solvers, this string describes the template
  1654. specialization which was detected in the problem and should be
  1655. used.
  1656. .. member:: std::string Solver::Summary::schur_structure_used
  1657. For Schur type linear solvers, this string describes the template
  1658. specialization that was actually instantiated and used. The reason
  1659. this will be different from
  1660. :member:`Solver::Summary::schur_structure_given` is because the
  1661. corresponding template specialization does not exist.
  1662. Template specializations can be added to ceres by editing
  1663. ``internal/ceres/generate_template_specializations.py``
  1664. .. member:: bool Solver::Summary::inner_iterations_given
  1665. `True` if the user asked for inner iterations to be used as part of
  1666. the optimization.
  1667. .. member:: bool Solver::Summary::inner_iterations_used
  1668. `True` if the user asked for inner iterations to be used as part of
  1669. the optimization and the problem structure was such that they were
  1670. actually performed. For example, in a problem with just one parameter
  1671. block, inner iterations are not performed.
  1672. .. member:: vector<int> inner_iteration_ordering_given
  1673. Size of the parameter groups given by the user for performing inner
  1674. iterations.
  1675. .. member:: vector<int> inner_iteration_ordering_used
  1676. Size of the parameter groups given used by the solver for
  1677. performing inner iterations. This maybe different from
  1678. :member:`Solver::Summary::inner_iteration_ordering_given` if the
  1679. user left :member:`Solver::Summary::inner_iteration_ordering_given`
  1680. blank and asked for an automatic ordering, or if the problem
  1681. contains some constant or inactive parameter blocks.
  1682. .. member:: PreconditionerType Solver::Summary::preconditioner_type_given
  1683. Type of the preconditioner requested by the user.
  1684. .. member:: PreconditionerType Solver::Summary::preconditioner_type_used
  1685. Type of the preconditioner actually used. This may be different
  1686. from :member:`Solver::Summary::linear_solver_type_given` if Ceres
  1687. determines that the problem structure is not compatible with the
  1688. linear solver requested or if the linear solver requested by the
  1689. user is not available.
  1690. .. member:: VisibilityClusteringType Solver::Summary::visibility_clustering_type
  1691. Type of clustering algorithm used for visibility based
  1692. preconditioning. Only meaningful when the
  1693. :member:`Solver::Summary::preconditioner_type` is
  1694. ``CLUSTER_JACOBI`` or ``CLUSTER_TRIDIAGONAL``.
  1695. .. member:: TrustRegionStrategyType Solver::Summary::trust_region_strategy_type
  1696. Type of trust region strategy.
  1697. .. member:: DoglegType Solver::Summary::dogleg_type
  1698. Type of dogleg strategy used for solving the trust region problem.
  1699. .. member:: DenseLinearAlgebraLibraryType Solver::Summary::dense_linear_algebra_library_type
  1700. Type of the dense linear algebra library used.
  1701. .. member:: SparseLinearAlgebraLibraryType Solver::Summary::sparse_linear_algebra_library_type
  1702. Type of the sparse linear algebra library used.
  1703. .. member:: LineSearchDirectionType Solver::Summary::line_search_direction_type
  1704. Type of line search direction used.
  1705. .. member:: LineSearchType Solver::Summary::line_search_type
  1706. Type of the line search algorithm used.
  1707. .. member:: LineSearchInterpolationType Solver::Summary::line_search_interpolation_type
  1708. When performing line search, the degree of the polynomial used to
  1709. approximate the objective function.
  1710. .. member:: NonlinearConjugateGradientType Solver::Summary::nonlinear_conjugate_gradient_type
  1711. If the line search direction is `NONLINEAR_CONJUGATE_GRADIENT`,
  1712. then this indicates the particular variant of non-linear conjugate
  1713. gradient used.
  1714. .. member:: int Solver::Summary::max_lbfgs_rank
  1715. If the type of the line search direction is `LBFGS`, then this
  1716. indicates the rank of the Hessian approximation.