Geomstats: a Python Package for Riemannian Geometry in Machine Learning

1 INTRODUCTION . From soft-classification to image recognition , Riemannian manifolds provide a natural framework to many a machine learning problem . Consider the following standard supervised learning problem : given an input X , the goal is to predict an output Y . The relation between X and Y is typically modeled by a function fθ : X → Y , characterized by a set of parameters θ. Riemannian geometry often naturally arises at each of the three different stages of the modelization : through the input X , the output Y , or the parameters θ . For instance , the input X might belong to a Riemannian manifold . This is typically the case in image processing , where images X are frequently modeled as elements of a low-dimensional manifold ( 17 ; 57 ; 61 ; 67 ; 18 ; 6 ) . Such is the case in ( 62 ) , in which the authors consider spherical images as elements of the orthogonal rotation group SO ( 3 ) . In some cases , X can even be a manifold itself— in ( 8 ) for instance , the authors propose to model images as a function of a 2D smooth surface representing a shape such as a human pose . Similarly , the output Y often belongs to a Riemannian manifold ( 42 ; 47 ) . Such is the case in problems where the output is a member of the set of doubly stochastic matrices –as for instance in some neurosciences applications ( 48 ; 11 ) — . or when the optimization is carried on a given manifold ( 2 ; 44 ; 27 ) . In ( 28 ) for example , the authors use a neural network to predict the pose of a camera Y , which is defined as an element of the Lie group SE ( 3 ) . Finally , the parameter θ of a model can be constrained on a Riemannian manifold , such as in the work of ( 29 ) which constrains the weights of a neural network on multiple dependent Stiefel manifolds . Manifolds offer intuitive and practical advantages for modeling inputs , outputs and parameters . When applied to the input , they constitute lower dimensional spaces with fewer degrees of freedom , thus potentially allowing faster computations and less substantial memory allocation costs . Moreover , the non-linear degrees of freedom in these manifolds are often more intuitive and benefit from more expressive power . For instance , the geolocation of points of interest on Earth is more efficiently achieved through their longitude and latitude—i.e. , their 2D manifold coordinates—rather than through their position ( x , y , z ) in the 3D Cartesian space . Most current machine learning problems make little use of this underlying manifold structure —rather viewing their optimization task as a 1The package is provided in a zip file at the following anonymized address : https : //goo.gl/XV2Rb7 . constrained optimization over Euclidean space . Riemannian geometry , on the other hand , attempts to leverage the manifold structure to solve the corresponding optimization problem , replacing lines by geodesics , partial differential by covariate differentiation ( 59 ) — thus potentially reducing the dimension of the prblem space and the memory allocation costs . Yet , the adoption of Riemannian geometry by the machine learning community has been largely hindered by the lack of a modular framework for implementing such methods . Code sequences are often custom tailored for specific problems and/or computing backends , and are thus not easily re-usable : . To address this issue , some packages have been written to perform computations on manifolds . The theanogeometry package ( 39 ) provides an implementation of differential geometric tensors on manifolds where closed forms do not necessarily exist , using the automatic differentiation tool theano to integrate differential equations that define the geometric tensors . The pygeometry package ( 10 ) offers an implementation primarily focused on the Lie groups SO ( 3 ) and SE ( 3 ) for robotics applications . However , no implementation of non-canonical metrics on these Lie groups is provided . The pymanopt package ( 63 ) , originally implemented in Matlab as manopt , provides a very comprehensive toolbox for optimization on a extensive list of manifolds . However , not only is the choice of metrics on these manifolds rather restricted , the manifolds themselves are often implemented using canonical embeddings in higher-dimensional euclidean spaces , with high computational costs . This paper presents geomstats , a package specifically targeted at the machine learning community to perform computations on Riemannian manifolds with a flexible choice of Riemannian metrics . The geomstats package makes three contributions . First , geomstats is the first Riemannian geometry package to be extensively unit-tested with more than 90 % code coverage . Second , geomstats implements numpy ( 51 ) and tensorflow ( 1 ) backends , providing vectorized , intuitive computations , and available for GPU implementation . We also provide an updated version of the deep learning framework , keras , equipped with Riemannian gradient descent on manifolds . Finally , geomstats strives to be a user-friendly and educational a tool , presenting Riemannian geometry to computer scientists and facilitating its use as a complement to theoretical papers or books . We refer to ( 55 ) for the theory and expect the reader to have a high-level understanding of Riemannian geometry . Our paper is organized as follows . We begin by providing an overview of geomstats in Section 2 . We then present concrete use cases of geomstats for machine learning on manifolds of increasing geometric complexity , starting with manifolds embedded in flat spaces in Section 3 , to a manifold embedded in a Lie group with a Lie group action in Section 4 , to the Lie groups SO ( n ) and SE ( n ) in Section 5 . Along the way , we present a review of the occurrences of each manifold in the machine learning literature , some educational visualizations of the Riemannian geometry as well as implementations of machine learning models where the inputs , the outputs and the parameters successively belong to manifolds . 2 THE PACKAGE GEOMSTATS 2.1 GEOMETRY . The geomstats package implements Riemannian geometry through a natural objectoriented approach based on two main families of classes : the manifolds , inherited from the class Manifold and the Riemannian metrics , inherited from the class RiemannianMetric . Children classes of Manifold considered here include : LieGroup , EmbeddedManifold , SpecialOrthogonalGroup , SpecialEuclideanGroup , Hypersphere , HyperbolicSpace and SPDMatricesSpace . Once the user has specified an instance of Manifold , she or he must endow it with a particular choice of Riemanniann metric ; Instantiations of the RiemannianMetric class and its children classes are attributes of the manifold objects . The class RiemannianMetric implements the usual methods of Riemannian geometry , such as the inner product of two tangent vectors at a base point , the ( squared ) norm of a tangent vector at a base point , the ( squared ) distance between two points , the Riemannian Exponential and Logarithm maps at a base point and a geodesic characterized by an initial tangent vector at an initial point or by an initial point and an end point . Children classes of RiemannianMetric include the class InvariantMetric , which implements the left—and right—invariant metrics on Lie groups , as well as EuclideanMetric and MinkowskiMetric which are respectively the most standard flat Riemannian and pseudo-Riemannian metrics . Contrary to prior existing packages , our methods have been extensively unit-tested , with more than 90 % code coverage . The code is provided with numpy and tensorflow backends . Moreover , geomstats strives for efficiency : the code is vectorized through the use of arrays in order to facilitate intuitive batch computation . The tensorflow backend also enables running the computations on GPUs . 2.2 STATISTICS AND MACHINE LEARNING . The package geomstats also allows the user to easily perform statistical analysis on manifolds —specifically for Riemannian statistics— in the class RiemannianMetric ( 53 ) . The class RiemannianMetric implements the weighted Fréchet mean of a dataset through a Gauss-Newton gradient descent iteration ( 21 ) , the variance of a dataset with respect to a point on the manifold , as well as tangent principal component analysis ( 20 ) . This provides an easily and readily-applicable tool for analysts to investigate and define summary statistics from the Riemannian perspective . From a machine learning viewpoint , geomstats strives to facilitate the use of Riemannian geometry in machine learning and deep learning settings by providing easy and practical frameworks to incorporate manifold constraints into the optimization objective . Let us suppose for instance that we want to train a neural network to predict an output Y on the manifold of our choice . Geomstats provides off-the-shelf loss functions on Riemannian manifolds , implemented as squared geodesic distances between the predicted output and the ground truth . These loss functions are consistent with the geometric structure of the Riemannian manifold . The package gives the closed forms of the Riemannian gradients corresponding to these losses , so that back-propagation can be easily performed . Let us suppose now that we want to constrain the parameters of a model , such as the weights of a neural network , to belong to a manifold . We provide modified versions of keras and tensorflow , so that they can constrain weights on manifolds during training . As such , the availability of geomstats from many different computing backends , as well as its computational efficiency should greatly facilitate the use of Riemannian geometry in machine learning/ In the following sections , we demonstrate the use of the manifolds implemented in geomstats . For each manifold , we present a literature review of its appearance in machine learning and we describe its implementation in geomstats along with a concrete use case . 3 EMBEDDED MANIFOLDS - HYPERSPHERE AND HYPERBOLIC SPACE . We begin by considering the hypersphere and the hyperbolic space , often considered as the simplest and most standard Riemannian manifolds of constant curvature ( 55 ) . The manifolds are respectively implemented in the classes Hypersphere and HyperbolicSpace . The logic of the Riemannian structure of these two manifolds is very similar . They are both manifolds defined by their embedding in a flat Riemannian or pseudo-Riemannian manifold . To be more specific , the n-dimensional hypersphere Sn is defined by its embedding in the ( n+ 1 ) - Euclidean space , which is a flat Riemannian manifold , as Sn = { x ∈ Rn+1 : x21 + ... + x2n+1 = 1 } . ( 1 ) Similarly , the n-dimensional hyperbolic space Hn is defined by its embedding in the ( n + 1 ) - dimensional Minkowski space , which is a flat pseudo-Riemannian manifold , as Hn = { x ∈ Rn+1 : −x21 + ... + x2n+1 = −1 } . ( 2 ) The classes Hypersphere and HyperbolicSpace therefore inherit from the class EmbeddedManifold . They implement methods such as : conversion functions from intrinsic n-dimensional coordinates to extrinsic ( n+ 1 ) -dimensional coordinates in the embedding space ( and vice-versa ) ; projection of a point in the embedding space to the embedded manifold ; projection of a vector in the embedding space to a tangent space at the embedded manifold . The Riemannian metric defined on Sn is derived from the Euclidean metric in the embedding space , while the Riemannian metric defined on Hn is derived from the Minkowski metric in the embedding space . They are respectively implemented in the classes HypersphereMetric and HyperbolicMetric . 3.1 HYPERSPHERE - REVIEW OF USE CASES IN MACHINE LEARNING . The hypersphere naturally appears in a number of settings . In particular , hyperspheres are common objects in circular statistics ( 31 ) , directional statistics ( 45 ) or orientation statistics ( 16 ) , that is , areas which focus on the analysis of data on circles , spheres and rotation groups . Concrete applications are extremely diverse and range from biology to physics ( 49 ; 37 ; 32 ) or trajectory analysis ( 9 ; 40 ) among many others ( 46 ; 65 ) . In biology for instance , the sphere S2 is used in nalysis of protein structures ( 36 ) . In physics , the semi-hypersphere S4+ is used to encode the projective space P4 for representing crystal orientations in applied crystallography ( 56 ; 14 ) . The shape statistics literature ( 34 ) is also manipulating data on abstract hyperspheres . For instance , in ( 35 ) , the author studies shapes of k landmarks in m dimensions and introduces the `` pre-shape '' spaces which are hyperspheres Sm ( k−1 ) . The s-rep , a skeletal representation of 3D shapes , also deals with hyperspheres S3n−4 as the object under study is represented by n points along its boundary ( 26 ) . Lastly , hyperspheres can be used to constrain the parameters of a machine learning model . For example , training a neural net with parameters constrained on a hypersphere has been shown to result in an easier optimization , faster convergence and comparable ( even better ) classification accuracy ( 43 ) .

Summary: This paper introduces Geomstats, a geometric toolbox for machine learning on Riemannian manifolds. In comparison to previous packages such as manopt and pymanopt, the paper claims that the proposed software provide more efficient implementations, and is integrated with deep learning backends. Several potential applications settings for the software are explored, introducing some performance gains on specific problems when one resorts to the geometry of the space. An example setting for deep learning on SE(3) is also presented.