diff options
Diffstat (limited to 'src/cython/example')
20 files changed, 401 insertions, 236 deletions
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 d9925c22..b8f283b3 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 @@ -17,40 +17,48 @@ __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 = 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.) -parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams') +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: +with open(args.file, "r") as f: first_line = f.readline() - if (first_line == 'OFF\n') or (first_line == 'nOFF\n'): + 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) - + 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() diff --git a/src/cython/example/alpha_rips_persistence_bottleneck_distance.py b/src/cython/example/alpha_rips_persistence_bottleneck_distance.py index 92bf9d39..086307ee 100755 --- a/src/cython/example/alpha_rips_persistence_bottleneck_distance.py +++ b/src/cython/example/alpha_rips_persistence_bottleneck_distance.py @@ -18,21 +18,23 @@ __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 = 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: +with open(args.file, "r") as f: first_line = f.readline() - if (first_line == 'OFF\n') or (first_line == 'nOFF\n'): + 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") @@ -40,8 +42,9 @@ with open(args.file, 'r') as f: message = "RipsComplex with max_edge_length=" + repr(args.threshold) print(message) - rips_complex = gudhi.RipsComplex(points=point_cloud, - max_edge_length=args.threshold) + rips_complex = gudhi.RipsComplex( + points=point_cloud, max_edge_length=args.threshold + ) rips_stree = rips_complex.create_simplex_tree(max_dimension=args.max_dimension) @@ -57,7 +60,9 @@ with open(args.file, 'r') as f: print(message) alpha_complex = gudhi.AlphaComplex(points=point_cloud) - alpha_stree = alpha_complex.create_simplex_tree(max_alpha_square=(args.threshold * args.threshold)) + 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) @@ -71,15 +76,26 @@ with open(args.file, 'r') as f: 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)) + 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) + 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("================================================================================") + print( + "================================================================================" + ) message = "Bottleneck distance is " + repr(max_b_distance) print(message) diff --git a/src/cython/example/bottleneck_basic_example.py b/src/cython/example/bottleneck_basic_example.py index f47e24d4..392d2a6e 100755 --- a/src/cython/example/bottleneck_basic_example.py +++ b/src/cython/example/bottleneck_basic_example.py @@ -16,9 +16,9 @@ __author__ = "Francois Godi, Vincent Rouvreau" __copyright__ = "Copyright (C) 2016 Inria" __license__ = "MIT" -diag1 = [[2.7, 3.7],[9.6, 14.],[34.2, 34.974], [3.,float('Inf')]] +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')]] +diag2 = [[2.8, 4.45], [9.5, 14.1], [3.2, float("Inf")]] message = "diag1=" + repr(diag1) print(message) @@ -26,9 +26,12 @@ print(message) message = "diag2=" + repr(diag2) print(message) -message = "Bottleneck distance approximation=" + repr(gudhi.bottleneck_distance(diag1, diag2, 0.1)) +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)) +message = "Bottleneck distance exact value=" + repr( + gudhi.bottleneck_distance(diag1, diag2) +) print(message) - diff --git a/src/cython/example/coordinate_graph_induced_complex.py b/src/cython/example/coordinate_graph_induced_complex.py index f30eaf3e..e32141b4 100755 --- a/src/cython/example/coordinate_graph_induced_complex.py +++ b/src/cython/example/coordinate_graph_induced_complex.py @@ -17,24 +17,31 @@ __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 = 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') +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') +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() @@ -45,12 +52,17 @@ if (nerve_complex.read_point_cloud(args.file)): 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.' + 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/cython/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py b/src/cython/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py index 1a8de8bd..610ba44f 100755 --- a/src/cython/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py +++ b/src/cython/example/euclidean_strong_witness_complex_diagram_persistence_from_off_file_example.py @@ -17,38 +17,54 @@ __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 = 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.) -parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams') +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: +with open(args.file, "r") as f: first_line = f.readline() - if (first_line == 'OFF\n') or (first_line == 'nOFF\n'): + 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) + 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) + 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) diff --git a/src/cython/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py b/src/cython/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py index 9a17f8de..7587b732 100755 --- a/src/cython/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py +++ b/src/cython/example/euclidean_witness_complex_diagram_persistence_from_off_file_example.py @@ -17,38 +17,53 @@ __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 = 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.) -parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams') +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: +with open(args.file, "r") as f: first_line = f.readline() - if (first_line == 'OFF\n') or (first_line == 'nOFF\n'): + 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) + 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) + 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) diff --git a/src/cython/example/functional_graph_induced_complex.py b/src/cython/example/functional_graph_induced_complex.py index f87c6837..8b645040 100755 --- a/src/cython/example/functional_graph_induced_complex.py +++ b/src/cython/example/functional_graph_induced_complex.py @@ -17,25 +17,32 @@ __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 = 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') +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') +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() @@ -46,12 +53,17 @@ if (nerve_complex.read_point_cloud(args.off_file)): 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.' + 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/cython/example/gudhi_graphical_tools_example.py b/src/cython/example/gudhi_graphical_tools_example.py index 4f64c615..3b0ca54d 100755 --- a/src/cython/example/gudhi_graphical_tools_example.py +++ b/src/cython/example/gudhi_graphical_tools_example.py @@ -19,9 +19,15 @@ __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))] +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("#####################################################################") diff --git a/src/cython/example/nerve_of_a_covering.py b/src/cython/example/nerve_of_a_covering.py index 707f0631..3c8e0f90 100755 --- a/src/cython/example/nerve_of_a_covering.py +++ b/src/cython/example/nerve_of_a_covering.py @@ -17,26 +17,33 @@ __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 = 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') +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') +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() @@ -47,12 +54,17 @@ if (nerve_complex.read_point_cloud(args.file)): 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.' + 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/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 40a2fed1..9cb855cd 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 @@ -17,8 +17,9 @@ __author__ = "Vincent Rouvreau" __copyright__ = "Copyright (C) 2016 Inria" __license__ = "MIT" + def is_file_perseus(file): - num_lines = open(file).read().count('\n') + num_lines = open(file).read().count("\n") try: f = open(file) num_dim = int(f.readline()) @@ -36,14 +37,21 @@ def is_file_perseus(file): 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 = 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') +parser.add_argument( + "--no-barcode", + default=False, + action="store_true", + help="Flag for not to display the barcodes", +) args = parser.parse_args() @@ -53,7 +61,9 @@ if is_file_perseus(args.file): 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) + diag = periodic_cubical_complex.persistence( + homology_coeff_field=3, min_persistence=0 + ) print(diag) print("betti_numbers()=") diff --git a/src/cython/example/random_cubical_complex_persistence_example.py b/src/cython/example/random_cubical_complex_persistence_example.py index 12db3f41..da0eb177 100755 --- a/src/cython/example/random_cubical_complex_persistence_example.py +++ b/src/cython/example/random_cubical_complex_persistence_example.py @@ -21,23 +21,26 @@ __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') +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: +if dimension_multiplication > 1: print("#####################################################################") print("CubicalComplex creation") - cubical_complex = gudhi.CubicalComplex(dimensions=args.dimension, - top_dimensional_cells = numpy.random.rand(dimension_multiplication)) + 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)) diff --git a/src/cython/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py b/src/cython/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py index 98be0123..3571580b 100755 --- a/src/cython/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py +++ b/src/cython/example/rips_complex_diagram_persistence_from_correlation_matrix_file_example.py @@ -18,22 +18,28 @@ __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 = 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.) -parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams') +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. < args.min_edge_correlation < 1.): +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) @@ -48,12 +54,18 @@ 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) +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.-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.-args.min_edge_correlation) +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()) @@ -65,7 +77,10 @@ print("betti_numbers()=") print(simplex_tree.betti_numbers()) # invert the persistence diagram -invert_diag = [(diag[pers][0],(1.-diag[pers][1][0], 1.-diag[pers][1][1])) for pers in range(len(diag))] +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) diff --git a/src/cython/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py b/src/cython/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py index f02dc0c0..0b9a9ba9 100755 --- a/src/cython/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py +++ b/src/cython/example/rips_complex_diagram_persistence_from_distance_matrix_file_example.py @@ -17,18 +17,24 @@ __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 = 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.) -parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams') +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() @@ -39,7 +45,9 @@ 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) +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()) diff --git a/src/cython/example/rips_complex_diagram_persistence_from_off_file_example.py b/src/cython/example/rips_complex_diagram_persistence_from_off_file_example.py index e1f8b85d..2b335bba 100755 --- a/src/cython/example/rips_complex_diagram_persistence_from_off_file_example.py +++ b/src/cython/example/rips_complex_diagram_persistence_from_off_file_example.py @@ -17,42 +17,52 @@ __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 = 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.) -parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams') +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: +with open(args.file, "r") as f: first_line = f.readline() - if (first_line == 'OFF\n') or (first_line == 'nOFF\n'): + 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) - + 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() diff --git a/src/cython/example/rips_complex_from_points_example.py b/src/cython/example/rips_complex_from_points_example.py index f0d7a097..59d8a261 100755 --- a/src/cython/example/rips_complex_from_points_example.py +++ b/src/cython/example/rips_complex_from_points_example.py @@ -18,8 +18,7 @@ __license__ = "MIT" print("#####################################################################") print("RipsComplex creation from points") -rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], - max_edge_length=42) +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) diff --git a/src/cython/example/rips_persistence_diagram.py b/src/cython/example/rips_persistence_diagram.py index 6b02eac9..f5897d7b 100755 --- a/src/cython/example/rips_persistence_diagram.py +++ b/src/cython/example/rips_persistence_diagram.py @@ -18,8 +18,7 @@ __license__ = "MIT" print("#####################################################################") print("RipsComplex creation from points") -rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], - max_edge_length=42) +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) diff --git a/src/cython/example/sparse_rips_persistence_diagram.py b/src/cython/example/sparse_rips_persistence_diagram.py index e58baf45..671d5e34 100755 --- a/src/cython/example/sparse_rips_persistence_diagram.py +++ b/src/cython/example/sparse_rips_persistence_diagram.py @@ -18,8 +18,9 @@ __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=.5) +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) diff --git a/src/cython/example/tangential_complex_plain_homology_from_off_file_example.py b/src/cython/example/tangential_complex_plain_homology_from_off_file_example.py index 075149fb..456bc9eb 100755 --- a/src/cython/example/tangential_complex_plain_homology_from_off_file_example.py +++ b/src/cython/example/tangential_complex_plain_homology_from_off_file_example.py @@ -17,38 +17,44 @@ __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 = 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.) -parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams') +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: +with open(args.file, "r") as f: first_line = f.readline() - if (first_line == 'OFF\n') or (first_line == 'nOFF\n'): + 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 = 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) - + + 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() diff --git a/src/cython/example/voronoi_graph_induced_complex.py b/src/cython/example/voronoi_graph_induced_complex.py index 1e62fb60..38be6c92 100755 --- a/src/cython/example/voronoi_graph_induced_complex.py +++ b/src/cython/example/voronoi_graph_induced_complex.py @@ -17,24 +17,31 @@ __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 = 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') +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') +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) @@ -42,12 +49,17 @@ if (nerve_complex.read_point_cloud(args.file)): 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.' + 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/cython/example/witness_complex_from_nearest_landmark_table.py b/src/cython/example/witness_complex_from_nearest_landmark_table.py index 5cf954bf..c04a82b2 100755 --- a/src/cython/example/witness_complex_from_nearest_landmark_table.py +++ b/src/cython/example/witness_complex_from_nearest_landmark_table.py @@ -18,11 +18,13 @@ __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]]] +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) |