This repository contains a PyTorch implementation of the experiments from the paper Learning Distances from Data with Normalizing Flows and Score Matching. It presents a method for computing Fermat distances, a type of density-based distance where shortest paths follow the data manifold, using a relaxation algorithm.
/
├── cpp_dijkstra/
│ ├── [Python package for C++ implementation of Dijkstra's algorithm]
├── fermat_distance/
│ ├── fermat_distance/
│ │ ├── [Python package containing three core files for computing Fermat distances]
│ ├── experiments/
│ │ ├── script.py # Creates and runs experiments
Clone this repository and install the dependencies:
git clone https://github.com/vislearn/Fermat-Distance.git
cd Fermat-Distance
pip install -r requirements.txt
# Install the C++ Dijkstra package
cd cpp_dijkstra
pip install .
cd ..
# Install the Fermat distance package
cd fermat_distance
pip install .Then you can import the package via
import fermat_distancepython script.py --config [config file]For an example configuration file, see configs/spiral_energy.yaml
Optional flags include:
--skip-data: Skip data creation--skip-training: Skip model training--skip-graphs: Skip graph creation--skip-eval: Skip evaluation step--score-relaxation: Calculate geodesics using a score model