# Persistence Images¶

Persistence Images were first introduced in Adams et al, 2017. Much of this work, an examples contained herein are inspired by the work of Obayashi and Hiraoka, 2017. Choices of weightings and general methods are often derived from Kusano, Fukumizu, and Yasuaki Hiraoka, 2016.

In [1]:

from itertools import product

import numpy as np
from sklearn import datasets
from scipy.stats import multivariate_normal as mvn
import matplotlib.pyplot as plt

from ripser import Rips
from persim import PersImage


## Generate persistence diagram using Ripser¶

In [2]:

# lots of random noise and 2 circles
data = np.concatenate([150 * np.random.random((300,2)),
10 + 10 * datasets.make_circles(n_samples=100)[0],
100 + 20 * datasets.make_circles(n_samples=100)[0]])

rips = Rips()
dgms = rips.fit_transform(data)

plt.figure(figsize=(10,5))
plt.subplot(121)
plt.scatter(data[:,0], data[:,1], s=4)
plt.title("Scatter plot of noisy data with some circles")

plt.subplot(122)
rips.plot(dgms, legend=False, show=False)
plt.title("Persistence diagram of $H_0$ and $H_1$")
plt.show()

Rips(maxdim=1, thresh=inf, coeff=2, do_cocycles=False, verbose=True)


## Persistence Images with various pixels¶

In [3]:

pim = PersImage(spread=1, pixels=[10,10], verbose=False)
img = pim.transform(dgms[1])

ax = plt.subplot(131)
plt.title("PI for $H_1$\nwith 10x10 pixels")
pim.show(img, ax)

img = pim.transform(dgms[1])

ax = plt.subplot(132)
plt.title("PI for $H_1$\nwith 50x50 pixels")
pim.show(img, ax)

img = pim.transform(dgms[1])

ax = plt.subplot(133)
plt.title("PI for $H_1$\nwith 100x100 pixels")
pim.show(img, ax)

plt.tight_layout()


Spread determines the standard deviate of the Gaussian kernel used.

In [4]:

pim = PersImage(spread=0.5, verbose=False)
img = pim.transform(dgms[1])

ax = plt.subplot(131)
plt.title("PI for $H_1$\nSpread=0.5")
pim.show(img, ax)

img = pim.transform(dgms[1])

ax = plt.subplot(132)
plt.title("PI for $H_1$\nSpread=1")
pim.show(img, ax)

plt.title("PI for $H_1$\nSpread=2")

In [ ]: