summaryrefslogtreecommitdiff
path: root/src/python/example
diff options
context:
space:
mode:
Diffstat (limited to 'src/python/example')
-rwxr-xr-xsrc/python/example/alpha_complex_diagram_persistence_from_off_file_example.py68
-rwxr-xr-xsrc/python/example/alpha_complex_from_points_example.py55
-rwxr-xr-xsrc/python/example/alpha_rips_persistence_bottleneck_distance.py105
-rwxr-xr-xsrc/python/example/bottleneck_basic_example.py37
-rwxr-xr-xsrc/python/example/coordinate_graph_induced_complex.py68
-rwxr-xr-xsrc/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py83
-rwxr-xr-xsrc/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py82
-rwxr-xr-xsrc/python/example/functional_graph_induced_complex.py69
-rwxr-xr-xsrc/python/example/gudhi_graphical_tools_example.py43
-rwxr-xr-xsrc/python/example/nerve_of_a_covering.py70
-rwxr-xr-xsrc/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py74
-rwxr-xr-xsrc/python/example/random_cubical_complex_persistence_example.py49
-rwxr-xr-xsrc/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py87
-rwxr-xr-xsrc/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py63
-rwxr-xr-xsrc/python/example/rips_complex_diagram_persistence_from_off_file_example.py72
-rwxr-xr-xsrc/python/example/rips_complex_from_points_example.py27
-rwxr-xr-xsrc/python/example/rips_persistence_diagram.py30
-rwxr-xr-xsrc/python/example/simplex_tree_example.py51
-rwxr-xr-xsrc/python/example/sparse_rips_persistence_diagram.py32
-rwxr-xr-xsrc/python/example/tangential_complex_plain_homology_from_off_file_example.py64
-rwxr-xr-xsrc/python/example/voronoi_graph_induced_complex.py65
-rwxr-xr-xsrc/python/example/witness_complex_from_nearest_landmark_table.py36
22 files changed, 1330 insertions, 0 deletions
diff --git a/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py b/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py
new file mode 100755
index 00000000..b8f283b3
--- /dev/null
+++ b/src/python/example/alpha_complex_diagram_persistence_from_off_file_example.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="AlphaComplex creation from " "points read in a OFF file.",
+ epilog="Example: "
+ "example/alpha_complex_diagram_persistence_from_off_file_example.py "
+ "-f ../data/points/tore3D_300.off -a 0.6"
+ "- Constructs a alpha complex with the "
+ "points from the given OFF file.",
+)
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument("-a", "--max_alpha_square", type=float, default=0.5)
+parser.add_argument("-b", "--band", type=float, default=0.0)
+parser.add_argument(
+ "--no-diagram",
+ default=False,
+ action="store_true",
+ help="Flag for not to display the diagrams",
+)
+
+args = parser.parse_args()
+
+with open(args.file, "r") as f:
+ first_line = f.readline()
+ if (first_line == "OFF\n") or (first_line == "nOFF\n"):
+ print("#####################################################################")
+ print("AlphaComplex creation from points read in a OFF file")
+
+ message = "AlphaComplex with max_edge_length=" + repr(args.max_alpha_square)
+ print(message)
+
+ alpha_complex = gudhi.AlphaComplex(off_file=args.file)
+ simplex_tree = alpha_complex.create_simplex_tree(
+ max_alpha_square=args.max_alpha_square
+ )
+
+ message = "Number of simplices=" + repr(simplex_tree.num_simplices())
+ print(message)
+
+ diag = simplex_tree.persistence()
+
+ print("betti_numbers()=")
+ print(simplex_tree.betti_numbers())
+
+ if args.no_diagram == False:
+ pplot = gudhi.plot_persistence_diagram(diag, band=args.band)
+ pplot.show()
+ else:
+ print(args.file, "is not a valid OFF file")
+
+ f.close()
diff --git a/src/python/example/alpha_complex_from_points_example.py b/src/python/example/alpha_complex_from_points_example.py
new file mode 100755
index 00000000..a746998c
--- /dev/null
+++ b/src/python/example/alpha_complex_from_points_example.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+
+from gudhi import AlphaComplex, SimplexTree
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+print("#####################################################################")
+print("AlphaComplex creation from points")
+alpha_complex = AlphaComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]])
+simplex_tree = alpha_complex.create_simplex_tree(max_alpha_square=60.0)
+
+if simplex_tree.find([0, 1]):
+ print("[0, 1] Found !!")
+else:
+ print("[0, 1] Not found...")
+
+if simplex_tree.find([4]):
+ print("[4] Found !!")
+else:
+ print("[4] Not found...")
+
+if simplex_tree.insert([0, 1, 2], filtration=4.0):
+ print("[0, 1, 2] Inserted !!")
+else:
+ print("[0, 1, 2] Not inserted...")
+
+if simplex_tree.insert([0, 1, 4], filtration=4.0):
+ print("[0, 1, 4] Inserted !!")
+else:
+ print("[0, 1, 4] Not inserted...")
+
+if simplex_tree.find([4]):
+ print("[4] Found !!")
+else:
+ print("[4] Not found...")
+
+print("dimension=", simplex_tree.dimension())
+print("filtrations=", simplex_tree.get_filtration())
+print("star([0])=", simplex_tree.get_star([0]))
+print("coface([0], 1)=", simplex_tree.get_cofaces([0], 1))
+
+print("point[0]=", alpha_complex.get_point(0))
+print("point[5]=", alpha_complex.get_point(5))
diff --git a/src/python/example/alpha_rips_persistence_bottleneck_distance.py b/src/python/example/alpha_rips_persistence_bottleneck_distance.py
new file mode 100755
index 00000000..086307ee
--- /dev/null
+++ b/src/python/example/alpha_rips_persistence_bottleneck_distance.py
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+import math
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="AlphaComplex and RipsComplex "
+ "persistence creation from points read in "
+ "a OFF file. Bottleneck distance computation"
+ " on each dimension",
+ epilog="Example: "
+ "example/alpha_rips_persistence_bottleneck_distance.py "
+ "-f ../data/points/tore3D_1307.off -t 0.15 -d 3",
+)
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument("-t", "--threshold", type=float, default=0.5)
+parser.add_argument("-d", "--max_dimension", type=int, default=1)
+
+args = parser.parse_args()
+with open(args.file, "r") as f:
+ first_line = f.readline()
+ if (first_line == "OFF\n") or (first_line == "nOFF\n"):
+ point_cloud = gudhi.read_off(off_file=args.file)
+ print("#####################################################################")
+ print("RipsComplex creation from points read in a OFF file")
+
+ message = "RipsComplex with max_edge_length=" + repr(args.threshold)
+ print(message)
+
+ rips_complex = gudhi.RipsComplex(
+ points=point_cloud, max_edge_length=args.threshold
+ )
+
+ rips_stree = rips_complex.create_simplex_tree(max_dimension=args.max_dimension)
+
+ message = "Number of simplices=" + repr(rips_stree.num_simplices())
+ print(message)
+
+ rips_diag = rips_stree.persistence()
+
+ print("#####################################################################")
+ print("AlphaComplex creation from points read in a OFF file")
+
+ message = "AlphaComplex with max_edge_length=" + repr(args.threshold)
+ print(message)
+
+ alpha_complex = gudhi.AlphaComplex(points=point_cloud)
+ alpha_stree = alpha_complex.create_simplex_tree(
+ max_alpha_square=(args.threshold * args.threshold)
+ )
+
+ message = "Number of simplices=" + repr(alpha_stree.num_simplices())
+ print(message)
+
+ alpha_diag = alpha_stree.persistence()
+
+ max_b_distance = 0.0
+ for dim in range(args.max_dimension):
+ # Alpha persistence values needs to be transform because filtration
+ # values are alpha square values
+ funcs = [math.sqrt, math.sqrt]
+ alpha_intervals = []
+ for interval in alpha_stree.persistence_intervals_in_dimension(dim):
+ alpha_intervals.append(
+ map(lambda func, value: func(value), funcs, interval)
+ )
+
+ rips_intervals = rips_stree.persistence_intervals_in_dimension(dim)
+ bottleneck_distance = gudhi.bottleneck_distance(
+ rips_intervals, alpha_intervals
+ )
+ message = (
+ "In dimension "
+ + repr(dim)
+ + ", bottleneck distance = "
+ + repr(bottleneck_distance)
+ )
+ print(message)
+ max_b_distance = max(bottleneck_distance, max_b_distance)
+
+ print(
+ "================================================================================"
+ )
+ message = "Bottleneck distance is " + repr(max_b_distance)
+ print(message)
+
+ else:
+ print(args.file, "is not a valid OFF file")
+
+ f.close()
diff --git a/src/python/example/bottleneck_basic_example.py b/src/python/example/bottleneck_basic_example.py
new file mode 100755
index 00000000..392d2a6e
--- /dev/null
+++ b/src/python/example/bottleneck_basic_example.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+import gudhi
+
+""" 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__ = "Francois Godi, Vincent Rouvreau"
+__copyright__ = "Copyright (C) 2016 Inria"
+__license__ = "MIT"
+
+diag1 = [[2.7, 3.7], [9.6, 14.0], [34.2, 34.974], [3.0, float("Inf")]]
+
+diag2 = [[2.8, 4.45], [9.5, 14.1], [3.2, float("Inf")]]
+
+message = "diag1=" + repr(diag1)
+print(message)
+
+message = "diag2=" + repr(diag2)
+print(message)
+
+message = "Bottleneck distance approximation=" + repr(
+ gudhi.bottleneck_distance(diag1, diag2, 0.1)
+)
+print(message)
+
+message = "Bottleneck distance exact value=" + repr(
+ gudhi.bottleneck_distance(diag1, diag2)
+)
+print(message)
diff --git a/src/python/example/coordinate_graph_induced_complex.py b/src/python/example/coordinate_graph_induced_complex.py
new file mode 100755
index 00000000..e32141b4
--- /dev/null
+++ b/src/python/example/coordinate_graph_induced_complex.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+""" 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) 2018 Inria
+
+ Modification(s):
+ - YYYY/MM Author: Description of the modification
+"""
+
+__author__ = "Vincent Rouvreau"
+__copyright__ = "Copyright (C) 2018 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="Coordinate GIC " "from points read in a OFF file.",
+ epilog="Example: "
+ "example/coordinate_graph_induced_complex.py "
+ "-f ../data/points/KleinBottle5D.off -c 0 -v"
+ "- Constructs the coordinate GIC with the "
+ "points from the given OFF file.",
+)
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument("-c", "--coordinate", type=int, default=0)
+parser.add_argument(
+ "-v",
+ "--verbose",
+ default=False,
+ action="store_true",
+ help="Flag for program verbosity",
+)
+
+args = parser.parse_args()
+
+nerve_complex = gudhi.CoverComplex()
+nerve_complex.set_verbose(args.verbose)
+
+if nerve_complex.read_point_cloud(args.file):
+ nerve_complex.set_type("GIC")
+ nerve_complex.set_color_from_coordinate(args.coordinate)
+ nerve_complex.set_function_from_coordinate(args.coordinate)
+ nerve_complex.set_graph_from_automatic_rips()
+ nerve_complex.set_automatic_resolution()
+ nerve_complex.set_gain()
+ nerve_complex.set_cover_from_function()
+ nerve_complex.find_simplices()
+ nerve_complex.plot_dot()
+ simplex_tree = nerve_complex.create_simplex_tree()
+ nerve_complex.compute_PD()
+ if args.verbose:
+ print("Iterator on coordinate GIC simplices")
+ result_str = (
+ "Coordinate GIC is of dimension "
+ + repr(simplex_tree.dimension())
+ + " - "
+ + repr(simplex_tree.num_simplices())
+ + " simplices - "
+ + repr(simplex_tree.num_vertices())
+ + " vertices."
+ )
+ print(result_str)
+ for filtered_value in simplex_tree.get_filtration():
+ print(filtered_value[0])
diff --git a/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py b/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py
new file mode 100755
index 00000000..610ba44f
--- /dev/null
+++ b/src/python/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="EuclideanStrongWitnessComplex creation from "
+ "points read in a OFF file.",
+ epilog="Example: "
+ "example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py "
+ "-f ../data/points/tore3D_300.off -a 1.0 -n 20 -d 2"
+ "- Constructs a strong witness complex with the "
+ "points from the given OFF file.",
+)
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument("-a", "--max_alpha_square", type=float, required=True)
+parser.add_argument("-n", "--number_of_landmarks", type=int, required=True)
+parser.add_argument("-d", "--limit_dimension", type=int, required=True)
+parser.add_argument("-b", "--band", type=float, default=0.0)
+parser.add_argument(
+ "--no-diagram",
+ default=False,
+ action="store_true",
+ help="Flag for not to display the diagrams",
+)
+
+args = parser.parse_args()
+
+with open(args.file, "r") as f:
+ first_line = f.readline()
+ if (first_line == "OFF\n") or (first_line == "nOFF\n"):
+ print("#####################################################################")
+ print("EuclideanStrongWitnessComplex creation from points read in a OFF file")
+
+ witnesses = gudhi.read_off(off_file=args.file)
+ landmarks = gudhi.pick_n_random_points(
+ points=witnesses, nb_points=args.number_of_landmarks
+ )
+
+ message = (
+ "EuclideanStrongWitnessComplex with max_edge_length="
+ + repr(args.max_alpha_square)
+ + " - Number of landmarks="
+ + repr(args.number_of_landmarks)
+ )
+ print(message)
+
+ witness_complex = gudhi.EuclideanStrongWitnessComplex(
+ witnesses=witnesses, landmarks=landmarks
+ )
+ simplex_tree = witness_complex.create_simplex_tree(
+ max_alpha_square=args.max_alpha_square, limit_dimension=args.limit_dimension
+ )
+
+ message = "Number of simplices=" + repr(simplex_tree.num_simplices())
+ print(message)
+
+ diag = simplex_tree.persistence()
+
+ print("betti_numbers()=")
+ print(simplex_tree.betti_numbers())
+
+ if args.no_diagram == False:
+ pplot = gudhi.plot_persistence_diagram(diag, band=args.band)
+ pplot.show()
+ else:
+ print(args.file, "is not a valid OFF file")
+
+ f.close()
diff --git a/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py b/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py
new file mode 100755
index 00000000..7587b732
--- /dev/null
+++ b/src/python/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="EuclideanWitnessComplex creation from " "points read in a OFF file.",
+ epilog="Example: "
+ "example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py "
+ "-f ../data/points/tore3D_300.off -a 1.0 -n 20 -d 2"
+ "- Constructs a weak witness complex with the "
+ "points from the given OFF file.",
+)
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument("-a", "--max_alpha_square", type=float, required=True)
+parser.add_argument("-n", "--number_of_landmarks", type=int, required=True)
+parser.add_argument("-d", "--limit_dimension", type=int, required=True)
+parser.add_argument("-b", "--band", type=float, default=0.0)
+parser.add_argument(
+ "--no-diagram",
+ default=False,
+ action="store_true",
+ help="Flag for not to display the diagrams",
+)
+
+args = parser.parse_args()
+
+with open(args.file, "r") as f:
+ first_line = f.readline()
+ if (first_line == "OFF\n") or (first_line == "nOFF\n"):
+ print("#####################################################################")
+ print("EuclideanWitnessComplex creation from points read in a OFF file")
+
+ witnesses = gudhi.read_off(off_file=args.file)
+ landmarks = gudhi.pick_n_random_points(
+ points=witnesses, nb_points=args.number_of_landmarks
+ )
+
+ message = (
+ "EuclideanWitnessComplex with max_edge_length="
+ + repr(args.max_alpha_square)
+ + " - Number of landmarks="
+ + repr(args.number_of_landmarks)
+ )
+ print(message)
+
+ witness_complex = gudhi.EuclideanWitnessComplex(
+ witnesses=witnesses, landmarks=landmarks
+ )
+ simplex_tree = witness_complex.create_simplex_tree(
+ max_alpha_square=args.max_alpha_square, limit_dimension=args.limit_dimension
+ )
+
+ message = "Number of simplices=" + repr(simplex_tree.num_simplices())
+ print(message)
+
+ diag = simplex_tree.persistence()
+
+ print("betti_numbers()=")
+ print(simplex_tree.betti_numbers())
+
+ if args.no_diagram == False:
+ pplot = gudhi.plot_persistence_diagram(diag, band=args.band)
+ pplot.show()
+ else:
+ print(args.file, "is not a valid OFF file")
+
+ f.close()
diff --git a/src/python/example/functional_graph_induced_complex.py b/src/python/example/functional_graph_induced_complex.py
new file mode 100755
index 00000000..8b645040
--- /dev/null
+++ b/src/python/example/functional_graph_induced_complex.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+""" 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) 2018 Inria
+
+ Modification(s):
+ - YYYY/MM Author: Description of the modification
+"""
+
+__author__ = "Vincent Rouvreau"
+__copyright__ = "Copyright (C) 2018 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="Functional GIC " "from points read in a OFF file.",
+ epilog="Example: "
+ "example/functional_graph_induced_complex.py "
+ "-o ../data/points/COIL_database/lucky_cat.off "
+ "-f ../data/points/COIL_database/lucky_cat_PCA1"
+ "- Constructs the functional GIC with the "
+ "points from the given OFF and function files.",
+)
+parser.add_argument("-o", "--off-file", type=str, required=True)
+parser.add_argument("-f", "--function-file", type=str, required=True)
+parser.add_argument(
+ "-v",
+ "--verbose",
+ default=False,
+ action="store_true",
+ help="Flag for program verbosity",
+)
+
+args = parser.parse_args()
+
+nerve_complex = gudhi.CoverComplex()
+nerve_complex.set_verbose(args.verbose)
+
+if nerve_complex.read_point_cloud(args.off_file):
+ nerve_complex.set_type("GIC")
+ nerve_complex.set_color_from_file(args.function_file)
+ nerve_complex.set_function_from_file(args.function_file)
+ nerve_complex.set_graph_from_automatic_rips()
+ nerve_complex.set_automatic_resolution()
+ nerve_complex.set_gain()
+ nerve_complex.set_cover_from_function()
+ nerve_complex.find_simplices()
+ nerve_complex.plot_dot()
+ simplex_tree = nerve_complex.create_simplex_tree()
+ nerve_complex.compute_PD()
+ if args.verbose:
+ print("Iterator on functional GIC simplices")
+ result_str = (
+ "Functional GIC is of dimension "
+ + repr(simplex_tree.dimension())
+ + " - "
+ + repr(simplex_tree.num_simplices())
+ + " simplices - "
+ + repr(simplex_tree.num_vertices())
+ + " vertices."
+ )
+ print(result_str)
+ for filtered_value in simplex_tree.get_filtration():
+ print(filtered_value[0])
diff --git a/src/python/example/gudhi_graphical_tools_example.py b/src/python/example/gudhi_graphical_tools_example.py
new file mode 100755
index 00000000..3b0ca54d
--- /dev/null
+++ b/src/python/example/gudhi_graphical_tools_example.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+
+import gudhi
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+print("#####################################################################")
+print("Show barcode persistence example")
+
+persistence = [
+ (2, (1.0, float("inf"))),
+ (1, (1.4142135623730951, float("inf"))),
+ (1, (1.4142135623730951, float("inf"))),
+ (0, (0.0, float("inf"))),
+ (0, (0.0, 1.0)),
+ (0, (0.0, 1.0)),
+ (0, (0.0, 1.0)),
+]
+gudhi.plot_persistence_barcode(persistence)
+
+print("#####################################################################")
+print("Show diagram persistence example")
+
+pplot = gudhi.plot_persistence_diagram(persistence)
+pplot.show()
+
+print("#####################################################################")
+print("Show diagram persistence example with a confidence band")
+
+pplot = gudhi.plot_persistence_diagram(persistence, band=0.2)
+pplot.show()
diff --git a/src/python/example/nerve_of_a_covering.py b/src/python/example/nerve_of_a_covering.py
new file mode 100755
index 00000000..3c8e0f90
--- /dev/null
+++ b/src/python/example/nerve_of_a_covering.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+""" 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) 2018 Inria
+
+ Modification(s):
+ - YYYY/MM Author: Description of the modification
+"""
+
+__author__ = "Vincent Rouvreau"
+__copyright__ = "Copyright (C) 2018 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="Nerve of a covering creation " "from points read in a OFF file.",
+ epilog="Example: "
+ "example/nerve_of_a_covering.py "
+ "-f ../data/points/human.off -c 2 -r 10 -g 0.3"
+ "- Constructs Nerve of a covering with the "
+ "points from the given OFF file.",
+)
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument("-c", "--coordinate", type=int, default=0)
+parser.add_argument("-r", "--resolution", type=int, default=10)
+parser.add_argument("-g", "--gain", type=float, default=0.3)
+parser.add_argument(
+ "-v",
+ "--verbose",
+ default=False,
+ action="store_true",
+ help="Flag for program verbosity",
+)
+
+args = parser.parse_args()
+
+nerve_complex = gudhi.CoverComplex()
+nerve_complex.set_verbose(args.verbose)
+
+if nerve_complex.read_point_cloud(args.file):
+ nerve_complex.set_type("Nerve")
+ nerve_complex.set_color_from_coordinate(args.coordinate)
+ nerve_complex.set_function_from_coordinate(args.coordinate)
+ nerve_complex.set_graph_from_OFF()
+ nerve_complex.set_resolution_with_interval_number(args.resolution)
+ nerve_complex.set_gain(args.gain)
+ nerve_complex.set_cover_from_function()
+ nerve_complex.find_simplices()
+ nerve_complex.write_info()
+ simplex_tree = nerve_complex.create_simplex_tree()
+ nerve_complex.compute_PD()
+ if args.verbose:
+ print("Iterator on graph induced complex simplices")
+ result_str = (
+ "Nerve is of dimension "
+ + repr(simplex_tree.dimension())
+ + " - "
+ + repr(simplex_tree.num_simplices())
+ + " simplices - "
+ + repr(simplex_tree.num_vertices())
+ + " vertices."
+ )
+ print(result_str)
+ for filtered_value in simplex_tree.get_filtration():
+ print(filtered_value[0])
diff --git a/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py b/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py
new file mode 100755
index 00000000..9cb855cd
--- /dev/null
+++ b/src/python/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+
+def is_file_perseus(file):
+ num_lines = open(file).read().count("\n")
+ try:
+ f = open(file)
+ num_dim = int(f.readline())
+ coeff = 1
+ for dim in range(0, num_dim):
+ try:
+ line = int(f.readline())
+ coeff *= abs(line)
+ except ValueError:
+ return False
+ if num_lines == (1 + num_dim + coeff):
+ return True
+ else:
+ return False
+ except ValueError:
+ return False
+
+
+parser = argparse.ArgumentParser(
+ description="Periodic cubical complex from a " "Perseus-style file name.",
+ epilog="Example: "
+ "./periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py"
+ " -f ../data/bitmap/CubicalTwoSphere.txt",
+)
+
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument(
+ "--no-barcode",
+ default=False,
+ action="store_true",
+ help="Flag for not to display the barcodes",
+)
+
+args = parser.parse_args()
+
+if is_file_perseus(args.file):
+ print("#####################################################################")
+ print("PeriodicCubicalComplex creation")
+ periodic_cubical_complex = gudhi.PeriodicCubicalComplex(perseus_file=args.file)
+
+ print("persistence(homology_coeff_field=3, min_persistence=0)=")
+ diag = periodic_cubical_complex.persistence(
+ homology_coeff_field=3, min_persistence=0
+ )
+ print(diag)
+
+ print("betti_numbers()=")
+ print(periodic_cubical_complex.betti_numbers())
+ if args.no_barcode == False:
+ gudhi.plot_persistence_barcode(diag)
+else:
+ print(args.file, "is not a valid perseus style file")
diff --git a/src/python/example/random_cubical_complex_persistence_example.py b/src/python/example/random_cubical_complex_persistence_example.py
new file mode 100755
index 00000000..da0eb177
--- /dev/null
+++ b/src/python/example/random_cubical_complex_persistence_example.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+
+import gudhi
+import numpy
+from functools import reduce
+import argparse
+import operator
+
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="Random cubical complex.",
+ epilog="Example: "
+ "./random_cubical_complex_persistence_example.py"
+ " 10 10 10 - Constructs a random cubical "
+ "complex in a dimension [10, 10, 10] (aka. "
+ "1000 random top dimensional cells).",
+)
+parser.add_argument("dimension", type=int, nargs="*", help="Cubical complex dimensions")
+
+args = parser.parse_args()
+dimension_multiplication = reduce(operator.mul, args.dimension, 1)
+
+if dimension_multiplication > 1:
+ print("#####################################################################")
+ print("CubicalComplex creation")
+ cubical_complex = gudhi.CubicalComplex(
+ dimensions=args.dimension,
+ top_dimensional_cells=numpy.random.rand(dimension_multiplication),
+ )
+
+ print("persistence(homology_coeff_field=2, min_persistence=0)=")
+ print(cubical_complex.persistence(homology_coeff_field=2, min_persistence=0))
+
+ print("betti_numbers()=")
+ print(cubical_complex.betti_numbers())
diff --git a/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py b/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py
new file mode 100755
index 00000000..3571580b
--- /dev/null
+++ b/src/python/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+
+import gudhi
+import sys
+import argparse
+
+""" 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) 2017 Inria
+
+ Modification(s):
+ - YYYY/MM Author: Description of the modification
+"""
+
+__author__ = "Vincent Rouvreau"
+__copyright__ = "Copyright (C) 2017 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="RipsComplex creation from " "a correlation matrix read in a csv file.",
+ epilog="Example: "
+ "example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py "
+ "-f ../data/correlation_matrix/lower_triangular_correlation_matrix.csv -e 12.0 -d 3"
+ "- Constructs a Rips complex with the "
+ "correlation matrix from the given csv file.",
+)
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument("-c", "--min_edge_correlation", type=float, default=0.5)
+parser.add_argument("-d", "--max_dimension", type=int, default=1)
+parser.add_argument("-b", "--band", type=float, default=0.0)
+parser.add_argument(
+ "--no-diagram",
+ default=False,
+ action="store_true",
+ help="Flag for not to display the diagrams",
+)
+
+args = parser.parse_args()
+
+if not (-1.0 < args.min_edge_correlation < 1.0):
+ print("Wrong value of the treshold corelation (should be between -1 and 1).")
+ sys.exit(1)
+
+print("#####################################################################")
+print("Caution: as persistence diagrams points will be under the diagonal,")
+print("bottleneck distance and persistence graphical tool will not work")
+print("properly, this is a known issue.")
+
+print("#####################################################################")
+print("RipsComplex creation from correlation matrix read in a csv file")
+
+message = "RipsComplex with min_edge_correlation=" + repr(args.min_edge_correlation)
+print(message)
+
+correlation_matrix = gudhi.read_lower_triangular_matrix_from_csv_file(
+ csv_file=args.file
+)
+# Given a correlation matrix M, we compute component-wise M'[i,j] = 1-M[i,j] to get a distance matrix:
+distance_matrix = [
+ [1.0 - correlation_matrix[i][j] for j in range(len(correlation_matrix[i]))]
+ for i in range(len(correlation_matrix))
+]
+
+rips_complex = gudhi.RipsComplex(
+ distance_matrix=distance_matrix, max_edge_length=1.0 - args.min_edge_correlation
+)
+simplex_tree = rips_complex.create_simplex_tree(max_dimension=args.max_dimension)
+
+message = "Number of simplices=" + repr(simplex_tree.num_simplices())
+print(message)
+
+diag = simplex_tree.persistence()
+
+print("betti_numbers()=")
+print(simplex_tree.betti_numbers())
+
+# invert the persistence diagram
+invert_diag = [
+ (diag[pers][0], (1.0 - diag[pers][1][0], 1.0 - diag[pers][1][1]))
+ for pers in range(len(diag))
+]
+
+if args.no_diagram == False:
+ pplot = gudhi.plot_persistence_diagram(invert_diag, band=args.band)
+ pplot.show()
diff --git a/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py b/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py
new file mode 100755
index 00000000..0b9a9ba9
--- /dev/null
+++ b/src/python/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="RipsComplex creation from " "a distance matrix read in a csv file.",
+ epilog="Example: "
+ "example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py "
+ "-f ../data/distance_matrix/lower_triangular_distance_matrix.csv -e 12.0 -d 3"
+ "- Constructs a Rips complex with the "
+ "distance matrix from the given csv file.",
+)
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument("-e", "--max_edge_length", type=float, default=0.5)
+parser.add_argument("-d", "--max_dimension", type=int, default=1)
+parser.add_argument("-b", "--band", type=float, default=0.0)
+parser.add_argument(
+ "--no-diagram",
+ default=False,
+ action="store_true",
+ help="Flag for not to display the diagrams",
+)
+
+args = parser.parse_args()
+
+print("#####################################################################")
+print("RipsComplex creation from distance matrix read in a csv file")
+
+message = "RipsComplex with max_edge_length=" + repr(args.max_edge_length)
+print(message)
+
+distance_matrix = gudhi.read_lower_triangular_matrix_from_csv_file(csv_file=args.file)
+rips_complex = gudhi.RipsComplex(
+ distance_matrix=distance_matrix, max_edge_length=args.max_edge_length
+)
+simplex_tree = rips_complex.create_simplex_tree(max_dimension=args.max_dimension)
+
+message = "Number of simplices=" + repr(simplex_tree.num_simplices())
+print(message)
+
+diag = simplex_tree.persistence()
+
+print("betti_numbers()=")
+print(simplex_tree.betti_numbers())
+
+if args.no_diagram == False:
+ pplot = gudhi.plot_persistence_diagram(diag, band=args.band)
+ pplot.show()
diff --git a/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py b/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py
new file mode 100755
index 00000000..2b335bba
--- /dev/null
+++ b/src/python/example/rips_complex_diagram_persistence_from_off_file_example.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="RipsComplex creation from " "points read in a OFF file.",
+ epilog="Example: "
+ "example/rips_complex_diagram_persistence_from_off_file_example.py "
+ "-f ../data/points/tore3D_300.off -a 0.6"
+ "- Constructs a Rips complex with the "
+ "points from the given OFF file.",
+)
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument("-e", "--max_edge_length", type=float, default=0.5)
+parser.add_argument("-d", "--max_dimension", type=int, default=1)
+parser.add_argument("-b", "--band", type=float, default=0.0)
+parser.add_argument(
+ "--no-diagram",
+ default=False,
+ action="store_true",
+ help="Flag for not to display the diagrams",
+)
+
+args = parser.parse_args()
+
+with open(args.file, "r") as f:
+ first_line = f.readline()
+ if (first_line == "OFF\n") or (first_line == "nOFF\n"):
+ print("#####################################################################")
+ print("RipsComplex creation from points read in a OFF file")
+
+ message = "RipsComplex with max_edge_length=" + repr(args.max_edge_length)
+ print(message)
+
+ point_cloud = gudhi.read_off(off_file=args.file)
+ rips_complex = gudhi.RipsComplex(
+ points=point_cloud, max_edge_length=args.max_edge_length
+ )
+ simplex_tree = rips_complex.create_simplex_tree(
+ max_dimension=args.max_dimension
+ )
+
+ message = "Number of simplices=" + repr(simplex_tree.num_simplices())
+ print(message)
+
+ diag = simplex_tree.persistence()
+
+ print("betti_numbers()=")
+ print(simplex_tree.betti_numbers())
+
+ if args.no_diagram == False:
+ pplot = gudhi.plot_persistence_diagram(diag, band=args.band)
+ pplot.show()
+ else:
+ print(args.file, "is not a valid OFF file")
+
+ f.close()
diff --git a/src/python/example/rips_complex_from_points_example.py b/src/python/example/rips_complex_from_points_example.py
new file mode 100755
index 00000000..59d8a261
--- /dev/null
+++ b/src/python/example/rips_complex_from_points_example.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+import gudhi
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+print("#####################################################################")
+print("RipsComplex creation from points")
+rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], max_edge_length=42)
+
+simplex_tree = rips.create_simplex_tree(max_dimension=1)
+
+print("filtrations=", simplex_tree.get_filtration())
+print("star([0])=", simplex_tree.get_star([0]))
+print("coface([0], 1)=", simplex_tree.get_cofaces([0], 1))
diff --git a/src/python/example/rips_persistence_diagram.py b/src/python/example/rips_persistence_diagram.py
new file mode 100755
index 00000000..f5897d7b
--- /dev/null
+++ b/src/python/example/rips_persistence_diagram.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+
+import gudhi
+
+""" 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__ = "Marc Glisse"
+__copyright__ = "Copyright (C) 2016 Inria"
+__license__ = "MIT"
+
+print("#####################################################################")
+print("RipsComplex creation from points")
+rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], max_edge_length=42)
+
+simplex_tree = rips.create_simplex_tree(max_dimension=1)
+
+
+diag = simplex_tree.persistence(homology_coeff_field=2, min_persistence=0)
+print("diag=", diag)
+
+pplot = gudhi.plot_persistence_diagram(diag)
+pplot.show()
diff --git a/src/python/example/simplex_tree_example.py b/src/python/example/simplex_tree_example.py
new file mode 100755
index 00000000..30de00da
--- /dev/null
+++ b/src/python/example/simplex_tree_example.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+import gudhi
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+print("#####################################################################")
+print("SimplexTree creation from insertion")
+
+st = gudhi.SimplexTree()
+
+if st.insert([0, 1]):
+ print("Inserted !!")
+else:
+ print("Not inserted...")
+
+if st.find([0, 1]):
+ print("Found !!")
+else:
+ print("Not found...")
+
+if st.insert([0, 1, 2], filtration=4.0):
+ print("Inserted !!")
+else:
+ print("Not inserted...")
+
+print("dimension=", st.dimension())
+
+st.initialize_filtration()
+print("filtration=", st.get_filtration())
+print("filtration[1, 2]=", st.filtration([1, 2]))
+print("filtration[4, 2]=", st.filtration([4, 2]))
+
+print("num_simplices=", st.num_simplices())
+print("num_vertices=", st.num_vertices())
+
+print("skeleton[2]=", st.get_skeleton(2))
+print("skeleton[1]=", st.get_skeleton(1))
+print("skeleton[0]=", st.get_skeleton(0))
diff --git a/src/python/example/sparse_rips_persistence_diagram.py b/src/python/example/sparse_rips_persistence_diagram.py
new file mode 100755
index 00000000..671d5e34
--- /dev/null
+++ b/src/python/example/sparse_rips_persistence_diagram.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+import gudhi
+
+""" 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) 2018 Inria
+
+ Modification(s):
+ - YYYY/MM Author: Description of the modification
+"""
+
+__author__ = "Marc Glisse"
+__copyright__ = "Copyright (C) 2018 Inria"
+__license__ = "MIT"
+
+print("#####################################################################")
+print("Sparse RipsComplex creation from points")
+rips = gudhi.RipsComplex(
+ points=[[0, 0], [0, 0.1], [1, 0], [0, 1], [1, 1]], max_edge_length=42, sparse=0.5
+)
+
+simplex_tree = rips.create_simplex_tree(max_dimension=2)
+
+
+diag = simplex_tree.persistence(homology_coeff_field=2, min_persistence=0)
+print("diag=", diag)
+
+pplot = gudhi.plot_persistence_diagram(diag)
+pplot.show()
diff --git a/src/python/example/tangential_complex_plain_homology_from_off_file_example.py b/src/python/example/tangential_complex_plain_homology_from_off_file_example.py
new file mode 100755
index 00000000..456bc9eb
--- /dev/null
+++ b/src/python/example/tangential_complex_plain_homology_from_off_file_example.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="TangentialComplex creation from " "points read in a OFF file.",
+ epilog="Example: "
+ "example/tangential_complex_plain_homology_from_off_file_example.py "
+ "-f ../data/points/tore3D_300.off -i 3"
+ "- Constructs a tangential complex with the "
+ "points from the given OFF file",
+)
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument("-i", "--intrisic_dim", type=int, required=True)
+parser.add_argument("-b", "--band", type=float, default=0.0)
+parser.add_argument(
+ "--no-diagram",
+ default=False,
+ action="store_true",
+ help="Flag for not to display the diagrams",
+)
+
+args = parser.parse_args()
+
+with open(args.file, "r") as f:
+ first_line = f.readline()
+ if (first_line == "OFF\n") or (first_line == "nOFF\n"):
+ print("#####################################################################")
+ print("TangentialComplex creation from points read in a OFF file")
+
+ tc = gudhi.TangentialComplex(intrisic_dim=args.intrisic_dim, off_file=args.file)
+ tc.compute_tangential_complex()
+ st = tc.create_simplex_tree()
+
+ message = "Number of simplices=" + repr(st.num_simplices())
+ print(message)
+
+ diag = st.persistence(persistence_dim_max=True)
+
+ print("betti_numbers()=")
+ print(st.betti_numbers())
+
+ if args.no_diagram == False:
+ pplot = gudhi.plot_persistence_diagram(diag, band=args.band)
+ pplot.show()
+ else:
+ print(args.file, "is not a valid OFF file")
+
+ f.close()
diff --git a/src/python/example/voronoi_graph_induced_complex.py b/src/python/example/voronoi_graph_induced_complex.py
new file mode 100755
index 00000000..38be6c92
--- /dev/null
+++ b/src/python/example/voronoi_graph_induced_complex.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+""" 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) 2018 Inria
+
+ Modification(s):
+ - YYYY/MM Author: Description of the modification
+"""
+
+__author__ = "Vincent Rouvreau"
+__copyright__ = "Copyright (C) 2018 Inria"
+__license__ = "MIT"
+
+parser = argparse.ArgumentParser(
+ description="Voronoi GIC " "from points read in a OFF file.",
+ epilog="Example: "
+ "example/voronoi_graph_induced_complex.py "
+ "-f ../data/points/human.off -n 700 -v"
+ "- Constructs the Voronoi GIC with the "
+ "points from the given OFF file.",
+)
+parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument("-n", "--subsample-nb-points", type=int, default=100)
+parser.add_argument(
+ "-v",
+ "--verbose",
+ default=False,
+ action="store_true",
+ help="Flag for program verbosity",
+)
+
+args = parser.parse_args()
+
+nerve_complex = gudhi.CoverComplex()
+nerve_complex.set_verbose(args.verbose)
+
+if nerve_complex.read_point_cloud(args.file):
+ nerve_complex.set_type("GIC")
+ nerve_complex.set_color_from_coordinate()
+ nerve_complex.set_graph_from_OFF()
+ nerve_complex.set_cover_from_Voronoi(args.subsample_nb_points)
+ nerve_complex.find_simplices()
+ nerve_complex.plot_off()
+ simplex_tree = nerve_complex.create_simplex_tree()
+ nerve_complex.compute_PD()
+ if args.verbose:
+ print("Iterator on graph induced complex simplices")
+ result_str = (
+ "Graph induced complex is of dimension "
+ + repr(simplex_tree.dimension())
+ + " - "
+ + repr(simplex_tree.num_simplices())
+ + " simplices - "
+ + repr(simplex_tree.num_vertices())
+ + " vertices."
+ )
+ print(result_str)
+ for filtered_value in simplex_tree.get_filtration():
+ print(filtered_value[0])
diff --git a/src/python/example/witness_complex_from_nearest_landmark_table.py b/src/python/example/witness_complex_from_nearest_landmark_table.py
new file mode 100755
index 00000000..c04a82b2
--- /dev/null
+++ b/src/python/example/witness_complex_from_nearest_landmark_table.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+from gudhi import StrongWitnessComplex, SimplexTree
+
+""" 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) 2016 Inria"
+__license__ = "MIT"
+
+print("#####################################################################")
+print("WitnessComplex creation from nearest landmark table")
+nearest_landmark_table = [
+ [[0, 0.0], [1, 0.1], [2, 0.2], [3, 0.3], [4, 0.4]],
+ [[1, 0.0], [2, 0.1], [3, 0.2], [4, 0.3], [0, 0.4]],
+ [[2, 0.0], [3, 0.1], [4, 0.2], [0, 0.3], [1, 0.4]],
+ [[3, 0.0], [4, 0.1], [0, 0.2], [1, 0.3], [2, 0.4]],
+ [[4, 0.0], [0, 0.1], [1, 0.2], [2, 0.3], [3, 0.4]],
+]
+
+witness_complex = StrongWitnessComplex(nearest_landmark_table=nearest_landmark_table)
+simplex_tree = witness_complex.create_simplex_tree(max_alpha_square=0.41)
+
+message = "Number of simplices: " + repr(simplex_tree.num_simplices())
+print(message)
+
+diag = simplex_tree.persistence(min_persistence=-0.1, homology_coeff_field=11)
+print(diag)