Package: fermat
Fermat distanceFermat is a Python library that computes the Fermat distance estimator (also called d-distance estimator) proposed inWeighted Geodesic Distance Following Fermat's Principle(seehttps://openreview.net/pdf?id=BJfaMIJwG).Nonhomogeneous Euclidean first-passage percolation and distance learning(seehttps://arxiv.org/abs/1810.09398)Table of contentsIntroductionInstallationImplementationClusteringFeaturesSupportFermat distance citationIntroductionA density-based estimator for weighted geodesic distances is proposed.
Let M be a D-dimensional manifold and consider a sample of N points X_n living in M. Let l(.,.) be a distance defined
in M (a typical choice could be Euclidean distance). For d>=1 and given two points p and q in M we define the Fermat
distance estimator asThe minimization is done over all K>=2 and all finite sequences of data points with x1= argmin l(x,p)
and xK = argmin l(x,q).When d=1, we recover the distance l(.,.) but if d>1, the Fermat distance tends to follow more closely the manifold
structure and regions with high density values.This distance is useful for clustering pourposes. Replacing Euclidean distance with Fermat distance in standard clustering alorithms leads to much better results.Installationpip install fermatImplementationThe optimization performed to compute the Fermat distance estimator runs all over the possible paths of points between each pair of points. We implement an algorithm that computes the exact Fermat distance and two that compute approximations.Exact: Floyd-WarshallPermorf theFloyd-Warshall algorithmthat gives the exact Fermat distance estimator inO( n^3 )operations between all possible paths that conects each pair of points.Aprox: Dijsktra + k-nearest neighboursWith probability arbitrary high we can restrict the minimum path search to paths where each consecutive pair of points are k-nearest neighbours, withk = O(log n). Then, we useDijkstra algorithmon the graph of k-nearest neighbours from each point. The complexity isO( n * ( k * n * log n ) ).Aprox: LandmarksIf the number of points n is too high and neither Floyd-Warshall and Dijkstra run in appropiate times, we implemente a gready version based on landmarks. Let consider a set of l of point in the data set (the landmarks) and denotes_jthe distance of the pointsto the landmarkj. Then, we can bound the distanced(s,t)between any two pointssandtaslower = max_j { | s_j - t_j | } <= d(s,t) <= min_j { s_j + t_j } = upperand estimated(s,t)as a function oflowerandupper(for example,d(s,t) ~ (_lower + upper_) / 2). The complexity isO( l * ( k * n * log n ) ).ClusteringThe tool FermatKmeans implements the K-medoids algorithm with Fermat distance as an input.Hereis an example explaining how to use it to compute clusters in MNIST datasetFeaturesExact and approximate algorithms to compute the Fermat distance.Examples explaining how to use this package.Quick startMNIST data set[Clustering using Fermat]DocumentationSupportIf you have an open-ended or a research question:'support@aristas.com.ar'Fermat distance citationFermat distance has been introduced and studied in the following papers@inproceedings{SGJ2018,
      title={Weighted Geodesic Distance Following Fermat's Principle},
      author={Facundo Sapienza and Pablo Groisman and Matthieu Jonckheere},
      year={2018},
      url={https://openreview.net/forum?id=BJfaMIJwG}
}

@article{GJS2018,
  title={Nonhomogeneous Euclidean first-passage percolation and distance learning},
  author={Groisman, Pablo and Jonckheere, Matthieu and Sapienza, Facundo},
  journal={arXiv preprint arXiv:1810.09398},
  year={2018}
}