Using ToMaTo with GUDHI¶

To download this notebook or its html/pdf version:

http://geometrica.saclay.inria.fr/team/Fred.Chazal/MVA2024.html

In [1]:
import numpy as np
import gudhi as gd
import random as rd
import matplotlib.pyplot as plt

%matplotlib inline

ToMaTo Clustering¶

This first part is not an exercise, just an illustration of the persistence-based clustering algorithm ToMaTo!

Gudhi provides an implementation of the persistence-based clustering algorithm ToMaTo.

See here for the documentation:

http://gudhi.gforge.inria.fr/python/latest/clustering.html

In [2]:
nb_pts=1000
angles = np.random.rand(2*nb_pts,1)
noisy_circle =\
    (1+ 0.2*np.random.normal(size=(2*nb_pts,2))) * np.concatenate([np.cos(2*np.pi*angles),np.sin(2*np.pi*angles)],axis=1)

gauss1 = 0.2 * np.random.normal(size=(nb_pts,2))
gauss2 = [1.5,1.5] + 0.3 * np.random.normal(size=(nb_pts,2))
data = np.concatenate([noisy_circle, gauss1, gauss2], axis=0)
plt.scatter(data[:,0],data[:,1],marker='.',s=1)
plt.show()
In [3]:
from gudhi.clustering.tomato import Tomato
t = Tomato(k=20)
t.fit(data)
t.plot_diagram()
In [4]:
t.n_clusters_=3
plt.scatter(data[:,0],data[:,1],marker='.',s=1,c=t.labels_)
plt.show()
In [5]:
t = Tomato(density_type='DTM', k=30, k_DTM=100)
t.fit(data)
t.plot_diagram()
In [6]:
t.n_clusters_= 3
plt.scatter(data[:,0],data[:,1],marker='.',s=1,c=t.labels_)
plt.show()

Documentation for the latest version of Gudhi:

http://gudhi.gforge.inria.fr/python/latest/

In [ ]: