blob: 8398c7f1b1c954884edc03017f12967cec8ffbca [file] [log] [blame]
Sameer Agarwal8ed29a72012-06-07 17:04:25 -07001%!TEX root = ceres-solver.tex
Sameer Agarwald3eaa482012-05-29 23:47:57 -07002\chapter{Solving}
Sameer Agarwal97fb6d92012-06-17 10:08:19 -07003Effective use of Ceres requires some familiarity with the basic components of a nonlinear least squares solver, so before we describe how to configure the solver, we will begin by taking a brief look at how some of the core optimization algorithms in Ceres work and the various linear solvers and preconditioners that power it.
Sameer Agarwald3eaa482012-05-29 23:47:57 -07004
Sameer Agarwal97fb6d92012-06-17 10:08:19 -07005\section{Trust Region Methods}
Sameer Agarwal122cf832012-08-24 16:28:27 -07006\label{sec:trust-region}
Sameer Agarwald3eaa482012-05-29 23:47:57 -07007Let $x \in \mathbb{R}^{n}$ be an $n$-dimensional vector of variables, and
8$ F(x) = \left[f_1(x), \hdots, f_{m}(x) \right]^{\top}$ be a $m$-dimensional function of $x$. We are interested in solving the following optimization problem~\footnote{At the level of the non-linear solver, the block and residual structure is not relevant, therefore our discussion here is in terms of an optimization problem defined over a state vector of size $n$.},
9\begin{equation}
10 \arg \min_x \frac{1}{2}\|F(x)\|^2\ .
11 \label{eq:nonlinsq}
12\end{equation}
Sameer Agarwal97fb6d92012-06-17 10:08:19 -070013Here, the Jacobian $J(x)$ of $F(x)$ is an $m\times n$ matrix, where $J_{ij}(x) = \partial_j f_i(x)$ and the gradient vector $g(x) = \nabla \frac{1}{2}\|F(x)\|^2 = J(x)^\top F(x)$. Since the efficient global optimization of~\eqref{eq:nonlinsq} for general $F(x)$ is an intractable problem, we will have to settle for finding a local minimum.
Sameer Agarwald3eaa482012-05-29 23:47:57 -070014
15The general strategy when solving non-linear optimization problems is to solve a sequence of approximations to the original problem~\cite{nocedal2000numerical}. At each iteration, the approximation is solved to determine a correction $\Delta x$ to the vector $x$. For non-linear least squares, an approximation can be constructed by using the linearization $F(x+\Delta x) \approx F(x) + J(x)\Delta x$, which leads to the following linear least squares problem:
16\begin{equation}
17 \min_{\Delta x} \frac{1}{2}\|J(x)\Delta x + F(x)\|^2
18 \label{eq:linearapprox}
19\end{equation}
Sameer Agarwal122cf832012-08-24 16:28:27 -070020Unfortunately, na\"ively solving a sequence of these problems and
21updating $x \leftarrow x+ \Delta x$ leads to an algorithm that may not
22converge. To get a convergent algorithm, we need to control the size
23of the step $\Delta x$. And this is where the idea of a trust-region
24comes in. Algorithm~\ref{alg:trust-region} describes the basic trust-region loop for non-linear least squares problems.
Sameer Agarwald3eaa482012-05-29 23:47:57 -070025
Sameer Agarwal122cf832012-08-24 16:28:27 -070026\begin{algorithm}
27\caption{The basic trust-region algorithm.\label{alg:trust-region}}
Sameer Agarwal97fb6d92012-06-17 10:08:19 -070028\begin{algorithmic}
29\REQUIRE Initial point $x$ and a trust region radius $\mu$.
30\LOOP
31\STATE{Solve $\arg \min_{\Delta x} \frac{1}{2}\|J(x)\Delta x + F(x)\|^2$ s.t. $\|D(x)\Delta x\|^2 \le \mu$}
32\STATE{$\rho = \frac{\displaystyle \|F(x + \Delta x)\|^2 - \|F(x)\|^2}{\displaystyle \|J(x)\Delta x + F(x)\|^2 - \|F(x)\|^2}$}
33\IF {$\rho > \epsilon$}
34\STATE{$x = x + \Delta x$}
35\ENDIF
36\IF {$\rho > \eta_1$}
37\STATE{$\rho = 2 * \rho$}
38\ELSE
39\IF {$\rho < \eta_2$}
40\STATE {$\rho = 0.5 * \rho$}
41\ENDIF
42\ENDIF
43\ENDLOOP
44\end{algorithmic}
Sameer Agarwal122cf832012-08-24 16:28:27 -070045\end{algorithm}
Sameer Agarwal97fb6d92012-06-17 10:08:19 -070046
47Here, $\mu$ is the trust region radius, $D(x)$ is some matrix used to define a metric on the domain of $F(x)$ and $\rho$ measures the quality of the step $\Delta x$, i.e., how well did the linear model predict the decrease in the value of the non-linear objective. The idea is to increase or decrease the radius of the trust region depending on how well the linearization predicts the behavior of the non-linear objective, which in turn is reflected in the value of $\rho$.
48
49The key computational step in a trust-region algorithm is the solution of the constrained optimization problem
50\begin{align}
51 \arg\min_{\Delta x}& \frac{1}{2}\|J(x)\Delta x + F(x)\|^2 \\
52 \text{such that}&\quad \|D(x)\Delta x\|^2 \le \mu
53\label{eq:trp}
54\end{align}
55
Sameer Agarwal122cf832012-08-24 16:28:27 -070056There are a number of different ways of solving this problem, each giving rise to a different concrete trust-region algorithm. Currently Ceres, implements two trust-region algorithms - Levenberg-Marquardt and Dogleg.
Sameer Agarwal97fb6d92012-06-17 10:08:19 -070057
58\subsection{Levenberg-Marquardt}
59The Levenberg-Marquardt algorithm~\cite{levenberg1944method, marquardt1963algorithm} is the most popular algorithm for solving non-linear least squares problems. It was also the first trust region algorithm to be developed~\cite{levenberg1944method,marquardt1963algorithm}. Ceres implements an exact step~\cite{madsen2004methods} and an inexact step variant of the Levenberg-Marquardt algorithm~\cite{wright1985inexact,nash1990assessing}.
60
61It can be shown, that the solution to~\eqref{eq:trp} can be obtained by solving an unconstrained optimization of the form
62\begin{align}
63 \arg\min_{\Delta x}& \frac{1}{2}\|J(x)\Delta x + F(x)\|^2 +\lambda \|D(x)\Delta x\|^2
64\end{align}
65Where, $\lambda$ is a Lagrange multiplier that is inverse related to $\mu$. In Ceres, we solve for
66\begin{align}
67 \arg\min_{\Delta x}& \frac{1}{2}\|J(x)\Delta x + F(x)\|^2 + \frac{1}{\mu} \|D(x)\Delta x\|^2
68\label{eq:lsqr}
69\end{align}
70The matrix $D(x)$ is a non-negative diagonal matrix, typically the square root of the diagonal of the matrix $J(x)^\top J(x)$.
Sameer Agarwald3eaa482012-05-29 23:47:57 -070071
72Before going further, let us make some notational simplifications. We will assume that the matrix $\sqrt{\mu} D$ has been concatenated at the bottom of the matrix $J$ and similarly a vector of zeros has been added to the bottom of the vector $f$ and the rest of our discussion will be in terms of $J$ and $f$, \ie the linear least squares problem.
73\begin{align}
74 \min_{\Delta x} \frac{1}{2} \|J(x)\Delta x + f(x)\|^2 .
75 \label{eq:simple}
76\end{align}
77For all but the smallest problems the solution of~\eqref{eq:simple} in each iteration of the Levenberg-Marquardt algorithm is the dominant computational cost in Ceres. Ceres provides a number of different options for solving~\eqref{eq:simple}. There are two major classes of methods - factorization and iterative.
78
79The factorization methods are based on computing an exact solution of~\eqref{eq:lsqr} using a Cholesky or a QR factorization and lead to an exact step Levenberg-Marquardt algorithm. But it is not clear if an exact solution of~\eqref{eq:lsqr} is necessary at each step of the LM algorithm to solve~\eqref{eq:nonlinsq}. In fact, we have already seen evidence that this may not be the case, as~\eqref{eq:lsqr} is itself a regularized version of~\eqref{eq:linearapprox}. Indeed, it is possible to construct non-linear optimization algorithms in which the linearized problem is solved approximately. These algorithms are known as inexact Newton or truncated Newton methods~\cite{nocedal2000numerical}.
80
81An inexact Newton method requires two ingredients. First, a cheap method for approximately solving systems of linear equations. Typically an iterative linear solver like the Conjugate Gradients method is used for this purpose~\cite{nocedal2000numerical}. Second, a termination rule for the iterative solver. A typical termination rule is of the form
82\begin{equation}
83 \|H(x) \Delta x + g(x)\| \leq \eta_k \|g(x)\|. \label{eq:inexact}
84\end{equation}
85Here, $k$ indicates the Levenberg-Marquardt iteration number and $0 < \eta_k <1$ is known as the forcing sequence. Wright \& Holt \cite{wright1985inexact} prove that a truncated Levenberg-Marquardt algorithm that uses an inexact Newton step based on~\eqref{eq:inexact} converges for any sequence $\eta_k \leq \eta_0 < 1$ and the rate of convergence depends on the choice of the forcing sequence $\eta_k$.
86
Sameer Agarwal97fb6d92012-06-17 10:08:19 -070087Ceres supports both exact and inexact step solution strategies. When the user chooses a factorization based linear solver, the exact step Levenberg-Marquardt algorithm is used. When the user chooses an iterative linear solver, the inexact step Levenberg-Marquardt algorithm is used.
88
Sameer Agarwal122cf832012-08-24 16:28:27 -070089\subsection{Dogleg}
90\label{sec:dogleg}
Sameer Agarwal97fb6d92012-06-17 10:08:19 -070091Another strategy for solving the trust region problem~\eqref{eq:trp} was introduced by M. J. D. Powell. The key idea there is to compute two vectors
92\begin{align}
93 \Delta x^{\text{Gauss-Newton}} &= \arg \min_{\Delta x}\frac{1}{2} \|J(x)\Delta x + f(x)\|^2.\\
94 \Delta x^{\text{Cauchy}} &= -\frac{\|g(x)\|^2}{\|J(x)g(x)\|^2}g(x).
95\end{align}
Sameer Agarwal122cf832012-08-24 16:28:27 -070096Note that the vector $\Delta x^{\text{Gauss-Newton}}$ is the solution
97to~\eqref{eq:linearapprox} and $\Delta x^{\text{Cauchy}}$ is the
98vector that minimizes the linear approximation if we restrict
99ourselves to moving along the direction of the gradient. Dogleg methods finds a vector $\Delta x$ defined by $\Delta
100x^{\text{Gauss-Newton}}$ and $\Delta x^{\text{Cauchy}}$ that solves
101the trust region problem. Ceres supports two
102variants.
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700103
Sameer Agarwal122cf832012-08-24 16:28:27 -0700104\texttt{TRADITIONAL\_DOGLEG} as described by Powell,
105constructs two line segments using the Gauss-Newton and Cauchy vectors
106and finds the point farthest along this line shaped like a dogleg
107(hence the name) that is contained in the
108trust-region. For more details on the exact reasoning and computations, please see Madsen et al~\cite{madsen2004methods}.
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700109
Sameer Agarwal122cf832012-08-24 16:28:27 -0700110 \texttt{SUBSPACE\_DOGLEG} is a more sophisticated method
111that considers the entire two dimensional subspace spanned by these
112two vectors and finds the point that minimizes the trust region
113problem in this subspace\cite{byrd1988approximate}.
114
115The key advantage of the Dogleg over Levenberg Marquardt is that if the step computation for a particular choice of $\mu$ does not result in sufficient decrease in the value of the objective function, Levenberg-Marquardt solves the linear approximation from scratch with a smaller value of $\mu$. Dogleg on the other hand, only needs to compute the interpolation between the Gauss-Newton and the Cauchy vectors, as neither of them depend on the value of $\mu$.
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700116
117The Dogleg method can only be used with the exact factorization based linear solvers.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700118
Sameer Agarwal122cf832012-08-24 16:28:27 -0700119\subsection{Non-monotonic Steps}
120\label{sec:non-monotic}
121Note that the basic trust-region algorithm described in
122Algorithm~\ref{alg:trust-region} is a descent algorithm in that they
123only accepts a point if it strictly reduces the value of the objective
124function.
125
126Relaxing this requirement allows the algorithm to be more
127efficient in the long term at the cost of some local increase
128in the value of the objective function.
129
130This is because allowing for non-decreasing objective function
131values in a princpled manner allows the algorithm to ``jump over
132boulders'' as the method is not restricted to move into narrow
133valleys while preserving its convergence properties.
134
135Setting \texttt{Solver::Options::use\_nonmonotonic\_steps} to \texttt{true}
136enables the non-monotonic trust region algorithm as described by
137Conn, Gould \& Toint in~\cite{conn2000trust}.
138
139Even though the value of the objective function may be larger
140than the minimum value encountered over the course of the
141optimization, the final parameters returned to the user are the
142ones corresponding to the minimum cost over all iterations.
143
144The option to take non-monotonic is available for all trust region
145strategies.
146
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700147\section{\texttt{LinearSolver}}
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700148Recall that in both of the trust-region methods described above, the key computational cost is the solution of a linear least squares problem of the form
149\begin{align}
150 \min_{\Delta x} \frac{1}{2} \|J(x)\Delta x + f(x)\|^2 .
151 \label{eq:simple2}
152\end{align}
153
154
155Let $H(x)= J(x)^\top J(x)$ and $g(x) = -J(x)^\top f(x)$. For notational convenience let us also drop the dependence on $x$. Then it is easy to see that solving~\eqref{eq:simple2} is equivalent to solving the {\em normal equations}
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700156\begin{align}
157H \Delta x &= g \label{eq:normal}
158\end{align}
159
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700160Ceres provides a number of different options for solving~\eqref{eq:normal}.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700161
162\subsection{\texttt{DENSE\_QR}}
163For small problems (a couple of hundred parameters and a few thousand residuals) with relatively dense Jacobians, \texttt{DENSE\_QR} is the method of choice~\cite{bjorck1996numerical}. Let $J = QR$ be the QR-decomposition of $J$, where $Q$ is an orthonormal matrix and $R$ is an upper triangular matrix~\cite{trefethen1997numerical}. Then it can be shown that the solution to~\eqref{eq:normal} is given by
164\begin{align}
Sameer Agarwal8ed29a72012-06-07 17:04:25 -0700165 \Delta x^* = -R^{-1}Q^\top f
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700166\end{align}
Sameer Agarwal122cf832012-08-24 16:28:27 -0700167Ceres uses \texttt{Eigen}'s dense QR factorization routines.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700168
Sameer Agarwal122cf832012-08-24 16:28:27 -0700169\subsection{\texttt{DENSE\_NORMAL\_CHOLESKY} \& \texttt{SPARSE\_NORMAL\_CHOLESKY}}
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700170Large non-linear least square problems are usually sparse. In such cases, using a dense QR factorization is inefficient. Let $H = R^\top R$ be the Cholesky factorization of the normal equations, where $R$ is an upper triangular matrix, then the solution to ~\eqref{eq:normal} is given by
171\begin{equation}
Sameer Agarwal8ed29a72012-06-07 17:04:25 -0700172 \Delta x^* = R^{-1} R^{-\top} g.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700173\end{equation}
Sameer Agarwal122cf832012-08-24 16:28:27 -0700174The observant reader will note that the $R$ in the Cholesky
175factorization of $H$ is the same upper triangular matrix $R$ in the QR
176factorization of $J$. Since $Q$ is an orthonormal matrix, $J=QR$
177implies that $J^\top J = R^\top Q^\top Q R = R^\top R$. There are two variants of Cholesky factorization -- sparse and
178dense.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700179
Sameer Agarwal122cf832012-08-24 16:28:27 -0700180\texttt{DENSE\_NORMAL\_CHOLESKY} as the name implies performs a dense
181Cholesky factorization of the normal equations. Ceres uses
182\texttt{Eigen}'s dense LDLT factorization routines.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700183
Sameer Agarwal122cf832012-08-24 16:28:27 -0700184\texttt{SPARSE\_NORMAL\_CHOLESKY}, as the name implies performs a
185sparse Cholesky factorization of the normal equations. This leads to
186substantial savings in time and memory for large sparse
187problems. Ceres uses the sparse Cholesky factorization routines in Professor Tim Davis' \texttt{SuiteSparse} or
188\texttt{CXSparse} packages~\cite{chen2006acs}.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700189
190\subsection{\texttt{DENSE\_SCHUR} \& \texttt{SPARSE\_SCHUR}}
191While it is possible to use \texttt{SPARSE\_NORMAL\_CHOLESKY} to solve bundle adjustment problems, bundle adjustment problem have a special structure, and a more efficient scheme for solving~\eqref{eq:normal} can be constructed.
192
193Suppose that the SfM problem consists of $p$ cameras and $q$ points and the variable vector $x$ has the block structure $x = [y_{1},\hdots,y_{p},z_{1},\hdots,z_{q}]$. Where, $y$ and $z$ correspond to camera and point parameters, respectively. Further, let the camera blocks be of size $c$ and the point blocks be of size $s$ (for most problems $c$ = $6$--$9$ and $s = 3$). Ceres does not impose any constancy requirement on these block sizes, but choosing them to be constant simplifies the exposition.
194
195A key characteristic of the bundle adjustment problem is that there is no term $f_{i}$ that includes two or more point blocks. This in turn implies that the matrix $H$ is of the form
196\begin{equation}
197 H = \left[
198 \begin{matrix} B & E\\ E^\top & C
199 \end{matrix}
200 \right]\ ,
201\label{eq:hblock}
202\end{equation}
203where, $B \in \reals^{pc\times pc}$ is a block sparse matrix with $p$ blocks of size $c\times c$ and $C \in \reals^{qs\times qs}$ is a block diagonal matrix with $q$ blocks of size $s\times s$. $E \in \reals^{pc\times qs}$ is a general block sparse matrix, with a block of size $c\times s$ for each observation. Let us now block partition $\Delta x = [\Delta y,\Delta z]$ and $g=[v,w]$ to restate~\eqref{eq:normal} as the block structured linear system
204\begin{equation}
205 \left[
206 \begin{matrix} B & E\\ E^\top & C
207 \end{matrix}
208 \right]\left[
209 \begin{matrix} \Delta y \\ \Delta z
210 \end{matrix}
211 \right]
212 =
213 \left[
214 \begin{matrix} v\\ w
215 \end{matrix}
216 \right]\ ,
217\label{eq:linear2}
218\end{equation}
219and apply Gaussian elimination to it. As we noted above, $C$ is a block diagonal matrix, with small diagonal blocks of size $s\times s$.
220Thus, calculating the inverse of $C$ by inverting each of these blocks is cheap. This allows us to eliminate $\Delta z$ by observing that $\Delta z = C^{-1}(w - E^\top \Delta y)$, giving us
221\begin{equation}
222 \left[B - EC^{-1}E^\top\right] \Delta y = v - EC^{-1}w\ . \label{eq:schur}
223\end{equation}
224The matrix
225\begin{equation}
226S = B - EC^{-1}E^\top\ ,
227\end{equation}
228is the Schur complement of $C$ in $H$. It is also known as the {\em reduced camera matrix}, because the only variables participating in~\eqref{eq:schur} are the ones corresponding to the cameras. $S \in \reals^{pc\times pc}$ is a block structured symmetric positive definite matrix, with blocks of size $c\times c$. The block $S_{ij}$ corresponding to the pair of images $i$ and $j$ is non-zero if and only if the two images observe at least one common point.
229
230Now, \eqref{eq:linear2}~can be solved by first forming $S$, solving for $\Delta y$, and then back-substituting $\Delta y$ to obtain the value of $\Delta z$.
231Thus, the solution of what was an $n\times n$, $n=pc+qs$ linear system is reduced to the inversion of the block diagonal matrix $C$, a few matrix-matrix and matrix-vector multiplies, and the solution of block sparse $pc\times pc$ linear system~\eqref{eq:schur}. For almost all problems, the number of cameras is much smaller than the number of points, $p \ll q$, thus solving~\eqref{eq:schur} is significantly cheaper than solving~\eqref{eq:linear2}. This is the {\em Schur complement trick}~\cite{brown-58}.
232
233This still leaves open the question of solving~\eqref{eq:schur}. The
234method of choice for solving symmetric positive definite systems
235exactly is via the Cholesky
236factorization~\cite{trefethen1997numerical} and depending upon the
237structure of the matrix, there are, in general, two options. The first
238is direct factorization, where we store and factor $S$ as a dense
239matrix~\cite{trefethen1997numerical}. This method has $O(p^2)$ space complexity and $O(p^3)$ time
240complexity and is only practical for problems with up to a few hundred
241cameras. Ceres implements this strategy as the \texttt{DENSE\_SCHUR} solver.
242
243
244 But, $S$ is typically a fairly sparse matrix, as most images
245only see a small fraction of the scene. This leads us to the second
246option: sparse direct methods. These methods store $S$ as a sparse
247matrix, use row and column re-ordering algorithms to maximize the
248sparsity of the Cholesky decomposition, and focus their compute effort
249on the non-zero part of the factorization~\cite{chen2006acs}.
250Sparse direct methods, depending on the exact sparsity structure of the Schur complement,
251allow bundle adjustment algorithms to significantly scale up over those based on dense
252factorization. Ceres implements this strategy as the \texttt{SPARSE\_SCHUR} solver.
253
254\subsection{\texttt{CGNR}}
255For general sparse problems, if the problem is too large for \texttt{CHOLMOD} or a sparse linear algebra library is not linked into Ceres, another option is the \texttt{CGNR} solver. This solver uses the Conjugate Gradients solver on the {\em normal equations}, but without forming the normal equations explicitly. It exploits the relation
256\begin{align}
Sameer Agarwal8ed29a72012-06-07 17:04:25 -0700257 H x = J^\top J x = J^\top(J x)
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700258\end{align}
259When the user chooses \texttt{ITERATIVE\_SCHUR} as the linear solver, Ceres automatically switches from the exact step algorithm to an inexact step algorithm.
260
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700261%Currently only the \texttt{JACOBI} preconditioner is available for use with this solver. It uses the block diagonal of $H$ as a preconditioner.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700262
263
264\subsection{\texttt{ITERATIVE\_SCHUR}}
265Another option for bundle adjustment problems is to apply PCG to the reduced camera matrix $S$ instead of $H$. One reason to do this is that $S$ is a much smaller matrix than $H$, but more importantly, it can be shown that $\kappa(S)\leq \kappa(H)$. Ceres implements PCG on $S$ as the \texttt{ITERATIVE\_SCHUR} solver. When the user chooses \texttt{ITERATIVE\_SCHUR} as the linear solver, Ceres automatically switches from the exact step algorithm to an inexact step algorithm.
266
267The cost of forming and storing the Schur complement $S$ can be prohibitive for large problems. Indeed, for an inexact Newton solver that computes $S$ and runs PCG on it, almost all of its time is spent in constructing $S$; the time spent inside the PCG algorithm is negligible in comparison. Because PCG only needs access to $S$ via its product with a vector, one way to evaluate $Sx$ is to observe that
268\begin{align}
269 x_1 &= E^\top x \notag \\
270 x_2 &= C^{-1} x_1 \notag\\
271 x_3 &= Ex_2 \notag\\
272 x_4 &= Bx \notag\\
273 Sx &= x_4 - x_3\ .\label{eq:schurtrick1}
274\end{align}
275Thus, we can run PCG on $S$ with the same computational effort per iteration as PCG on $H$, while reaping the benefits of a more powerful preconditioner. In fact, we do not even need to compute $H$, \eqref{eq:schurtrick1} can be implemented using just the columns of $J$.
276
277Equation~\eqref{eq:schurtrick1} is closely related to {\em Domain Decomposition methods} for solving large linear systems that arise in structural engineering and partial differential equations. In the language of Domain Decomposition, each point in a bundle adjustment problem is a domain, and the cameras form the interface between these domains. The iterative solution of the Schur complement then falls within the sub-category of techniques known as Iterative Sub-structuring~\cite{saad2003iterative,mathew2008domain}.
278
279\section{Preconditioner}
280The convergence rate of Conjugate Gradients for solving~\eqref{eq:normal} depends on the distribution of eigenvalues of $H$~\cite{saad2003iterative}. A useful upper bound is $\sqrt{\kappa(H)}$, where, $\kappa(H)$f is the condition number of the matrix $H$. For most bundle adjustment problems, $\kappa(H)$ is high and a direct application of Conjugate Gradients to~\eqref{eq:normal} results in extremely poor performance.
281
282The solution to this problem is to replace~\eqref{eq:normal} with a {\em preconditioned} system. Given a linear system, $Ax =b$ and a preconditioner $M$ the preconditioned system is given by $M^{-1}Ax = M^{-1}b$. The resulting algorithm is known as Preconditioned Conjugate Gradients algorithm (PCG) and its worst case complexity now depends on the condition number of the {\em preconditioned} matrix $\kappa(M^{-1}A)$.
283
284The computational cost of using a preconditioner $M$ is the cost of computing $M$ and evaluating the product $M^{-1}y$ for arbitrary vectors $y$. Thus, there are two competing factors to consider: How much of $H$'s structure is captured by $M$ so that the condition number $\kappa(HM^{-1})$ is low, and the computational cost of constructing and using $M$. The ideal preconditioner would be one for which $\kappa(M^{-1}A) =1$. $M=A$ achieves this, but it is not a practical choice, as applying this preconditioner would require solving a linear system equivalent to the unpreconditioned problem. It is usually the case that the more information $M$ has about $H$, the more expensive it is use. For example, Incomplete Cholesky factorization based preconditioners have much better convergence behavior than the Jacobi preconditioner, but are also much more expensive.
285
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700286
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700287The simplest of all preconditioners is the diagonal or Jacobi preconditioner, \ie, $M=\operatorname{diag}(A)$, which for block structured matrices like $H$ can be generalized to the block Jacobi preconditioner.
288
289For \texttt{ITERATIVE\_SCHUR} there are two obvious choices for block diagonal preconditioners for $S$. The block diagonal of the matrix $B$~\cite{mandel1990block} and the block diagonal $S$, \ie the block Jacobi preconditioner for $S$. Ceres's implements both of these preconditioners and refers to them as \texttt{JACOBI} and \texttt{SCHUR\_JACOBI} respectively.
290
291For bundle adjustment problems arising in reconstruction from community photo collections, more effective preconditioners can be constructed by analyzing and exploiting the camera-point visibility structure of the scene~\cite{kushal2012}. Ceres implements the two visibility based preconditioners described by Kushal \& Agarwal as \texttt{CLUSTER\_JACOBI} and \texttt{CLUSTER\_TRIDIAGONAL}. These are fairly new preconditioners and Ceres' implementation of them is in its early stages and is not as mature as the other preconditioners described above.
292
293\section{Ordering}
Sameer Agarwal65625f72012-09-17 12:06:57 -0700294TBD - re-write this section once the ordering API is complete.
295
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700296All three of the Schur based solvers depend on the user indicating to the solver, which of the parameter blocks correspond to the points and which correspond to the cameras. Ceres refers to them as \texttt{e\_block}s and \texttt{f\_blocks}. The only constraint on \texttt{e\_block}s is that there should be no term in the objective function with two or more \texttt{e\_block}s.
297
298As we saw in Section~\ref{chapter:tutorial:bundleadjustment}, there are two ways to indicate \texttt{e\_block}s to Ceres. The first is to explicitly create an ordering vector \texttt{Solver::Options::ordering} containing the parameter blocks such that all the \texttt{e\_block}s/points occur before the \texttt{f\_blocks}, and setting \texttt{Solver::Options::num\_eliminate\_blocks} to the number \texttt{e\_block}s.
299
300For some problems this is an easy thing to do and we recommend its use. In some problems though, this is onerous and it would be better if Ceres could automatically determine \texttt{e\_block}s. Setting \texttt{Solver::Options::ordering\_type} to \texttt{SCHUR} achieves this.
301
302The \texttt{SCHUR} ordering algorithm is based on the observation that
303the constraint that no two \texttt{e\_block} co-occur in a residual
304block means that if we were to treat the sparsity structure of the
305block matrix $H$ as a graph, then the set of \texttt{e\_block}s is an
306independent set in this graph. The larger the number of
307\texttt{e\_block}, the smaller is the size of the Schur complement $S$. Indeed the reason Schur based solvers are so efficient at solving bundle adjustment problems is because the number of points in a bundle adjustment problem is usually an order of magnitude or two larger than the number of cameras.
308
309Thus, the aim of the \texttt{SCHUR} ordering algorithm is to identify the largest independent set in the graph of $H$. Unfortunately this is an NP-Hard problem. But there is a greedy approximation algorithm that performs well~\cite{li2007miqr} and we use it to identify \texttt{e\_block}s in Ceres.
310
311\section{\texttt{Solver::Options}}
312
Sameer Agarwal122cf832012-08-24 16:28:27 -0700313\texttt{Solver::Options} controls the overall behavior of the
314solver. We list the various settings and their default values below.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700315
316\begin{enumerate}
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700317
Sameer Agarwal122cf832012-08-24 16:28:27 -0700318\item{\texttt{trust\_region\_strategy\_type }}
319 (\texttt{LEVENBERG\_MARQUARDT}) The trust region step computation
320 algorithm used by Ceres. Currently \texttt{LEVENBERG\_MARQUARDT }
321 and \texttt{DOGLEG} are the two valid choices.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700322
Sameer Agarwal122cf832012-08-24 16:28:27 -0700323\item{\texttt{dogleg\_type}} (\texttt{TRADITIONAL\_DOGLEG}) Ceres
324 supports two different dogleg strategies.
325 \texttt{TRADITIONAL\_DOGLEG} method by Powell and the
326 \texttt{SUBSPACE\_DOGLEG} method described by Byrd et al.
327~\cite{byrd1988approximate}. See Section~\ref{sec:dogleg} for more details.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700328
Sameer Agarwal122cf832012-08-24 16:28:27 -0700329\item{\texttt{use\_nonmonotoic\_steps}} (\texttt{false})
330Relax the requirement that the trust-region algorithm take strictly
331decreasing steps. See Section~\ref{sec:non-monotonic} for more details.
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700332
Sameer Agarwal122cf832012-08-24 16:28:27 -0700333\item{\texttt{max\_consecutive\_nonmonotonic\_steps}} (5)
334The window size used by the step selection algorithm to accept
335non-monotonic steps.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700336
Sameer Agarwal122cf832012-08-24 16:28:27 -0700337\item{\texttt{max\_num\_iterations }}(\texttt{50}) Maximum number of
338 iterations for Levenberg-Marquardt.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700339
Sameer Agarwal122cf832012-08-24 16:28:27 -0700340\item{\texttt{max\_solver\_time\_in\_seconds }} ($10^9$) Maximum
341 amount of time for which the solver should run.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700342
Sameer Agarwal122cf832012-08-24 16:28:27 -0700343\item{\texttt{num\_threads }}(\texttt{1}) Number of threads used by
344 Ceres to evaluate the Jacobian.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700345
Sameer Agarwal122cf832012-08-24 16:28:27 -0700346\item{\texttt{initial\_trust\_region\_radius } ($10^4$)} The size of
347 the initial trust region. When the \texttt{LEVENBERG\_MARQUARDT}
348 strategy is used, the reciprocal of this number is the initial
349 regularization parameter.
Sameer Agarwal8ed29a72012-06-07 17:04:25 -0700350
Sameer Agarwal122cf832012-08-24 16:28:27 -0700351\item{\texttt{max\_trust\_region\_radius } ($10^{16}$)} The trust
352 region radius is not allowed to grow beyond this value.
Sameer Agarwal8ed29a72012-06-07 17:04:25 -0700353
Sameer Agarwal122cf832012-08-24 16:28:27 -0700354\item{\texttt{min\_trust\_region\_radius } ($10^{-32}$)} The solver
355 terminates, when the trust region becomes smaller than this value.
356
357\item{\texttt{min\_relative\_decrease }}($10^{-3}$) Lower threshold
358 for relative decrease before a Levenberg-Marquardt step is acceped.
359
360\item{\texttt{lm\_min\_diagonal } ($10^6$)} The
361 \texttt{LEVENBERG\_MARQUARDT} strategy, uses a diagonal matrix to
362 regularize the the trust region step. This is the lower bound on the
363 values of this diagonal matrix.
364
365\item{\texttt{lm\_max\_diagonal } ($10^{32}$)} The
366 \texttt{LEVENBERG\_MARQUARDT} strategy, uses a diagonal matrix to
367 regularize the the trust region step. This is the upper bound on the
368 values of this diagonal matrix.
369
370\item{\texttt{max\_num\_consecutive\_invalid\_steps } (5)} The step
371 returned by a trust region strategy can sometimes be numerically
372 invalid, usually because of conditioning issues. Instead of crashing
373 or stopping the optimization, the optimizer can go ahead and try
374 solving with a smaller trust region/better conditioned problem. This
375 parameter sets the number of consecutive retries before the
376 minimizer gives up.
Sameer Agarwal8ed29a72012-06-07 17:04:25 -0700377
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700378\item{\texttt{function\_tolerance }}($10^{-6}$) Solver terminates if
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700379\begin{align}
380\frac{|\Delta \text{cost}|}{\text{cost}} < \texttt{function\_tolerance}
381\end{align}
Sameer Agarwal122cf832012-08-24 16:28:27 -0700382where, $\Delta \text{cost}$ is the change in objective function value
383(up or down) in the current iteration of Levenberg-Marquardt.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700384
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700385\item \texttt{Solver::Options::gradient\_tolerance } Solver terminates if
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700386\begin{equation}
387 \frac{\|g(x)\|_\infty}{\|g(x_0)\|_\infty} < \texttt{gradient\_tolerance}
388\end{equation}
389where $\|\cdot\|_\infty$ refers to the max norm, and $x_0$ is the vector of initial parameter values.
390
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700391\item{\texttt{parameter\_tolerance }}($10^{-8}$) Solver terminates if
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700392\begin{equation}
Sameer Agarwal8ed29a72012-06-07 17:04:25 -0700393 \frac{\|\Delta x\|}{\|x\| + \texttt{parameter\_tolerance}} < \texttt{parameter\_tolerance}
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700394\end{equation}
395where $\Delta x$ is the step computed by the linear solver in the current iteration of Levenberg-Marquardt.
396
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700397\item{\texttt{linear\_solver\_type }(\texttt{SPARSE\_NORMAL\_CHOLESKY})}
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700398
Sameer Agarwal122cf832012-08-24 16:28:27 -0700399\item{\texttt{linear\_solver\_type
400 }}(\texttt{SPARSE\_NORMAL\_CHOLESKY}/\texttt{DENSE\_QR}) Type of
401 linear solver used to compute the solution to the linear least
402 squares problem in each iteration of the Levenberg-Marquardt
403 algorithm. If Ceres is build with \suitesparse linked in then the
404 default is \texttt{SPARSE\_NORMAL\_CHOLESKY}, it is
405 \texttt{DENSE\_QR} otherwise.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700406
Sameer Agarwal122cf832012-08-24 16:28:27 -0700407\item{\texttt{preconditioner\_type }}(\texttt{JACOBI}) The
408 preconditioner used by the iterative linear solver. The default is
409 the block Jacobi preconditioner. Valid values are (in increasing
410 order of complexity) \texttt{IDENTITY},\texttt{JACOBI},
411 \texttt{SCHUR\_JACOBI}, \texttt{CLUSTER\_JACOBI} and
412 \texttt{CLUSTER\_TRIDIAGONAL}.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700413
Sameer Agarwal122cf832012-08-24 16:28:27 -0700414\item{\texttt{sparse\_linear\_algebra\_library }
415 (\texttt{SUITE\_SPARSE})} Ceres supports the use of two sparse
416 linear algebra libraries, \texttt{SuiteSparse}, which is enabled by
417 setting this parameter to \texttt{SUITE\_SPARSE} and
418 \texttt{CXSparse}, which can be selected by setting this parameter
419 to $\texttt{CX\_SPARSE}$. \texttt{SuiteSparse} is a sophisticated
420 and complex sparse linear algebra library and should be used in
421 general. If your needs/platforms prevent you from using
422 \texttt{SuiteSparse}, consider using \texttt{CXSparse}, which is a
423 much smaller, easier to build library. As can be expected, its
424 performance on large problems is not comparable to that of
425 \texttt{SuiteSparse}.
Sameer Agarwal8ed29a72012-06-07 17:04:25 -0700426
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700427
Sameer Agarwal122cf832012-08-24 16:28:27 -0700428\item{\texttt{num\_linear\_solver\_threads }}(\texttt{1}) Number of
429 threads used by the linear solver.
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700430
Sameer Agarwal65625f72012-09-17 12:06:57 -0700431%\item{\texttt{num\_eliminate\_blocks }}(\texttt{0})
432%For Schur reduction based methods, the first 0 to num blocks are
433%eliminated using the Schur reduction. For example, when solving
434%traditional structure from motion problems where the parameters are in
435%two classes (cameras and points) then \texttt{num\_eliminate\_blocks}
436%would be the number of points.
437%
438%\item{\texttt{ordering\_type }}(\texttt{NATURAL}) Internally Ceres
439% reorders the parameter blocks to help the various linear
440% solvers. This parameter allows the user to influence the re-ordering
441% strategy used. For structure from motion problems use
442% \texttt{SCHUR}, for other problems \texttt{NATURAL} (default) is a
443% good choice. In case you wish to specify your own ordering scheme,
444% for example in conjunction with \texttt{num\_eliminate\_blocks}, use
445% \texttt{USER}.
446%
447%\item{\texttt{ordering }} The ordering of the parameter blocks. The
448% solver pays attention to it if the \texttt{ordering\_type} is set to
449% \texttt{USER} and the ordering vector is non-empty.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700450
Sameer Agarwal122cf832012-08-24 16:28:27 -0700451\item{\texttt{use\_block\_amd } (\texttt{true})} By virtue of the
452 modeling layer in Ceres being block oriented, all the matrices used
453 by Ceres are also block oriented.
Sameer Agarwal8ed29a72012-06-07 17:04:25 -0700454When doing sparse direct factorization of these matrices, the
455fill-reducing ordering algorithms can either be run on the
456block or the scalar form of these matrices. Running it on the
457block form exposes more of the super-nodal structure of the
458matrix to the Cholesky factorization routines. This leads to
Sameer Agarwal122cf832012-08-24 16:28:27 -0700459substantial gains in factorization performance. Setting this parameter
460to true, enables the use of a block oriented Approximate Minimum
461Degree ordering algorithm. Settings it to \texttt{false}, uses a
462scalar AMD algorithm. This option only makes sense when using
463\texttt{sparse\_linear\_algebra\_library = SUITE\_SPARSE} as it uses
464the \texttt{AMD} package that is part of \texttt{SuiteSparse}.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700465
Sameer Agarwal122cf832012-08-24 16:28:27 -0700466\item{\texttt{linear\_solver\_min\_num\_iterations }}(\texttt{1})
467 Minimum number of iterations used by the linear solver. This only
468 makes sense when the linear solver is an iterative solver, e.g.,
469 \texttt{ITERATIVE\_SCHUR}.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700470
Sameer Agarwal122cf832012-08-24 16:28:27 -0700471\item{\texttt{linear\_solver\_max\_num\_iterations }}(\texttt{500})
472 Minimum number of iterations used by the linear solver. This only
473 makes sense when the linear solver is an iterative solver, e.g.,
474 \texttt{ITERATIVE\_SCHUR}.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700475
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700476\item{\texttt{eta }} ($10^{-1}$)
Sameer Agarwal122cf832012-08-24 16:28:27 -0700477 Forcing sequence parameter. The truncated Newton solver uses this
478 number to control the relative accuracy with which the Newton step is
479 computed. This constant is passed to ConjugateGradientsSolver which
480 uses it to terminate the iterations when
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700481\begin{equation}
Sameer Agarwal122cf832012-08-24 16:28:27 -0700482\frac{Q_i - Q_{i-1}}{Q_i} < \frac{\eta}{i}
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700483\end{equation}
484
Sameer Agarwal122cf832012-08-24 16:28:27 -0700485\item{\texttt{jacobi\_scaling }}(\texttt{true}) \texttt{true} means
486 that the Jacobian is scaled by the norm of its columns before being
487 passed to the linear solver. This improves the numerical
488 conditioning of the normal equations.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700489
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700490\item{\texttt{logging\_type }}(\texttt{PER\_MINIMIZER\_ITERATION})
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700491
492
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700493\item{\texttt{minimizer\_progress\_to\_stdout }}(\texttt{false})
Sameer Agarwal122cf832012-08-24 16:28:27 -0700494By default the Minimizer progress is logged to \texttt{STDERR}
495depending on the \texttt{vlog} level. If this flag is
496set to true, and \texttt{logging\_type } is not \texttt{SILENT}, the
497logging output
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700498is sent to \texttt{STDOUT}.
499
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700500\item{\texttt{return\_initial\_residuals }}(\texttt{false})
501\item{\texttt{return\_final\_residuals }}(\texttt{false})
Sameer Agarwal122cf832012-08-24 16:28:27 -0700502If true, the vectors \texttt{Solver::Summary::initial\_residuals } and
503\texttt{Solver::Summary::final\_residuals } are filled with the
504residuals before and after the optimization. The entries of these
505vectors are in the order in which ResidualBlocks were added to the
506Problem object.
507
Sameer Agarwal4997cbc2012-07-02 12:44:34 -0700508\item{\texttt{return\_initial\_gradient }}(\texttt{false})
509\item{\texttt{return\_final\_gradient }}(\texttt{false})
Sameer Agarwal122cf832012-08-24 16:28:27 -0700510If true, the vectors \texttt{Solver::Summary::initial\_gradient } and
511\texttt{Solver::Summary::final\_gradient } are filled with the
512gradient before and after the optimization. The entries of these
513vectors are in the order in which ParameterBlocks were added to the
514Problem object.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700515
Sameer Agarwal122cf832012-08-24 16:28:27 -0700516Since \texttt{AddResidualBlock } adds ParameterBlocks to the
517\texttt{Problem } automatically if they do not already exist, if you
518wish to have explicit control over the ordering of the vectors, then
519use \texttt{Problem::AddParameterBlock } to explicitly add the
520ParameterBlocks in the order desired.
521
Sameer Agarwal4997cbc2012-07-02 12:44:34 -0700522\item{\texttt{return\_initial\_jacobian }}(\texttt{false})
523\item{\texttt{return\_initial\_jacobian }}(\texttt{false})
Sameer Agarwal122cf832012-08-24 16:28:27 -0700524If true, the Jacobian matrices before and after the optimization are
525returned in \texttt{Solver::Summary::initial\_jacobian } and
526\texttt{Solver::Summary::final\_jacobian } respectively.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700527
Sameer Agarwal122cf832012-08-24 16:28:27 -0700528The rows of these matrices are in the same order in which the
529ResidualBlocks were added to the Problem object. The columns are in
530the same order in which the ParameterBlocks were added to the Problem
531object.
Sameer Agarwal4997cbc2012-07-02 12:44:34 -0700532
Sameer Agarwal122cf832012-08-24 16:28:27 -0700533Since \texttt{AddResidualBlock } adds ParameterBlocks to the
534\texttt{Problem } automatically if they do not already exist, if you
535wish to have explicit control over the column ordering of the matrix,
536then use \texttt{Problem::AddParameterBlock } to explicitly add the
537ParameterBlocks in the order desired.
538
539The Jacobian matrices are stored as compressed row sparse
540matrices. Please see \texttt{ceres/crs\_matrix.h } for more details of
541the format.
542
543\item{\texttt{lsqp\_iterations\_to\_dump }} List of iterations at
544 which the optimizer should dump the linear least squares problem to
545 disk. Useful for testing and benchmarking. If empty (default), no
546 problems are dumped.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700547
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700548\item{\texttt{lsqp\_dump\_directory }} (\texttt{/tmp})
Sameer Agarwal122cf832012-08-24 16:28:27 -0700549 If \texttt{lsqp\_iterations\_to\_dump} is non-empty, then this
550 setting determines the directory to which the files containing the
551 linear least squares problems are written to.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700552
553
Sameer Agarwal122cf832012-08-24 16:28:27 -0700554\item{\texttt{lsqp\_dump\_format }}(\texttt{TEXTFILE}) The format in
555 which linear least squares problems should be logged
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700556when \texttt{lsqp\_iterations\_to\_dump} is non-empty. There are three options
557\begin{itemize}
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700558\item{\texttt{CONSOLE }} prints the linear least squares problem in a human readable format
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700559 to \texttt{stderr}. The Jacobian is printed as a dense matrix. The vectors
560 $D$, $x$ and $f$ are printed as dense vectors. This should only be used
561 for small problems.
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700562\item{\texttt{PROTOBUF }}
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700563 Write out the linear least squares problem to the directory
564 pointed to by \texttt{lsqp\_dump\_directory} as a protocol
565 buffer. \texttt{linear\_least\_squares\_problems.h/cc} contains routines for
566 loading these problems. For details on the on disk format used,
Sameer Agarwal122cf832012-08-24 16:28:27 -0700567 see \texttt{matrix.proto}. The files are named
568 \texttt{lm\_iteration\_???.lsqp}. This requires that
569 \texttt{protobuf} be linked into Ceres Solver.
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700570\item{\texttt{TEXTFILE }}
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700571 Write out the linear least squares problem to the directory
572 pointed to by \texttt{lsqp\_dump\_directory} as text files
573 which can be read into \texttt{MATLAB/Octave}. The Jacobian is dumped as a
574 text file containing $(i,j,s)$ triplets, the vectors $D$, $x$ and $f$ are
575 dumped as text files containing a list of their values.
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700576
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700577 A \texttt{MATLAB/Octave} script called \texttt{lm\_iteration\_???.m} is also output,
578 which can be used to parse and load the problem into memory.
579\end{itemize}
580
581
582
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700583\item{\texttt{check\_gradients }}(\texttt{false})
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700584 Check all Jacobians computed by each residual block with finite
585 differences. This is expensive since it involves computing the
586 derivative by normal means (e.g. user specified, autodiff,
587 etc), then also computing it using finite differences. The
588 results are compared, and if they differ substantially, details
589 are printed to the log.
590
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700591\item{\texttt{gradient\_check\_relative\_precision }} ($10^{-8}$)
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700592 Relative precision to check for in the gradient checker. If the
593 relative difference between an element in a Jacobian exceeds
594 this number, then the Jacobian for that cost term is dumped.
595
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700596\item{\texttt{numeric\_derivative\_relative\_step\_size }} ($10^{-6}$)
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700597 Relative shift used for taking numeric derivatives. For finite
598 differencing, each dimension is evaluated at slightly shifted
599 values, \eg for forward differences, the numerical derivative is
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700600
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700601\begin{align}
Sameer Agarwal122cf832012-08-24 16:28:27 -0700602 \delta &= \texttt{numeric\_derivative\_relative\_step\_size}\\
603 \Delta f &= \frac{f((1 + \delta) x) - f(x)}{\delta x}
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700604\end{align}
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700605
Sameer Agarwal122cf832012-08-24 16:28:27 -0700606The finite differencing is done along each dimension. The
607reason to use a relative (rather than absolute) step size is
608that this way, numeric differentiation works for functions where
609the arguments are typically large (e.g. $10^9$) and when the
610values are small (e.g. $10^{-5}$). It is possible to construct
611"torture cases" which break this finite difference heuristic,
612but they do not come up often in practice.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700613
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700614\item{\texttt{callbacks }}
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700615 Callbacks that are executed at the end of each iteration of the
Sameer Agarwal122cf832012-08-24 16:28:27 -0700616\texttt{Minimizer}. They are executed in the order that they are
617specified in this vector. By default, parameter blocks are
618updated only at the end of the optimization, i.e when the
619\texttt{Minimizer} terminates. This behavior is controlled by
620\texttt{update\_state\_every\_variable}. If the user wishes to have access
621to the update parameter blocks when his/her callbacks are
622executed, then set \texttt{update\_state\_every\_iteration} to true.
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700623
Sameer Agarwal122cf832012-08-24 16:28:27 -0700624The solver does NOT take ownership of these pointers.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700625
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700626\item{\texttt{update\_state\_every\_iteration }}(\texttt{false})
Sameer Agarwal122cf832012-08-24 16:28:27 -0700627Normally the parameter blocks are only updated when the solver
628terminates. Setting this to true update them in every iteration. This
629setting is useful when building an interactive application using Ceres
630and using an \texttt{IterationCallback}.
631
632\item{\texttt{solver\_log}} If non-empty, a summary of the execution of the solver is
633 recorded to this file. This file is used for recording and Ceres'
634 performance. Currently, only the iteration number, total
635 time and the objective function value are logged. The format of this
636 file is expected to change over time as the performance evaluation
637 framework is fleshed out.
Sameer Agarwald3eaa482012-05-29 23:47:57 -0700638\end{enumerate}
639
640\section{\texttt{Solver::Summary}}
Sameer Agarwal97fb6d92012-06-17 10:08:19 -0700641TBD