Automatic Multivector Differentiation and Optimization

In this work, we present a novel approach to nonlinear optimization of multivectors in the Euclidean and conformal model of geometric algebra by introducing automatic differentiation. This is used to compute gradients and Jacobian matrices of multivector valued functions for use in nonlinear optimization where the emphasis is on the estimation of rigid body motions.


Introduction
Geometric algebra has been employed in many applications in robotics and computer vision.An important problem in these applications is the estimation of geometric objects and transformations from noisy data.Most estimation techniques based on geometric algebra employ singular value decomposition or other linear least squares methods, see [4,5,20,21,31,39].Valkenburg and Alwesh [48] employ nonlinear optimization in a calibration method of multiple stationary 3D points as part of an optical positioning system using the conformal model of geometric algebra.Perwass [37] uses nonlinear optimization in 3D-reconstruction from multiple view geometry in the projective model of geometric algebra.The methods of [48] and [37] make use of multivector differentiation in geometric calculus [26] to compute gradients and Jacobian matrices.This involves tensor expressions.
Another tool for computing gradients and Jacobian matrices in nonlinear optimization is algorithmic or automatic differentiation [22].Automatic differentiation computes derivatives with machine precision and works by exploiting the fact that all computer implementations of mathematical functions are composed of simple differentiable unary or binary operations, e.g., addition, multiplication or transcendental functions as sin, cos and exp.Adv.Appl.Clifford Algebras Derivatives of more complex functions are computed by applying the chain rule at each operation and bookkeeping the results [44].
Automatic differentiation has been used extensively in robotics and computer vision in recent years, e.g., for solving large scale bundle adjustment problems [2] and multi-camera calibration and people tracking in networks of RGB-D cameras [34].These applications have been implemented in the Ceres [1] optimization framework developed by Google.
In this work, we present a novel approach to nonlinear optimization of multivectors in the Euclidean and conformal model of geometric algebra by introducing automatic differentiation.Automatic differentiation is used to compute gradients and Jacobian matrices of multivector valued functions for use in nonlinear optimization where the emphasis is on the estimation of rigid body motions.
The paper is organized as follows.Section 2 presents geometric algebra and the conformal model with focus on notation and on the representation of rigid body motions.Section 3 presents an overview of automatic differentiation.In Sect. 4 we introduce automatic multivector differentiation; A novel approach to differentiation of multivector valued functions by employing automatic differentiation.Further, in Sect.5, we present multivector estimation using nonlinear optimization with focus on estimation of rigid body motions.In Sect.6 we present implementation details regarding both automatic multivector differentiation and multivector estimation.Then, in Sect.7, we present experimental results.Finally, in Sect.8, we conclude the paper.

Geometric Algebra and the Conformal Model
Geometric algebra is an approach to geometry based on the work of W. Clifford which combined H. Grassmann's exterior algebra with Hamilton's quaternions and created what he termed geometric algebra.D. Hestenes developed geometric algebra further in his books [25,26] and later introduced the conformal model in [32].
The elements of a geometric algebra are called multivectors.The geometric algebra over 3-dimensional Euclidean space R 3 is denoted R 3 .The notation R r 3 refers to the r-grade elements of R 3 e.g.R 2 3 refers to the elements of R 3 of grade 2-the bivectors.The notation R + 3 refers to the elements of R 3 of even grade.The conformal model of geometric algebra is denoted R 4,1 and has the null basis {e 1 , e 2 , e 3 , n o , n ∞ }.The basis vector n ∞ represents the point at infinity, and the basis vector n o represents an arbitrary origin.These basis vectors have the properties The notation e ij is shorthand for the outer product e i ∧ e j of the vectors e i , e j ∈ R 1  3 .The highest grade element of R 3 , the Euclidean pseudoscalar, is denoted I 3 .The element of grade r of a multivector X is extracted using the grade projection operator X r .The reverse of a multivector X is denoted X.
Vectors x ∈ R 1 3 map to points p ∈ R 1 4,1 using where B ∈ R 2 3 is the unit bivector representing the rotation plane and θ is the rotation angle.It is noted that rotors are isomorphic to the unit quaternions.A rotor R is on the rotor manifold where R = R −1 is the reverse rotor.The rotation of a vector a ∈ R 1 3 to a vector a is given by the sandwich product a = Ra R. (2.4) A translation by a vector v is described with a translator T v given by The translation of the rotor R gives This gives The position and orientation of rigid body can be described with a motor M .A motor can be described as a rotation about a line through the origin followed by a translation u according to This cannot be combined in a single exponential function because the rotation and the translation do not commute.This is solved with the application of Chasle's theorem, where the motion of a rigid body is described with a rotation about a line that is not necessarily through the origin, and a translation along the same line, in which case the rotation and translation will commute.The motor is then where w is the translation along the line of rotation, and v is the translation of the rotor.This vector is in the rotation plane given by B. A motor can therefore be written as the exponential function L.
Here B ∈ R 2 3 is the rotation plane, and t ∈ R 1 3 is a vector given by t = t ⊥ + t where t ⊥ = w is normal to B, and Moreover, it can be shown that Λ * is a dual line representing the screw axis of the rigid body motion, see [12].Following [50], the exponential formulation in (2.10) can be written in terms of the constituent elements of different grades as where sinc(x) = sin(x)/x.The motor manifold M is of dimension 6, and is embedded in the 8dimensional subspace M with basis {1, e 12 , e 13 , e 23 , e 1 n ∞ , e 2 n ∞ , e 3 n ∞ , I 3 n ∞ }.A multivector M ∈ M will be a motor if and only if ( It is noted that this condition implies where p is the displaced point.

Automatic Differentiation
Automatic differentiation computes derivative values of computer implemented functions with accuracy up to machine precision.Derivative information as Jacobian matrices and gradients can be found symbolically by hand-computations and implemented manually or generated by computer algebra systems, approximated using numerical differentiation or computed using automatic differentiation.Supplying hand-coded derivative values is error-prone and time consuming for complex nonlinear functions and symbolic differentiation using a computer algebra system can in certain cases lead to significant long computation times [28,44].Consider the vector valued function f : Numerical differentiation using finite differences is based on evaluating (3.2) with a small value h > 0. However, this method is prone to truncation and rounding off errors and may fail completely when the implemented functions include conditional statements [44].Automatic differentiation is also numerical differentiation in that it computes numerical derivative values, but it computes the numerical values up to machine precision.
The main principle behind automatic differentiation is that every function can be represented as a finite sequence ϕ of elemental unary or binary operations with known derivatives, e.g., unary operations as trigonometric, exponential and logarithmic operations or binary operations as addition, multiplication, division and the power operation.The derivative of the whole computation can then be computed through the chain rule.Using the notation of [22], a finite sequence can be written as where {v −n , . . ., v 0 } are the input variables, and {v 1 , . . ., v l−m } are intermediate variables computed as The output of the sequence is given by the variables {v l−m+1 , . . ., v l }.A finite sequence for the computations of a computer implemented function can be determined by what is known as an evaluation trace of elemental operations or Wengert list [3].As an example consider the function f : R 2 → R, with the evaluation trace as shown in Table 1.
There are two main approaches to automatic differentiation -forward mode and reverse mode.
Table 1.Forward evaluation and derivative trace of the function y Forward evaluation trace Forward derivative trace The forward derivative trace is then found by applying the chain rule to each elemental operation in the forward evaluation trace.For a function f : R n → R, one pass through the forward derivative trace computes ∂f /∂x j for a fixed j.The Jacobian matrix of a function f : R n → R m can thus be evaluated in n passes through the forward derivative trace, where each pass computes one column.
Consider again the function in (3.5).The derivative ∂f /∂x 1 = ∂v 3 /∂v −1 can be found by setting v−1 = 1 and v0 = 0 and evaluating the forward derivative trace in Table 1: Similarly, ∂f /∂x 2 can be found by setting v−1 = 0 and v0 = 1 and evaluating the forward derivative trace again.

Dual Numbers.
Forward mode automatic differentiation can be seen as evaluating a function f using dual numbers.Introduced by W. K. Clifford in the seminal paper Preliminary Sketch of Biquaternions [6], dual numbers are given as where x and y are real numbers, and ε is the dual unit, which satisfies ε = 0 and ε 2 = 0.The Taylor expansion of f (x + ε) at x is given by which returns the function value as the real part plus the derivative as the dual part.

Reverse Mode
Reverse mode automatic differentiation is based on populating the intermediate variables in the forward evaluation trace and then propagating derivatives with respect to an output variable y j in a reverse phase.This is done by assigning to intermediate variable and propagating these backwards from a given output.The reverse adjoint trace of (3.5) is shown in Table 2.As seen, both v0 and v−1 is computed in one reverse pass.This is the major advantage of the reverse mode compared to the forward mode of automatic differentiation, that is, the gradient of a function f : R n → R can be evaluated in one pass compared to n passes in the forward mode.
Table 2. Forward evaluation trace and reverse adjoint trace of the function y

Implementation Using Operator Overloading
There are two main approaches to implementing automatic differentiationsource code transformation and operator overloading.Source code transformation is based on pre-processing the function source code and generating code that implements the necessary steps to compute the derivatives.The approach used in this work is that of operator overloading in C++.The main idea here is to overload the scalar type used in the computations and to write functions as function templates using template metaprogramming.
The new scalar type then implements the necessary logic to compute the derivatives.Examples are the Jet-type in the Google Ceres framework that implements forward mode automatic differentiation using the dual numbers approach in Sect.3.1.1and the adouble-type in the Adept [29] framework by Robin J. Hogan that implements both forward and reverse mode automatic differentiation using expression templates [30].

Automatic Multivector Differentiation
As an example, consider differentiating the sandwich product where The finite sequence or evaluation trace of (4.2) to (4.8) are shown in Table 3 and consist of a total of 17 statements to compute the derivative with respect to θ.The multiplications in statements v 7 , v 10 and v 13 correspond to the sign changes due to the geometric products in (4.2) and (4.6).
The expressions in statements v 14 and v 15 are the output of the function f , i.e.,  (4.9) show that the output is correct and that computer implementations of geometric algebra algorithms can be differentiated using automatic differentiation.

Multivector Estimation
In this section a new approach to rotor and motor estimation is proposed based on nonlinear least squares optimization of the form min X∈M F (X). (5.1) where F : M → R is the cost function to be minimized and X is a conformal motor on the motor manifold M or a Euclidean rotor on the rotor manifold R.
The cost function F is given by where each observation i corresponds to a vector f i (X) = (r i1 , . . ., r ip ) of p residuals r ij ∈ R. It is seen that the cost function F has m = Np residuals where N is the number of observations.A residual is a scalar measure for the discrepancy between the model and the observed data [36].

Rotor Estimation
Following Lasenby et al. [31], the rotor estimation problem can be formulated as the nonlinear least squares optimization problem where a i , b i ∈ R 1 3 and {(a i , b i )} i=1,...,N are N observations of Euclidean vectors and the rotor R is parameterized by the parameter vector x.In this formulation there are 3 residuals for each observation, namely, the residual Euclidean distances in the e 1 , e 2 and e 3 directions, giving a total of 3N residuals.The Jacobian matrices will be of size 3N × dim(x).

Parameterization.
Several parameterizations are possible for the rotor in (5.3) such that the constraint in (2.3) is enforced.One possible parameterization is to use all the 4 components of the rotor 13 , e 23 }, (5.4) and to re-normalize after each optimization step.However, this is an overparameterization as the rotors lie on the 3-dimensional manifold R.
Another solution to the problem of over-parameterization is to parameterize the rotor using only the bivector parts (x 2 , x 3 , x 4 ) of x and to compute the full parameterization of the rotor using This is investigated for quaternions in [40].This approach is not recommended as the rotation angle is limited to − π 2 , π 2 and the radicand in (5.5) can not be guaranteed to be positive when estimating the rotor R using the Levenberg-Marquardt method.Adv.Appl.Clifford Algebras The parameterization of the rotor R in this work makes use of the theory of optimization on differentiable manifolds [44].Then the step is calculated in the tangent space of the rotor manifold R and thus removing null directions in the step update.The increment is calculated in the rotor manifold using the exponential map, which is given in terms of its bivector generator B: R = exp(B(x)), (5.6)where The rotor in iteration k + 1 can then be written as where the exponential map is computed using (2.2).It follows that R k+1 ∈ R whenever R k ∈ R.

Motor Estimation from Point Clouds
Consider a rigid body that is displaced by a motor be a set of points on the rigid body in the initial configuration, and let {q i = Mp i M } be the same point in the displaced configuration.The sets {p i } and {q i } are called point clouds.Motor estimation is the problem of finding the motor M given {p i } and {q i }.
One possible formulation of this optimization problem is to use the inner product between two conformal points min (5.9) In this formulation the measure that is optimized is the squared distance between each two points, resulting in a 1-dimensional residual vector for each observation.This, however, is not a good formulation for the cost function as discussed in the experimental results in Sect.7.2.2.
A better formulation of this problem is to project the points to the 3dimensional Euclidean model after the transformation by the motor M , and then to use the residual errors along each of the coordinate axes, resulting in a 3-dimensional residual vector for each observation with the optimization problem min (5.10) Implementationwise, this projection is performed by selecting only the pure Euclidean components of the conformal points.

Parameterization.
One possible parameterization of conformal motors is based on the polar decomposition by Valkenburg and Dorst [49].This parameterization is based on representing the motor M using the full 8dimensional basis as presented in Sect.2, that is, where x = (x 1 , . . ., x 8 ) and M i ∈ {1, e 12 , e 13 , e 23 , e 1 n ∞ , e 2 n ∞ , e 3 n ∞ , I 3 n ∞ }.
Using this approach, similarly to the 4-dimensional rotor parameterization in Sect.5.1.1,it is necessary to re-normalize after each optimization step to ensure that the resulting object X(x) ∈ M is in fact a motor, in which case (5.12) This re-normalization can not be performed by normalizing x due to the constraint in (5.12).Lemma 2.3 in [49], however, shows that any element X ∈ M, |X| = 0 has a unique polar decomposition X = MS = SM where M ∈ M, S ∈ span{1, I 3 n ∞ }, S > 0. Any element X ∈ M can then be projected onto the motor manifold M using the following projection The motor in iteration k + 1 using this parameterization is then computed as (5.14 Another parameterization is based on the exponential form of a motor in terms of its bivector generator as presented in (2.10).As opposed to the polar decomposition approach, this ensures that the step is taken in the motor manifold M. The motor in iteration k +1 using this parameterization is given by where

Implementation
This section presents the implementation of automatic multivector differentiation and estimation.Adv.Clifford Algebras Listing 1. Templated C++ code of the sandwich product b = Ra R where a, b, ∈ R 1 3 and R ∈ R + 3 for use in automatic differentiation

Automatic Multivector Differentiation
The use of automatic differentiation using operator overloading sets some constraints on the implementation of geometric algebra and the conformal model.A number of geometric algebra libraries and software systems in different programming languages have been developed over the last decades, e.g., CLUCalc [38] and GAViewer [15] which are both designed as development environments with graphics for visualization based on OpenGL [51] and specially designed domain specific languages [19] for ease of programming.Examples of freely available geometric algebra C++ libraries are Gaalop [27], which is a geometric algebra pre-compiler for high-performance computing where algorithms developed in CLUCalc can be used directly in the C++ source and pre-compiled to, e.g., C++, OpenCL [45] and CUDA [35].Other geometric algebra source code generators are Gaigen [18] and Gaigen2 [16] which are used in the C++ code accompanying the Geometric Algebra for Computer Science book by Dorst et al. [14].In the Gaigen libraries C, C++ and Java code can be generated from specifications of the Euclidean, projective and conformal model of geometric algebra.However, the aforementioned libraries are not suited for use with operator overloading based automatic differentiation libraries as they do not permit templating the scalar type used in the computations.
In this paper we propose an approach to multivector estimation using automatic differentiation based on the following idea: Consider again the sandwich product in (4.1).The main idea is to be able to write code as presented in Listing 1 where the input are the four components of a rotor R ∈ R + 3 and the three components of a Euclidean vector v ∈ R 1  3 and the output is the three components of the rotated vector.In addition to the geometric product and reverse operation in the Euclidean model presented in Listing 1, more complex operations like the outer and inner products and the left contraction should be supported as well as the conformal model and other geometric algebras.To clarify this, we present three possible formulations to investigate their suitability to our problem.The three formulations are a matrix based implementation of the Euclidean model and two multivector based implementations of both the Euclidean and conformal model implemented in the C++11 standard.
Listing 2. Templated C++ code of the sandwich product b = Ra R where a, b, ∈ R 1 3 and R ∈ R + 3 for use in automatic differentiation implemented using 4 × 4 matrices in the Eigen [23] matrix library Listing 3. Templated matrix implementation of the basis vector e 1 ∈ R 1  3 .The other basis vectors e 2 , e 3 are implemented similarly

Matrix Based Implementation of Geometric Algebra.
A matrix implementation of the Euclidean model can be based on the isomorphism between the geometric algebra R 3 and the matrix algebra of 4×4 matrices with entries in R, see [42].The three basis vectors in R 1  3 can then be represented by the matrices Then the geometric product is matrix multiplication and the identity is represented by the 4 × 4 identity matrix.Using the Eigen [23] C++ matrix library the function in Listing 1 can be implemented as presented in Listing 2 and Listing 3. Further, the conformal model can be implemented using Vahlen matrices, see [13] and [43].This approach is relatively simple to implement for the Euclidean model as all elements in the geometric algebra are represented by matrices.However, and as noted in [14], the matrix representation works only for the geometric product and the contraction operations can not be implemented in the same framework due to nonassociativity.The simplicity of representing all elements in a geometric algebra as matrices is also the main argument for not using it as it lacks the notion of types, that is, a vector has the same type as a bivector or a rotor.This kind of abstraction is essential for working with all the geometric entities and transformations in, e.g., the conformal model.Adv.Appl.Clifford Algebras The first implementation is the hep-ga [41] library developed by Chris Schwan for use in high energy physics.hep-ga is a C++11 library for efficient numeric computations using geometric algebra and is implemented using C++ expression templates [30].The implementation of the geometric algebra computations in hep-ga follows the bitset approach by Daniel Fontijne in [17] and [14].The use of expression templates ensures high performance computations at runtime, however the compile times using this library can become very long especially when evaluating multiple sandwich products of multivectors with many components, e.g., in forward kinematic computations of serial kinematic chains using motors.
The implementation of the function in Listing 1 using the hep-ga library is shown in Listing 4. Using this approach, different multivectors have different types through the use of type aliases.Similarly, the conformal model can be implemented by defining special types for the algebra and for the different multivectors.Only non-degenerate diagonal metrics are implemented and the change to a non-diagonal null metric must be implemented by the user and computed at runtime.The type alias for a conformal point p ∈ R 1 4,1 is shown in Listing 5.
The second implementation of geometric algebra used in this work is the Versor [7] library developed by Pablo Colapinto.Versor is a C++11 template metaprogramming library that generates optimized code at compile time, however, in contrast to the hep-ga library it is not based on expression templates.The Versor library supports arbitrary dimensions and non-degenerate metrics and implements the change to a null basis in the conformal model at Listing 6. Templated C++ code of the sandwich product b = Ma M where a, b, ∈ R 1 4,1 and M ∈ M for use in automatic differentiation implemented using the Versor library compile time.This is vital for high runtime performance and for algorithm development.Similarly to the hep-ga library, the implementation of the geometric algebra computations in Versor is following the bitset approach by Daniel Fontijne in [17] and [14].The Versor library also includes implementation of algorithms like the logarithm and exponential maps of conformal motors and data types for the most used conformal objects, e.g., vectors, points, spheres, lines and planes as well as rotors and motors.Examples of the use of the Versor library for surface and mesh generation using the conformal model can be found in [8] and [9].
The implementation of the function in Listing 1 using the Versor library is similar to the code for the hep-ga library in the sense that type aliases are used for the different multivectors.However, the types for the conformal model can be defined in a null metric, that is, a point p ∈ R 1 4,1 can be defined on the basis {e 1 , e 2 , e 3 , n o , n ∞ } directly.The change to the diagonal metric and back is performed at compile time.This enables us to write code as presented in Listing 6 and compute a 5 × 8 Jacobian matrix of the sandwich product b = Ma M where M ∈ M and a, b ∈ R 1 4,1 .

Multivector Estimation
The optimization framework used in this work is the Ceres [1] nonlinear least squares optimization framework developed by Google for solving large scale bundle adjustment problems [2,24].The Ceres framework is written in C++ and supports multiple line search and trust region methods, including nonlinear conjugate gradients, BFGS, L-BFGS, Powell's Dogleg trust region method and the Levenberg-Marquardt method [33].The Ceres framework also supports multiple sparse and dense linear solvers through the Eigen [23] and SuiteSparse [11] libraries.Gradients and Jacobians can be supplied manually or evaluated using numerical finite difference methods and automatic differentiation using an implementation of dual number forward mode automatic differentiation, as presented in Sect.3.1.1,through the Jet class.Another important feature of the Ceres framework is the use of OpenMP [10] based multithreading to speed up Jacobian evaluations and linear solvers.There are two main aspects of implementing optimization problem using automatic differentiation in the Ceres framework.The first is to implement a templated functor (function object) that implements the logic of the cost function and to pass this functor to the optimization problem using the L. Tingelstad  AutoDiffCostFunction class.The second aspect is used if the parameter to be estimated is an over-parameterization, as in rotor and motor estimation where the parameters are subject to the constraint of being on the rotor and motor manifolds.This is performed by implementing a templated functor that implements, e.g., the exponential map of rotors and motors and passing this to the optimization problem using the AutoDiffLocalParameterization class.
The functor that implements the cost function in (5.10) using the Versor library is shown in Listing 7 and the implementation of the motor parameterization in (2.10) is shown in Listing 8.

Experimental Results
This section presents the experimental results of automatic multivector differentiation and estimation using synthetic datasets.
The experiments were implemented using our framework called GAME [46] for multivector estimation.The source code is available online.The GAME framework is implemented in an Ubuntu1 16.04 Docker2 container.All experiments were run on an early 2015 Apple Macbook Pro 13 with an Intel i5 CPU at 2.7 GHz with 8 GB memory.The Docker version used were v1.12.0.The Ceres version were v.1.11.0 with Eigen v.3.2.92.The Adept version used were v.1.1.

Automatic Differentiation of Multivector Valued Functions
This section presents experimental results from calculation of the 3 × 1 Jacobian matrix of the sandwich product presented in (4.2)-(4.8)and evaluated at Listing 8. Templated functor for use in the Ceres framework that implements the motor parameterization in (2.10) using the Versor library θ = π/3.The benchmarks were implemented using the Benchmark3 library of Google.The geometric algebra implementations used were the Versor library with the implementation as presented in Listing 1, the hep-ga library using the implementation as presented in Listing 4 and the matrix based approach implemented using the Eigen matrix library with the implementation presented in Listing 2. The performance of the different geometric algebra implementations in combination with the Ceres and Adept automatic differentiation libraries is shown in Table 4.
All three libraries were able to compute the correct function and derivative values, however, there were significant performance differences.The best performing implementation was the combination of the Versor library with the forward mode implementation from Ceres with a mean computation time of μ = 528 ns and a standard deviation of σ = 7 ns.The worst performing implementation was the combination of the Matrix implementation with the forward mode implementation in the Adept library with a mean computation time of μ = 48125 ns and a standard deviation of σ = 1504 ns.Using the Adept library, the hep-ga implementation were faster than the Versor implementation.Using the Versor library, the number of statements to compute the derivative were 134 with a total of 170 operations.Using the hep-ga library, the number of statements were 95 with a total of 171 operations.The number of statements and operations using the 4 × 4 matrix approach Adv.Appl.Clifford Algebras differs in an order of magnitude to the number of statements and operations using the Versor and hep-ga library with a total of 1600 statements with 2077 operations.The reason for this difference is the use of expression templates in both Eigen and Adept and that the compiler is not able to reduce the generated expressions.This is a known limitation of the Adept library as presented in the Adept documentation 4 .Note that the hep-ga library is also based on expression templates.The matrix implementation were slowest in both automatic differentiation implementations.There were no significant differences using forward mode or reverse mode with the Adept library for these experiments as the size of the Jacobian were relatively small.

Multivector Estimation
This section presents experimental results from multivector estimation.Section 7.2.1 presents attitude estimation, that is, rotor estimation from unit (direction) vectors and Sect.7.2.2 presents motor estimation from point clouds.

Rotor Estimation.
Following the experimental setup in [39], the true vectors {a i } where a i ∈ R 1 3 for i ∈ {1, . . ., N} are Gaussian distributed unit vectors with a standard deviation σ = 0.8.The vectors {a i } are rotated by the ground truth rotor R to form the set {a i } where a i = Ra i R. Gaussian noise with standard deviation σ r is added to the rotated vectors a i .The resulting vectors are then normalized to form the set {b i }.
The cost function in (5.3) and the parameterization in (5.7) used in these experiments are implemented using the hep-ga library.Plots of the development in the cost function value in two experiments are shown in Fig. 1.The Levenberg-Marquardt method is able to estimate the rotor in 4 iterations, while the limited memory BFGS (L-BFGS) [36] method is able to estimate the rotor in 10 iterations.The Gaussian noise that was added to form the set {b i } had a standard deviation σ = 0.09.The initial rotor was set to the identity rotor R 0 = 1.The bivector exponential parameterization was used in both experiments.The Levenberg-Marquardt method was able to estimate the rotor in 4 iterations while the limited memory BFGS (L-BFGS) method was able to estimate the rotor in 10 iterations To compare the accuracy of our developed method with state of the art rotation estimation methods we compute the average mean and standard deviation of the root mean square (RMS) of the quality measure from 1000 experiments, where {a i } are the ground truth vector rotated by the estimated rotor R.
Our method is denoted rotor, the quaternion method shipped with Ceres [1] is denoted ceres-quaternion and the singular value decomposition based method presented in [47] is denoted umeyama.The results are presented in Table 5.Our rotor-method and the ceres-quaternion method perform equally.This is expected, as the only difference is that the ceres-quaternion method is implemented with the matrix representation of a quaternion, rather than the geometric algebra implementation in the rotor-method.Both nonlinear methods perform slightly better than the singular value decomposition based method.

Motor Estimation.
The optimization method used in this section is the Levenberg-Marquardt [33] method in combination with a dense QR linear solver.The focus is on the choice of cost function, the influence of the motor parameterization used and on the computational performance.All cost functions and parameterizations are implemented using the Versor library in combination with the automatic differentiation implementation in Ceres.Experimental results from motor estimation using 1000, 100000 and 1000000 observations are shown in Table 6.
Similarly to the experimental setup in the previous section, the true points {a i }, a i ∈ R 1 4,1 for i ∈ {1, . . ., n} are Gaussian distributed with a standard deviation σ = 0.8.The points {a i } are transformed by the ground truth motor M to form the set {a i } where a i = Ma i M .Gaussian noise with standard deviation σ r = 0.09 is added to the rotated points a i .The resulting points form the set {b i }.
The main difference between the two motor estimation formulations in (5.9) and (5.10) is that the formulation in (5.9) converges more slowly than (5.10) when close to the solution.The formulation in (5.9) converged in 26 iterations and the formulation in (5.10) converged in 4 iterations.The main reason for this difference is that the inner product based formulation in (5.9) employs only a measure for the total residual distance opposed to signed residual distances along each of the three coordinate axes in (5.10).These results were the same for all number of observations.
The choice of parameterization also influences the robustness and convergence rate of the optimization.The difference between the two parameterizations in Sect.5.2.1 is that the parameterization in (5.15), employing 6 parameters and the bivector exponential map, removes null directions in the update, that is, update directions normal to the motor manifold M. In contrast to this, when the parameterization in (5.14) is used, the updates can be in all directions of M. The use of the parameterization in (5.15) reduces the number of iterations from 5 to 4 when using the cost function in (5.10) employing 3 residuals per observation.It does not influence the convergence rate of the optimization when using the inner product based cost function in (5.9) with 1 residual per observation.
Even though the choice of parameterization did not influence the number of iterations when using the cost function in (5.9), it does influence the total time of the optimization.This reduction is also seen when using the cost function in (5.10).The reason for the time reduction is the reduction in the size of the Jacobian matrix, e.g., from a 3000000 × 8 Jacobian matrix in experiment 12 to a 3000000 × 6 Jacobian matrix in experiment 11, as seen in the two bottom rows of Table 6.This leads to a reduction in the time used to evaluate the Jacobian matrix and in the linear solver in each iteration.
The developed framework can be used to compute motors from large sets of observations.In practice, these observations would come from, e.g., RGB-D sensors.When estimating motors from synthetic datasets of 100000 points we were able to compute the correct motor in 4 iterations in 0.74 s when the number of OpenMP [10] threads available were set to 512 and from synthetic datasets of 1000000 points we were able to compute the correct motor in 4 iterations in 7.1343 s when the number of OpenMP [10] threads available were set to 2048.

Conclusion
In this work, we have presented automatic differentiation of multivector valued functions using 3 different implementations of geometric algebra and 2 different implementations of automatic differentiation and thus enabling automatic computations of gradient and Jacobian matrices for use in nonlinear least squares optimization.We have shown that our formulations perform equally well as state-of-the-art formulations for rotation estimation and we were able to estimate Euclidean rotors from noisy data in 4 iterations using the Levenberg-Marquardt optimization method.We have also presented motor estimation, that is, estimation of rigid body motions from noisy point data.We were able to estimate motors from 100000 point observations in 0.74 s and from 1000000 point observations in 7.1343 s, showing that our formulations scale well.
The presented formulations for multivector estimation can easily be expanded from estimation of rotors and motors using vectors and points to estimation of any transformation or object in the conformal model.The cost function can be arbitrary complex and difficult to differentiate analytically as all gradients and Jacobian matrices are computed using automatic differentiation.

Listing 4 .
Templated C++ code of the sandwich product b = Ra R where a, b, ∈ R 1 3 and R ∈ R + 3 for use in automatic differentiation implemented using the hep-ga [41] library Listing 5. Type alias for a conformal point p ∈ R 1 4,1 in the hep-ga [41] library 6.1.2.Multivector Based Implementations of Geometric Algebra.This section presents the two multivector based implementations of geometric algebra.

Figure 1 .
Figure1.Plot of the value of the cost function in each iteration of two rotor estimation experiments using 10 observations.The rotor to be found is R = cos(π/6) − sin(π/6)e 12 .The Gaussian noise that was added to form the set {b i } had a standard deviation σ = 0.09.The initial rotor was set to the identity rotor R 0 = 1.The bivector exponential parameterization was used in both experiments.The Levenberg-Marquardt method was able to estimate the rotor in 4 iterations while the limited memory BFGS (L-BFGS) method was able to estimate the rotor in 10 iterations Tingelstad and O. Egeland Adv.Appl.Clifford Algebras where Λ * ∈ span{e 12 , e 13 , e 23 , e 1 n ∞ , e 2 n ∞ , e 3 n ∞ } and
and O. Egeland Adv.Appl.Clifford Algebras Listing 7. Templated functor for use in the Ceres framework that implements the cost function in (5.10) the Versor library

Table 5 .
Experimental results from rotor estimation

Table 6 .
Experimental results from motor estimation