Skip to content

IsHubolla/Matching-distance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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) and dB(g_i, g_j) for component functions f and g
  • Bottleneck distances dB(\phi*_i, \phi*_j) for linear combinations of f and g
  • 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:

  1. Computes the vertex values of each f_i and g_i
  2. Normalizes them by a common infinity norm
  3. Computes persistence diagrams for each f_i and g_i and their combinations needed to compute the matching distances
  4. Computes pairwise distances and matching distances between all the possible pairs \Phi_i, \Phi_j and ave them in matrices
  5. Outputs all distance matrices and key parameters to a timestamped text file

Requirements

  • Python 3.7+
  • NumPy
  • SciPy
  • persim (part of scikit-tda)
  • phat for persistence diagram computation

Install all dependencies via:

pip install -r requirements.txt

File 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

  1. Place your OFF model files in the data/ directory. Name them as 1.off, 2.off, etc.

  2. In main.py:

    • Write the explicit expression of the components f and g of the biparametric filtering function considered.
    • Adjust the MODNAMES range 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:

    • f given by the x component, g given by the y component;
    • OFF file already contained in the data/ directory;
    • n = 5
  3. Run the script:

python main.py
  1. The output will be saved to a timestamped file in the output/ directory.

Output

The script generates:

  • Four symmetric distance matrices:
    • dB_f for f_i
    • dB_g for g_i
    • dB_ab for 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 max dB_ab used 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]

About

Python implementation for computing the 2D matching distance and bottleneck distances between multivariate functions on triangulated surfaces.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages