This is a very lightweight library that hides all the headaches of extracting representative cycles from persistence diagrams.
cyclonysus currently sits on top of Dionysus, but hides almost everything from you. All you have to worry about is your numpy arrays.
There are no guarantees that this library is fast, well written, or correct. If you find issues, please create a github issue or pull request. It is currently only tested for 1-cycles.
This library is a wrapper around Dionysus and Dionysus requires Boost to work properly. If you have Boost, then you can install cyclonysus easily.
git clone https://github.com/sauln/cyclonysus
pip install -e .
First, construct a diagram. In this example, we will use Ripser.
Create one big noise circle and a noisy blob nearby.
import numpy as np
from sklearn import datasets
data, _ = datasets.make_circles(40)
data = np.concatenate([data,np.random.random((30,2))+3])
Then, we'll generate the persistence diagram for
from cyclonysus import Cycler
cycler = Cycler()
cycler.fit(data)
top_intervals = cycler.longest_intervals(3)
cycles = [cycler.get_cycle(interval) for interval in top_intervals]
vertex_sets = [cycler.order_vertices(cycle) for cycle in cycles]
Using ripser
, the generated persistence diagram looks like
Let's take a look at the cycles we generated overlaid on the original data. In the image below, the longest interval corresponds to the cycle around the main circle, just as we would expect.
# Plot cycle
for vertices in vertex_sets:
xs_v, ys_v = data[vertices][:,0], data[vertices][:,1]
plt.plot(xs_v, ys_v)
# Plot data
xs, ys = data[:,0], data[:,1]
plt.scatter(xs, ys)
plt.show()
Checkout the notebook Computing Cycles.ipynb for an executable example.