diff options
Diffstat (limited to 'src/cython/example')
-rwxr-xr-x | src/cython/example/alpha_complex_example.py | 77 | ||||
-rwxr-xr-x | src/cython/example/alpha_complex_from_file_example.py | 62 | ||||
-rwxr-xr-x | src/cython/example/cubical_complex_from_perseus_file_example.py | 56 | ||||
-rwxr-xr-x | src/cython/example/gudhi_graphical_tools_example.py | 47 | ||||
-rwxr-xr-x | src/cython/example/mini_simplex_tree_example.py | 73 | ||||
-rwxr-xr-x | src/cython/example/random_cubical_complex_example.py | 57 | ||||
-rwxr-xr-x | src/cython/example/rips_complex_example.py | 41 | ||||
-rwxr-xr-x | src/cython/example/rips_complex_from_file_example.py | 62 | ||||
-rwxr-xr-x | src/cython/example/rips_persistence_diagram.py | 39 | ||||
-rwxr-xr-x | src/cython/example/simplex_tree_example.py | 69 | ||||
-rwxr-xr-x | src/cython/example/witness_complex_from_file_example.py | 56 |
11 files changed, 639 insertions, 0 deletions
diff --git a/src/cython/example/alpha_complex_example.py b/src/cython/example/alpha_complex_example.py new file mode 100755 index 00000000..cfeff5d8 --- /dev/null +++ b/src/cython/example/alpha_complex_example.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +import gudhi + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2016 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +print("#####################################################################") +print("AlphaComplex creation from points") +alpha_complex = gudhi.AlphaComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], + max_alpha_square=60.0) + +if alpha_complex.find([0, 1]): + print("[0, 1] Found !!") +else: + print("[0, 1] Not found...") + +if alpha_complex.find([4]): + print("[4] Found !!") +else: + print("[4] Not found...") + +if alpha_complex.insert([0, 1, 2], filtration=4.0): + print("[0, 1, 2] Inserted !!") +else: + print("[0, 1, 2] Not inserted...") + +if alpha_complex.insert([0, 1, 4], filtration=4.0): + print("[0, 1, 4] Inserted !!") +else: + print("[0, 1, 4] Not inserted...") + +if alpha_complex.find([4]): + print("[4] Found !!") +else: + print("[4] Not found...") + +print("dimension=", alpha_complex.dimension()) +print("filtered_tree=", alpha_complex.get_filtered_tree()) +print("star([0])=", alpha_complex.get_star_tree([0])) +print("coface([0], 1)=", alpha_complex.get_coface_tree([0], 1)) + +print("point[0]=", alpha_complex.get_point(0)) +print("point[5]=", alpha_complex.get_point(5)) + +print("betti_numbers()=") +print(alpha_complex.betti_numbers()) + +alpha_complex.initialize_filtration() +print("persistence(homology_coeff_field=2, min_persistence=0)=") +print(alpha_complex.persistence(homology_coeff_field=2, min_persistence=0)) + +print("betti_numbers()=") +print(alpha_complex.betti_numbers()) diff --git a/src/cython/example/alpha_complex_from_file_example.py b/src/cython/example/alpha_complex_from_file_example.py new file mode 100755 index 00000000..beb5d101 --- /dev/null +++ b/src/cython/example/alpha_complex_from_file_example.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python + +import gudhi +import pandas +import argparse + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2016 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +print("#####################################################################") +print("AlphaComplex creation from points read in a file") + +parser = argparse.ArgumentParser(description='AlphaComplex creation from ' + 'points read in a file.', + epilog='Example: ' + 'example/alpha_complex_from_file_example.py ' + 'data/500_random_points_on_3D_Torus.csv ' + '- Constructs a alpha complex with the ' + 'points from the given file. File format ' + 'is X1, X2, ..., Xn') +parser.add_argument('file', type=argparse.FileType('r')) +args = parser.parse_args() + +points = pandas.read_csv(args.file, header=None) + +print("AlphaComplex with max_alpha_square=0.5") + +alpha_complex = gudhi.AlphaComplex(points=points.values, + max_alpha_square=0.5) + +alpha_complex.initialize_filtration() +diag = alpha_complex.persistence(homology_coeff_field=2, min_persistence=0.1) + +print("betti_numbers()=") +print(alpha_complex.betti_numbers()) + +gudhi.diagram_persistence(diag) + +gudhi.barcode_persistence(diag) diff --git a/src/cython/example/cubical_complex_from_perseus_file_example.py b/src/cython/example/cubical_complex_from_perseus_file_example.py new file mode 100755 index 00000000..23f7ece6 --- /dev/null +++ b/src/cython/example/cubical_complex_from_perseus_file_example.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +import gudhi +import numpy +import argparse +import operator +import os + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2016 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +parser = argparse.ArgumentParser(description='Cubical complex from a perseus' + 'file style name.', + epilog='Example: ' + './cubical_complex_from_perseus_file_example.py' + ' -f ../data/bitmap/CubicalTwoSphere.txt') + +parser.add_argument("-f", "--file", type=str, required=True) + +args = parser.parse_args() + +if os.access(args.file, os.R_OK): + print("#####################################################################") + print("CubicalComplex creation") + cubical_complex = gudhi.CubicalComplex(perseus_file=args.file) + + 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()) +else: + print(args.file, "is unreachable") diff --git a/src/cython/example/gudhi_graphical_tools_example.py b/src/cython/example/gudhi_graphical_tools_example.py new file mode 100755 index 00000000..40558bee --- /dev/null +++ b/src/cython/example/gudhi_graphical_tools_example.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +import gudhi + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2016 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +print("#####################################################################") +print("Show palette colors values for dimension") + +gudhi.show_palette_values() + +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.barcode_persistence(persistence) + +print("#####################################################################") +print("Show diagram persistence example") + +gudhi.diagram_persistence(persistence) diff --git a/src/cython/example/mini_simplex_tree_example.py b/src/cython/example/mini_simplex_tree_example.py new file mode 100755 index 00000000..7b65a9d6 --- /dev/null +++ b/src/cython/example/mini_simplex_tree_example.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python + +import gudhi + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2016 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +print("#####################################################################") +print("MiniSimplexTree creation from insertion") + +""" Complex to build. + 1 3 + o---o + /X\ / + o---o o + 2 0 4 +""" + +triangle012 = [0, 1, 2] +edge03 = [0, 3] +edge13 = [1, 3] +vertex4 = [4] +mini_st = gudhi.MiniSimplexTree() +mini_st.insert(triangle012) +mini_st.insert(edge03) +mini_st.insert(edge13) +mini_st.insert(vertex4) + +# FIXME: Remove this line +mini_st.set_dimension(2) + +# initialize_filtration required before plain_homology +mini_st.initialize_filtration() + +print("persistence(homology_coeff_field=2)=") +print(mini_st.persistence(homology_coeff_field=2)) + +edge02 = [0, 2] +if mini_st.find(edge02): + # Only coface is 012 + print("coface(edge02,1)=", mini_st.get_coface_tree(edge02, 1)) + +if mini_st.get_coface_tree(triangle012, 1) == []: + # Precondition: Check the simplex has no coface before removing it. + mini_st.remove_maximal_simplex(triangle012) + +# initialize_filtration required after removing +mini_st.initialize_filtration() + +print("filtered_tree after triangle012 removal =", mini_st.get_filtered_tree()) diff --git a/src/cython/example/random_cubical_complex_example.py b/src/cython/example/random_cubical_complex_example.py new file mode 100755 index 00000000..147eaa49 --- /dev/null +++ b/src/cython/example/random_cubical_complex_example.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +import gudhi +import numpy +import argparse +import operator + + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2016 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +parser = argparse.ArgumentParser(description='Random cubical complex.', + epilog='Example: ' + './random_cubical_complex_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())
\ No newline at end of file diff --git a/src/cython/example/rips_complex_example.py b/src/cython/example/rips_complex_example.py new file mode 100755 index 00000000..65246c9c --- /dev/null +++ b/src/cython/example/rips_complex_example.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +import gudhi + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2016 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +print("#####################################################################") +print("RipsComplex creation from points") +rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], + max_dimension=1, max_edge_length=42) + +print("filtered_tree=", rips.get_filtered_tree()) +print("star([0])=", rips.get_star_tree([0])) +print("coface([0], 1)=", rips.get_coface_tree([0], 1)) + +print("persistence(homology_coeff_field=2, min_persistence=0)=") +print(rips.persistence(homology_coeff_field=2, min_persistence=0)) diff --git a/src/cython/example/rips_complex_from_file_example.py b/src/cython/example/rips_complex_from_file_example.py new file mode 100755 index 00000000..fae72443 --- /dev/null +++ b/src/cython/example/rips_complex_from_file_example.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python + +import gudhi +import pandas +import argparse + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2016 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +print("#####################################################################") +print("RipsComplex creation from points read in a file") + +parser = argparse.ArgumentParser(description='RipsComplex creation from ' + 'points read in a file.', + epilog='Example: ' + 'example/rips_complex_from_file_example.py ' + 'data/2000_random_points_on_3D_Torus.csv ' + '- Constructs a rips complex with the ' + 'points from the given file. File format ' + 'is X1, X2, ..., Xn') +parser.add_argument('file', type=argparse.FileType('r')) +args = parser.parse_args() + +points = pandas.read_csv(args.file, header=None) + +print("RipsComplex with max_edge_length=0.7") + +rips_complex = gudhi.RipsComplex(points=points.values, + max_dimension=len(points.values[0]), max_edge_length=0.7) + +rips_complex.initialize_filtration() +diag = rips_complex.persistence(homology_coeff_field=2, min_persistence=0.3) + +print("betti_numbers()=") +print(rips_complex.betti_numbers()) + +gudhi.diagram_persistence(diag) + +gudhi.barcode_persistence(diag) diff --git a/src/cython/example/rips_persistence_diagram.py b/src/cython/example/rips_persistence_diagram.py new file mode 100755 index 00000000..fddea298 --- /dev/null +++ b/src/cython/example/rips_persistence_diagram.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +import gudhi + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Marc Glisse + + Copyright (C) 2016 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +__author__ = "Marc Glisse" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +print("#####################################################################") +print("RipsComplex creation from points") +rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], + max_dimension=1, max_edge_length=42) + +diag = rips.persistence(homology_coeff_field=2, min_persistence=0) +print("diag=", diag) + +gudhi.diagram_persistence(diag) diff --git a/src/cython/example/simplex_tree_example.py b/src/cython/example/simplex_tree_example.py new file mode 100755 index 00000000..cc33ed6e --- /dev/null +++ b/src/cython/example/simplex_tree_example.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python + +import gudhi + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2016 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +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...") + +# FIXME: Remove this line +st.set_dimension(3) +print("dimension=", st.dimension()) + +st.set_filtration(4.0) +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_tree[2]=", st.get_skeleton_tree(2)) +print("skeleton_tree[1]=", st.get_skeleton_tree(1)) +print("skeleton_tree[0]=", st.get_skeleton_tree(0)) + +print("persistence(homology_coeff_field=2, min_persistence=0)=") +print(st.persistence(homology_coeff_field=2, min_persistence=0)) diff --git a/src/cython/example/witness_complex_from_file_example.py b/src/cython/example/witness_complex_from_file_example.py new file mode 100755 index 00000000..82a5b49a --- /dev/null +++ b/src/cython/example/witness_complex_from_file_example.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +import gudhi +import pandas +import argparse + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2016 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +print("#####################################################################") +print("WitnessComplex creation from points read in a file") + +parser = argparse.ArgumentParser(description='WitnessComplex creation from ' + 'points read in a file.', + epilog='Example: ' + 'example/witness_complex_from_file_example.py' + ' data/2000_random_points_on_3D_Torus.csv ' + '- Constructs a witness complex with the ' + 'points from the given file. File format ' + 'is X1, X2, ..., Xn') +parser.add_argument('file', type=argparse.FileType('r')) +args = parser.parse_args() + +points = pandas.read_csv(args.file, header=None) + +print("WitnessComplex with number_of_landmarks=100") + +witness_complex = gudhi.WitnessComplex(points=points.values, + number_of_landmarks=100) + +witness_complex.initialize_filtration() + +print("filtered_tree=", witness_complex.get_filtered_tree()) |