Giter Site home page Giter Site logo

cyclonysus's Introduction

Build Status codecov License: MIT

cyclonysus

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.

Setup

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 .

Usage

First, construct a diagram. In this example, we will use Ripser.

First generate some data.

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])

raw data, one noise circle with another blob nearby

Then, we'll generate the persistence diagram for $H_1$ for this data. Using persistence diagram, we can extract the longest 3 cycles and vertex sets of each cycle.

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

persistence diagram for H1. One point far from the diagonal

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()

multiple cycles on dataset

Checkout the notebook Computing Cycles.ipynb for an executable example.

cyclonysus's People

Watchers

James Cloos avatar Naheed avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.