From 355dc2a0ae73f243fc0aa8d7c797509d8ba5e6b4 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 18 Aug 2016 15:33:26 +0000 Subject: Move pandas files points into data/pandas Fix example and tests New persistence constructor for cubical to increase max_persistence_dim (and only for cubical, periodic or not) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1442 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 243a843a65a82b9d3d8d564aa906c0a17eda176a --- ...ex_diagram_persistence_from_off_file_example.py | 15 +++-- ...arcode_persistence_from_perseus_file_example.py | 2 +- .../example/random_cubical_complex_example.py | 57 ------------------ .../random_cubical_complex_persistence_example.py | 57 ++++++++++++++++++ ...am_persistence_with_pandas_interface_example.py | 68 ++++++++++++++++++++++ src/cython/example/rips_complex_example.py | 41 ------------- .../example/rips_complex_from_file_example.py | 62 -------------------- .../example/rips_complex_from_points_example.py | 38 ++++++++++++ src/cython/example/simplex_tree_example.py | 3 - 9 files changed, 175 insertions(+), 168 deletions(-) delete mode 100755 src/cython/example/random_cubical_complex_example.py create mode 100755 src/cython/example/random_cubical_complex_persistence_example.py create mode 100755 src/cython/example/rips_complex_diagram_persistence_with_pandas_interface_example.py delete mode 100755 src/cython/example/rips_complex_example.py delete mode 100755 src/cython/example/rips_complex_from_file_example.py create mode 100755 src/cython/example/rips_complex_from_points_example.py (limited to 'src/cython/example') diff --git a/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py b/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py index 8e534061..d74eba57 100755 --- a/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py +++ b/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py @@ -33,11 +33,12 @@ 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 ' - '../data/points/tore3D_1307.off ' + '-f ../data/points/tore3D_300.off -a 0.6' '- Constructs a alpha complex with the ' 'points from the given file. File format ' 'is X1, X2, ..., Xn') parser.add_argument("-f", "--file", type=str, required=True) +parser.add_argument("-a", "--max_alpha_square", type=float, default=0.5) parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams') args = parser.parse_args() @@ -45,12 +46,18 @@ 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") - alpha_complex = gudhi.AlphaComplex(off_file=args.file, max_alpha_square=0.5) + + message = "AlphaComplex with max_edge_length=" + repr(args.max_alpha_square) + print(message) + + alpha_complex = gudhi.AlphaComplex(off_file=args.file, max_alpha_square=args.max_alpha_square) - diag = alpha_complex.persistence(homology_coeff_field=2, min_persistence=0.1) + message = "Number of simplices=" + repr(alpha_complex.num_simplices()) + print(message) + + diag = alpha_complex.persistence() print("betti_numbers()=") print(alpha_complex.betti_numbers()) diff --git a/src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py b/src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py index e6ba94e1..a9545ee9 100755 --- a/src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py +++ b/src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py @@ -51,7 +51,7 @@ def is_file_perseus(file): parser = argparse.ArgumentParser(description='Periodic cubical complex from a ' 'perseus file style name.', epilog='Example: ' - './periodic_cubical_complex_from_perseus_file_example.py' + './periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py' ' -f ../data/bitmap/CubicalTwoSphere.txt') parser.add_argument("-f", "--file", type=str, required=True) diff --git a/src/cython/example/random_cubical_complex_example.py b/src/cython/example/random_cubical_complex_example.py deleted file mode 100755 index 147eaa49..00000000 --- a/src/cython/example/random_cubical_complex_example.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/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 . -""" - -__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/random_cubical_complex_persistence_example.py b/src/cython/example/random_cubical_complex_persistence_example.py new file mode 100755 index 00000000..1c55f777 --- /dev/null +++ b/src/cython/example/random_cubical_complex_persistence_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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +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()) \ No newline at end of file diff --git a/src/cython/example/rips_complex_diagram_persistence_with_pandas_interface_example.py b/src/cython/example/rips_complex_diagram_persistence_with_pandas_interface_example.py new file mode 100755 index 00000000..bcf2fbcb --- /dev/null +++ b/src/cython/example/rips_complex_diagram_persistence_with_pandas_interface_example.py @@ -0,0 +1,68 @@ +#!/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 . +""" + +__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_diagram_persistence_with_pandas_interface_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("-f", "--file", type=str, required=True) +parser.add_argument("-e", "--max-edge-length", type=float, default=0.5) +parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams') + +args = parser.parse_args() + +points = pandas.read_csv(args.file, header=None) + +message = "RipsComplex with max_edge_length=" + repr(args.max_edge_length) +print(message) + +rips_complex = gudhi.RipsComplex(points=points.values, + max_dimension=len(points.values[0]), max_edge_length=args.max_edge_length) + +message = "Number of simplices=" + repr(rips_complex.num_simplices()) +print(message) + +rips_complex.initialize_filtration() +diag = rips_complex.persistence() + +print("betti_numbers()=") +print(rips_complex.betti_numbers()) + +if args.no_diagram == False: + gudhi.diagram_persistence(diag) diff --git a/src/cython/example/rips_complex_example.py b/src/cython/example/rips_complex_example.py deleted file mode 100755 index 65246c9c..00000000 --- a/src/cython/example/rips_complex_example.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/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 . -""" - -__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 deleted file mode 100755 index fae72443..00000000 --- a/src/cython/example/rips_complex_from_file_example.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/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 . -""" - -__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_complex_from_points_example.py b/src/cython/example/rips_complex_from_points_example.py new file mode 100755 index 00000000..1a22d8e3 --- /dev/null +++ b/src/cython/example/rips_complex_from_points_example.py @@ -0,0 +1,38 @@ +#!/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 . +""" + +__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)) diff --git a/src/cython/example/simplex_tree_example.py b/src/cython/example/simplex_tree_example.py index cc33ed6e..bf5f17a2 100755 --- a/src/cython/example/simplex_tree_example.py +++ b/src/cython/example/simplex_tree_example.py @@ -64,6 +64,3 @@ 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)) -- cgit v1.2.3