Bertrand MICHEL - Introduction to Topological Data AnalysisPractical lessons with Gudhi PythonWe will follow the tutorial python notebooks of Gudhi. Part 1: Data, Filtrations and Persistence DiagramsRead the first two paragraphs (with the corresponding notebooks) of the tutorial main page.
ExercicesExercise 1. Recall the torus is the surface which is homeomorphic to the surface obtained by identifying the opposite sides of a square as illustrated on the Figure below.
Using Gudhi, construct a triangulation ( Exercise 2. The goal of this exercise is to illustrate the persistence stability theorem for functions on a very simple example. The code below allows to define a simplicial complex (the so-called n_pts = 1000 #Build a random set of points in the unit square X = np.random.rand(n_pts,2) #Compute the alpha-complex filtration alpha_complex = gd.AlphaComplex(points=X) st_alpha = alpha_complex.create_simplex_tree(max_alpha_square=1000.0) Let a) Build on such a simplicial complex the sublevel set filtration of the function ![]() and compute its persistence diagrams in dimension b) Compute the persistence diagrams of random perturbations of Exercise 3. Sensor Data Download the data_acc.dat dataset at this adress address. Then load it using the pickle module: import numpy as np import pickle as pickle import gudhi as gd from mpl_toolkits.mplot3d import Axes3D f = open("data_acc.dat","rb") data = pickle.load(f,encoding="latin1") f.close() data_A = data[0] data_B = data[1] data_C = data[2] label = data[3] The walk of 3 persons A, B and C, has been recorded using the accelerometer sensor of a smartphone in their pocket, giving rise to 3 multivariate time series in 1. Plot a few of the time series to get an idea of the corresponding point clouds in data_A_sample = data_A[0] plt.gca(projection='3d') plt.plot(data_A_sample [:,0],data_A_sample [:,1],data_A_sample [:,2] ) 2. Compute and plot the persistence diagrams of the Vietoris-Rips and the alpha-complex filtrations, for a few examples of the time series. 3. Compute the from sklearn import manifold # B is the pairwise distance matrix between 0 or 1-dim dgms #label_color contains the colors corresponding to the class of each dgm mds = manifold.MDS(n_components=3, max_iter=3000, eps=1e-9, dissimilarity="precomputed", n_jobs=1) pos1 = mds.fit(B1).embedding_ fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(pos1[:,0], pos1[:, 1], pos1[:,2], marker = 'o', color=label_color) 4. Use the function below to embed the data in dimension def sliding_window_data(x,edim,delay=1): """time delay embedding of a d-dim times series into R^{d*edim} the time series is assumed to be periodic parameters: + x: a list of d lists of same length L or a dxL numpy array + edim: the number of points taken to build the embedding in R^{d*edim} + delay: embeeding given by (x[i],x[i+delay],..., x[i + (edim-1)*delay]) Default value for delay is 1 """ ts = np.asarray(x) if len(np.shape(ts)) == 1: ts = np.reshape(ts,(1,ts.shape[0])) ts_d = ts.shape[0] ts_length = ts.shape[1] #output = zeros((edim*ts_d,nb_pt)) output = ts for i in range(edim-1): output = np.concatenate((output,np.roll(ts,-(i+1)*delay,axis=1)),axis=0) return output Part 2: TDA and StatisticsFor many applications of persistent homology, we observe topological features close to the diagonal. Since they correspond to topological structures that die very soon after they appear in the filtration, these points are generally considered as “topological noise”. Confidence regions for persistence diagram provide a rigorous framework to this idea. This notebook introduces the subsampling approach of Fasy et al. 2014 AoS. Part 3: Representations of TDA and Machine LearningIn this notebook, we learn how to use alternative representations of persistence with the representations module and finally we see a first example of how to efficiently combine machine learning and topological data analysis. This notebook illustrates Perslay: a neural network layer for persistence diagrams and new graph topological signatures. Exercise 4. Sensor Data By computing representations of persistence to train a classifier on the Sensor Data of Exercice 3. Part 4: Mapper with GudhiThis notebook illustrates the use of Mapper. If you want to run it, you have to install the Mapper branch of the Gudhi library! (soon merged in Gudhi). Alternatively, you can try Mapper with R. |