1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/usr/bin/env python
import gudhi
import matplotlib.pyplot as plt
import time
""" This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
Author(s): Vincent Rouvreau
Copyright (C) 2016 Inria
Modification(s):
- YYYY/MM Author: Description of the modification
"""
__author__ = "Vincent Rouvreau"
__copyright__ = "Copyright (C) 2020 Inria"
__license__ = "MIT"
print("#####################################################################")
print("RipsComplex (only the one-skeleton) creation from tore3D_300.off file")
off_file = gudhi.__root_source_dir__ + '/data/points/tore3D_300.off'
point_cloud = gudhi.read_points_from_off_file(off_file = off_file)
rips_complex = gudhi.RipsComplex(points=point_cloud, max_edge_length=12.0)
simplex_tree = rips_complex.create_simplex_tree(max_dimension=1)
result_str = '1. Rips complex is of dimension ' + repr(simplex_tree.dimension()) + ' - ' + \
repr(simplex_tree.num_simplices()) + ' simplices - ' + \
repr(simplex_tree.num_vertices()) + ' vertices.'
print(result_str)
# Expansion of this one-skeleton would require a lot of memory. Let's collapse it
start = time.process_time()
simplex_tree.collapse_edges()
simplex_tree.expansion(3)
diag = simplex_tree.persistence()
print("Collapse, expansion and persistence computation took ", time.process_time() - start, " sec.")
result_str = '2. Rips complex is of dimension ' + repr(simplex_tree.dimension()) + ' - ' + \
repr(simplex_tree.num_simplices()) + ' simplices - ' + \
repr(simplex_tree.num_vertices()) + ' vertices.'
print(result_str)
# Use subplots to display diagram and density side by side
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(12, 5))
gudhi.plot_persistence_diagram(diag, axes=axes[0])
axes[0].set_title("Persistence after 1 collapse")
# Collapse can be performed several times. Let's collapse it 3 times
start = time.process_time()
simplex_tree.collapse_edges(nb_iterations = 3)
simplex_tree.expansion(3)
diag = simplex_tree.persistence()
print("Collapse, expansion and persistence computation took ", time.process_time() - start, " sec.")
result_str = '3. Rips complex is of dimension ' + repr(simplex_tree.dimension()) + ' - ' + \
repr(simplex_tree.num_simplices()) + ' simplices - ' + \
repr(simplex_tree.num_vertices()) + ' vertices.'
print(result_str)
gudhi.plot_persistence_diagram(diag, axes=axes[1])
axes[1].set_title("Persistence after 3 more collapses")
# Plot the 2 persistence diagrams side to side to check the persistence is the same
plt.show()
|