Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
A Topology Layer for Machine Learning : Persistent Homology + Features for PyTorch
| Date | Stars |
|---|---|
| 2026-07-31 | 430 |
| 2026-08-05 | 430 |
| 2026-08-06 | 430 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
# TopologyLayer
[Rickard Brüel Gabrielsson](http://bruel.org/), Bradley J. Nelson, Anjan Dwaraknath, Primoz Skraba, Leonidas J. Guibas, and Gunnar Carlsson
[[arXiv](https://arxiv.org/abs/1905.12200)]
AISTATS 2020
### Citation
```
@misc{brüelgabrielsson2020topology,
title={A Topology Layer for Machine Learning},
author={Rickard Brüel-Gabrielsson and Bradley J. Nelson and Anjan Dwaraknath and Primoz Skraba and Leonidas J. Guibas and Gunnar Carlsson},
year={2020},
eprint={1905.12200},
}
```
### Introduction
Build Status: [](https://travis-ci.com/bruel-gabrielsson/TopologyLayer)
This repository contains a Python package that implements PyTorch-compatible persistent homology layers, as well as featurization of the output.
For an introduction to this topic, see the paper **A Topology Layer for Machine Learning**, [arxiv:1905.12200](https://arxiv.org/abs/1905.12200)
### Point Cloud Optimization
In this example, we increase the size of holes in a random point cloud. [full source](examples/pointcloud/holes.py)
```python
from topologylayer.nn import AlphaLayer, BarcodePolyFeature
import torch, numpy as np, matplotlib.pyplot as plt
# random pointcloud
np.random.seed(0)
data = np.random.rand(100, 2)
# optimization to increase size of holes
layer = AlphaLayer(maxdim=1)
x = torch.autograd.Variable(torch.tensor(data).type(torch.float), requires_grad=True)
f1 = BarcodePolyFeature(1,2,0)
optimizer = torch.optim.Adam([x], lr=1e-2)
for i in range(100):
optimizer.zero_grad()
loss = -f1(layer(x))
loss.backward()
optimizer.step()
```

### Level Set Optimization
In this example, we use level set topology to regularize a least squares problem `y = X * beta + noise`. [full source](examples/levelset/noisy_circle.py)
```python
import torch, torch.nn as nn, numpy as np, matplotlib.pyplot as plt
from topologylayer.nn import LevelSetLayer2D, SumBarcodeLengths, PartialSumBarcodeLengths
# see full source for setup of problem
# X, y, and beta_ols are created
class TopLoss(nn.Module):
def __init__(self, size):
super(TopLoss, self).__init__()
self.pdfn = LevelSetLayer2D(size=size, sublevel=False)
self.topfn = PartialSumBarcodeLengths(dim=1, skip=1) # penalize more than 1 hole
self.topfn2 = SumBarcodeLengths(dim=0) # penalize more than 1 max
def forward(self, beta):
dgminfo = self.pdfn(beta)
return self.topfn(dgminfo) + self.topfn2(dgminfo)
tloss = TopLoss((50,50)) # topology penalty
dloss = nn.MSELoss() # data loss
beta_t = torch.autograd.Variable(torch.tensor(beta_ols).type(torch.float), requires_grad=True)
X_t = torch.tensor(X, dtype=torch.float, requires_grad=False)
y_t = torch.tensor(y, dtype=torch.float, requires_grad=False)
optimizer = torch.optim.Adam([beta_t], lr=1e-2)
for i in range(500):
optimizer.zero_grad()
loss = 0.1*tloss(beta_t) + dloss(y_t, torch.matmul(X_t, beta_t.view(-1)))
loss.backward()
optimizer.step()
```

# Get Started
Dependencies:
* Python (2 or 3)
* NumPy
* SciPy
* PyTorch 1.0+
## Installation using pip
Assuming you have the listed dependencies and pip, you should be able to install.
```bash
pip install git+https://github.com/bruel-gabrielsson/TopologyLayer.git
```
If you're having issues, see [troubleshooting notes](#troubleshooting-installation) below. __MacOS__ users will likely need to see this section to set some necessary environment variables.
## (Optional) Conda Environment Configuration
First, create a conda environment
```bash
conda create -n toplayer # python=2 or python=3
source activate toplayer
```
Now, add dependencies
```bash
conda install numpy scipy matplotlib
conda install pytorch torchvision -c pytorch
```
Now, you can install the TopologyLayer package.
```bash
pip Excerpt of 16,946 characters
Read on GitHubWould you bet a product on this? Bounded 0–100 and slow moving.
matched fp:eecbf88898f36f10, llm:description: 'A Topology Layer for Machine Learning : Persistent Homology + Features for PyTorch' (repository description)
matched fp:eecbf88898f36f10, llm:description: 'A Topology Layer for Machine Learning : Persistent Homology + Features for PyTorch' (repository description)
matched fp:eecbf88898f36f10, llm:description: 'A Topology Layer for Machine Learning : Persistent Homology + Features for PyTorch' (repository description)