Skip to main content

Fermat distance

Fermat is a Python library that computes the Fermat distance estimator (also called d-distance estimator) proposed in

Table of contents

  1. Introduction
  2. Installation
  3. Implementation
  4. Clustering
  5. Features
  6. Support
  7. Fermat distance citation

Introduction


A 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 as

The 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.

Installation

pip install fermat

Implementation


The 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-Warshall

Permorf the Floyd-Warshall algorithm that gives the exact Fermat distance estimator in O( n^3 ) operations between all possible paths that conects each pair of points.

  • Aprox: Dijsktra + k-nearest neighbours

With probability arbitrary high we can restrict the minimum path search to paths where each consecutive pair of points are k-nearest neighbours, with k = O(log n). Then, we use Dijkstra algorithm on the graph of k-nearest neighbours from each point. The complexity is O( n * ( k * n * log n ) ).

  • Aprox: Landmarks

If 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 denote s_j the distance of the point s to the landmark j. Then, we can bound the distance d(s,t) between any two points s and t as

lower = max_j { | s_j - t_j | } <= d(s,t) <= min_j { s_j + t_j } = upper

and estimate d(s,t) as a function of lower and upper (for example, d(s,t) ~ (_lower + upper_) / 2 ). The complexity is O( l * ( k * n * log n ) ).

Clustering

The tool FermatKmeans implements the K-medoids algorithm with Fermat distance as an input. Here is an example explaining how to use it to compute clusters in MNIST dataset

Features


Support


If you have an open-ended or a research question:

  • 'support@aristas.com.ar'

Fermat distance citation


Fermat 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}
}	

Metadata

Release files for fermat 0.2.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for fermat 0.2.7
File Interpreter ABI Platform
fermat-0.2.7-py3-none-any.whl Python 3 none any Details

Release files / fermat-0.2.7-py3-none-any.whl

Download URL fermat-0.2.7-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7215b47cd95cf86c4ee4af0e8f2addae12f28c36a796e3ef992ca51121bbd2b
BLAKE2b-256 checksum
How to use checksums
0783629bc0f20d7b45248f952fd1dfefddaa0f237b429503d7a0cff3a89446bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9

Release history Release notifications | RSS feed

This release

0.2.7 This release

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.2

1 release file

0.2.0

1 release file

0.1.0

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page