IsHubolla/Matching-distance
Python implementation for computing the 2D matching distance and bottleneck distances between multivariate functions on triangulated surfaces.
Matching Distance Computation for 2D Functions on Triangulated Surfaces
This repository contains Python code to compute various distances between functions defined on triangulated surfaces, specifically:
- Bottleneck distances
dB(f_i, f_j)anddB(g_i, g_j)for component functionsfandg - Bottleneck distances
dB(\phi*_i, \phi*_j)for linear combinations offandg - Matching distance between multivariate functions
\Phi_i := (f_i, g_i)
References
This code is inspired by the following research articles:
- F. Cagliari, B. Di Fabio, M. Ferri. A new algorithm for computing the 2-dimensional matching distance between size functions, Journal of Mathematical Imaging and Vision, 2013.
- A. Cerri, B. Di Fabio, M. Ferri, P. Frosini. A new approximation algorithm for the matching distance in multidimensional persistence, Journal of Computational Geometry, 2013.
The current implementation is a simplified version and serves as a foundation toward integrating the full algorithms described in the above papers.
Description
Consider a collection of models X_i (triangulated surfaces), two scalar functions f, g (e.g. the x coordinate and the y coordinate, respectively) and denote with f_i, g_i their applications to the model X_i, \Phi_i := (f_i, g_i). The aim of this program is to compute the matching distances between all the possible pairs \Phi_i, \Phi_j. In particular, this program:
- Computes the vertex values of each
f_iandg_i - Normalizes them by a common infinity norm
- Computes persistence diagrams for each
f_iandg_iand their combinations needed to compute the matching distances - Computes pairwise distances and matching distances between all the possible pairs
\Phi_i,\Phi_jand ave them in matrices - Outputs all distance matrices and key parameters to a timestamped text file
Requirements
- Python 3.7+
- NumPy
- SciPy
persim(part ofscikit-tda)phatfor persistence diagram computation
Install all dependencies via:
pip install -r requirements.txtFile Structure
project_root/
│
├── main.py # Main computation script (formerly named verbosely)
├── requirements.txt # Dependencies
├── README.md # This file
├── LICENSE # MIT License file
├── output/ # Folder where results are saved
├── data/ # Folder with input OFF models
├── vertex_componenti/ # Folder with vertex values of f and g
├── vertex_phi_ab/ # Folder with combined function values
├── PDs_componenti/ # Folder with persistence diagrams of f and g
├── PDs_phi_ab/ # Folder with persistence diagrams of \phi*_ab
How to Use
-
Place your OFF model files in the
data/directory. Name them as1.off,2.off, etc. -
In
main.py:- Write the explicit expression of the components
fandgof the biparametric filtering function considered. - Adjust the
MODNAMESrange to match your model indices. - Choose the parameter
n, which will be used to choose 1/(2^n) uniform values in the foliation parameter intervals.
The default values are:
fgiven by the x component,ggiven by the y component;- OFF file already contained in the
data/directory; n= 5
- Write the explicit expression of the components
-
Run the script:
python main.py- The output will be saved to a timestamped file in the
output/directory.
Output
The script generates:
- Four symmetric distance matrices:
dB_fforf_idB_gforg_idB_abfor combined functions\phi*_ab- Matching distance matrix
- The value of parameters used (
n,C,h, etc.) - For each model pair, the
(a,b)that realizes the maxdB_abused in the matching distance
📄 License
This project is licensed under the MIT License © 2025 Isabella Mastroianni.
Author
Isabella Mastroianni - [isabella.mastroianni@ge.imati.cnr.it]