A native PyTorch implementation of PersLay for persistence diagrams.
Project description
torchPersLay
torchPersLay is a native PyTorch implementation of PersLay, a neural-network layer for persistence diagrams in topological data analysis. The package is published on PyPI as torchPersLay; the Python import package is perslay.
This repository focuses on PersLay-style persistence-image features with learnable point weights and Gaussian bandwidths. Earlier DeepSet experiment code has been removed to keep the package focused on the successful PersLay implementation.
Installation
Install the released package from PyPI:
pip install torchperslay
Install the local repository in editable mode:
git clone https://github.com/jhnrckmnznrs/torchPersLay.git
cd torchPersLay
pip install -e .
To run the experiment scripts in this repository, also install the experiment extra or the repository requirements:
pip install -e ".[experiments]"
# or
pip install -r requirements.txt
Quick start
The example below builds a PersLay regressor for a small batch of padded persistence diagrams. Diagrams are expected as (birth, death) pairs with shape [batch, num_points, 2].
import torch
from perslay import (
GaussianPerslayPhi,
NormalizedLearnablePowerPerslayWeight,
Perslay,
)
from perslay.models import FlattenRho
image_size = [10, 10]
image_bnds = [[0.0, 1.0], [0.0, 1.0]] # birth bounds, persistence bounds
weight = NormalizedLearnablePowerPerslayWeight(image_bnds=image_bnds)
phi = GaussianPerslayPhi(
image_size=image_size,
image_bnds=image_bnds,
sigma_x=0.1,
sigma_y=0.1,
normalize=False,
)
perslay = Perslay(
weight=weight,
phi=phi,
perm_op=torch.sum,
rho=FlattenRho(),
)
# Two padded diagrams with three points each.
diagrams = torch.tensor(
[
[[0.0, 0.4], [0.2, 0.8], [0.0, 0.0]],
[[0.1, 0.5], [0.3, 0.9], [0.4, 0.95]],
],
dtype=torch.float32,
)
mask = torch.tensor(
[
[True, True, False],
[True, True, True],
]
)
features = perslay(diagrams, mask=mask)
print(features.shape) # torch.Size([2, 100])
Regression models
For most regression experiments, use the provided model wrappers:
from perslay.models import PerslayRegressor, MultiPerslayRegressor
model = PerslayRegressor(
image_size=[20, 20],
image_bnds=[[0.0, 1.0], [0.0, 1.0]],
sigma_x=0.05,
sigma_y=0.05,
hidden_dim=128,
weight_type="normalized_learnable_power",
)
Available weight_type values are:
constantlearnable_powernormalized_learnable_powermlp
MultiPerslayRegressor supports multiple homology dimensions or multiple diagram sources per sample. See experiments/configs/h0_h2_regression.yaml for an example configuration.
Repository layout
src/perslay/
data.py Dataset and collate utilities for persistence-diagram CSV files
layers.py PersLay layers, feature maps, and point-weight functions
models.py Single-branch and multi-branch PersLay regressors
experiments/
train_regression.py Config-driven regression training script
configs/degree2_regression.yaml
configs/h0_h2_regression.yaml
Running experiments
Prepare persistence diagram CSV files with columns similar to:
birth,death
0.1,0.4
0.2,0.8
Prepare a target CSV with:
filename,target
sample_001.csv,3.14
Then run:
python experiments/train_regression.py --config experiments/configs/degree2_regression.yaml
For multi-diagram input, use:
python experiments/train_regression.py --config experiments/configs/h0_h2_regression.yaml
Training writes checkpoints and resolved configs under the configured output.run_dir.
Citation
If you use this package in research, please cite the original PersLay paper:
Mathieu Carrière, Frédéric Chazal, Yuichi Ike, Théo Lacombe, Martin Royer, and Yuhei Umeda. PersLay: A Neural Network Layer for Persistence Diagrams and New Graph Topological Signatures. AISTATS 2020, PMLR 108:2786–2796.
License
This project is distributed under the MIT License. See LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchperslay-0.1.5.tar.gz.
File metadata
- Download URL: torchperslay-0.1.5.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df1b35484640af27032a0421287e56cd27460b334a0d35577166a0ce9c3c1185
|
|
| MD5 |
f78548fc8b946f147c8feebc5219a877
|
|
| BLAKE2b-256 |
80b60a3767a9f843e314dc899d6535e4ae2c27b66b9eda9eae339371b4717cfc
|
File details
Details for the file torchperslay-0.1.5-py3-none-any.whl.
File metadata
- Download URL: torchperslay-0.1.5-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9f5b27838b6c4b94497a88460b16828043a522e3ac0e3474cce97066b899587
|
|
| MD5 |
7d7566f50d28637a3cbf30a45469fea3
|
|
| BLAKE2b-256 |
c9be56105c3cc9e3b6a64a7444c271d9a32122fbbc9fb216fdb4d0f752bbb60d
|