Lab 1 — First persistence diagrams¶
Goal. Compute persistence diagrams of three point clouds (noisy circle, torus, two interlocked circles), plot them, and interpret which features survive across scales.
What you ship. Notebook with three persistence diagrams plus a 200-word interpretation in markdown explaining what the H_0 and H_1 bars tell you about each shape.
Setup¶
Install the dependencies (one-time).
In [ ]:
# !pip install ripser persim matplotlib numpy
In [ ]:
import numpy as np
import matplotlib.pyplot as plt
from ripser import ripser
from persim import plot_diagrams
rng = np.random.default_rng(42)
Datasets — three synthetic point clouds¶
We build the data inline so the lab is reproducible without external downloads.
In [ ]:
def noisy_circle(n=200, r=1.0, noise=0.05):
theta = rng.uniform(0, 2*np.pi, n)
pts = np.column_stack([r*np.cos(theta), r*np.sin(theta)])
pts += noise * rng.normal(size=pts.shape)
return pts
def noisy_torus(n=400, R=1.5, r=0.5, noise=0.03):
u = rng.uniform(0, 2*np.pi, n)
v = rng.uniform(0, 2*np.pi, n)
x = (R + r*np.cos(v)) * np.cos(u)
y = (R + r*np.cos(v)) * np.sin(u)
z = r * np.sin(v)
pts = np.column_stack([x, y, z])
return pts + noise * rng.normal(size=pts.shape)
def two_circles(n=300, sep=2.5, noise=0.05):
c1 = noisy_circle(n//2)
c2 = noisy_circle(n//2) + np.array([sep, 0.0])
return np.vstack([c1, c2])
X_circle = noisy_circle()
X_torus = noisy_torus()
X_two = two_circles()
print('circle:', X_circle.shape, 'torus:', X_torus.shape, 'two:', X_two.shape)
Exercise 1 — Compute and plot the three diagrams¶
In [ ]:
for name, X in [('circle', X_circle), ('torus', X_torus), ('two_circles', X_two)]:
result = ripser(X, maxdim=1)
fig, ax = plt.subplots(figsize=(5,5))
plot_diagrams(result['dgms'], ax=ax)
ax.set_title(f'{name}')
plt.show()
Exercise 2 — Interpret¶
In [ ]:
# YOUR TURN
# Write a short markdown cell below each plot that answers:
# - How many H_0 bars are long-lived in each diagram? Why?
# - How many H_1 bars survive to high persistence? Why?
# - Where are the noisy features sitting in the diagram?
Exercise 3 — Stretch goal¶
In [ ]:
# YOUR TURN
# Increase the noise parameter on the circle. At what level does the
# H_1 feature stop being clearly separated from the diagonal?
# Document the noise level you found and explain in 2-3 sentences.
Done?¶
Submit per the cohort schedule. Peer review pairing announced the following Monday.