From 4a089fe4840f09b4aabafa06ad53200baa6d6547 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 6 Jun 2016 14:54:17 +0000 Subject: bar code persistence tool Copyright modification git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1251 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ff7a8baeffbcafe6d074786b6a7956d815edd21b --- src/cython/Makefile | 1 - src/cython/example/alpha_complex_example.py | 4 +- .../example/alpha_complex_from_file_example.py | 4 +- .../example/gudhi_graphical_tools_example.py | 42 +++++++++++ src/cython/example/mini_simplex_tree_example.py | 4 +- .../example/random_cubical_complex_example.py | 4 +- src/cython/example/rips_complex_example.py | 4 +- src/cython/example/rips_persistence_diagram.py | 14 +--- src/cython/example/simplex_tree_example.py | 4 +- src/cython/gudhi.pyx | 1 + src/cython/src/cpp/Alpha_complex_interface.h | 2 +- src/cython/src/cpp/Cubical_complex_interface.h | 2 +- .../src/cpp/Persistent_cohomology_interface.h | 2 +- src/cython/src/cpp/Simplex_tree_interface.h | 2 +- src/cython/src/cython/alpha_complex.pyx | 4 +- src/cython/src/cython/cubical_complex.pyx | 4 +- src/cython/src/cython/mini_simplex_tree.pyx | 4 +- .../src/cython/persistence_graphical_tools.py | 82 ++++++++++++++++++++++ src/cython/src/cython/rips_complex.pyx | 4 +- src/cython/src/cython/simplex_tree.pyx | 4 +- src/cython/test/test_alpha_complex.py | 4 +- src/cython/test/test_mini_simplex_tree.py | 4 +- src/cython/test/test_rips_complex.py | 4 +- src/cython/test/test_simplex_tree.py | 4 +- 24 files changed, 162 insertions(+), 46 deletions(-) create mode 100755 src/cython/example/gudhi_graphical_tools_example.py create mode 100755 src/cython/src/cython/persistence_graphical_tools.py (limited to 'src/cython') diff --git a/src/cython/Makefile b/src/cython/Makefile index 05b831f6..e6054122 100644 --- a/src/cython/Makefile +++ b/src/cython/Makefile @@ -13,7 +13,6 @@ example: python example/rips_complex_example.py python example/alpha_complex_example.py python example/random_cubical_complex_example.py 10 10 - python example/rips_persistence_diagram.py python example/alpha_complex_from_file_example.py data/500_random_points_on_3D_Torus.csv clean: diff --git a/src/cython/example/alpha_complex_example.py b/src/cython/example/alpha_complex_example.py index 37c04f23..cfeff5d8 100755 --- a/src/cython/example/alpha_complex_example.py +++ b/src/cython/example/alpha_complex_example.py @@ -8,7 +8,7 @@ import gudhi Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ import gudhi """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" print("#####################################################################") diff --git a/src/cython/example/alpha_complex_from_file_example.py b/src/cython/example/alpha_complex_from_file_example.py index 9ceb82b1..04b4b279 100755 --- a/src/cython/example/alpha_complex_from_file_example.py +++ b/src/cython/example/alpha_complex_from_file_example.py @@ -10,7 +10,7 @@ import argparse Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -27,7 +27,7 @@ import argparse """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" print("#####################################################################") 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..c43b2338 --- /dev/null +++ b/src/cython/example/gudhi_graphical_tools_example.py @@ -0,0 +1,42 @@ +#!/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("Show palette colors values for dimension") + +gudhi.show_palette_values() + +print("#####################################################################") +print("Show bar code 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.bar_code_persistence(persistence) diff --git a/src/cython/example/mini_simplex_tree_example.py b/src/cython/example/mini_simplex_tree_example.py index d7189ddf..7b65a9d6 100755 --- a/src/cython/example/mini_simplex_tree_example.py +++ b/src/cython/example/mini_simplex_tree_example.py @@ -8,7 +8,7 @@ import gudhi Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ import gudhi """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" print("#####################################################################") diff --git a/src/cython/example/random_cubical_complex_example.py b/src/cython/example/random_cubical_complex_example.py index b479e2e6..147eaa49 100755 --- a/src/cython/example/random_cubical_complex_example.py +++ b/src/cython/example/random_cubical_complex_example.py @@ -12,7 +12,7 @@ import operator Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -29,7 +29,7 @@ import operator """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" parser = argparse.ArgumentParser(description='Random cubical complex.', diff --git a/src/cython/example/rips_complex_example.py b/src/cython/example/rips_complex_example.py index 449ea2b3..65246c9c 100755 --- a/src/cython/example/rips_complex_example.py +++ b/src/cython/example/rips_complex_example.py @@ -8,7 +8,7 @@ import gudhi Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ import gudhi """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" print("#####################################################################") diff --git a/src/cython/example/rips_persistence_diagram.py b/src/cython/example/rips_persistence_diagram.py index 3e95f2cc..57f25b22 100755 --- a/src/cython/example/rips_persistence_diagram.py +++ b/src/cython/example/rips_persistence_diagram.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import gudhi -import matplotlib.pyplot as plt """This file is part of the Gudhi Library. The Gudhi library (Geometric Understanding in Higher Dimensions) is a generic C++ @@ -9,7 +8,7 @@ import matplotlib.pyplot as plt Author(s): Marc Glisse - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -26,7 +25,7 @@ import matplotlib.pyplot as plt """ __author__ = "Marc Glisse" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" print("#####################################################################") @@ -37,11 +36,4 @@ rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], diag = rips.persistence(homology_coeff_field=2, min_persistence=0) print("diag=", diag) -diag0=[i[1] for i in diag if i[0]==0] -diag1=[i[1] for i in diag if i[0]==1] - -plt.plot([i[0] for i in diag0],[min(i[1],1.5) for i in diag0],'ro', - [i[0] for i in diag1],[i[1] for i in diag1],'bs',[-.2,1.5],[-.2,1.5], - '-') -plt.axis([-.2,1.5,-.2,1.5]) -plt.show() +gudhi.bar_code_persistence(diag) diff --git a/src/cython/example/simplex_tree_example.py b/src/cython/example/simplex_tree_example.py index 45d57c53..cc33ed6e 100755 --- a/src/cython/example/simplex_tree_example.py +++ b/src/cython/example/simplex_tree_example.py @@ -8,7 +8,7 @@ import gudhi Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ import gudhi """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" print("#####################################################################") diff --git a/src/cython/gudhi.pyx b/src/cython/gudhi.pyx index d0e2df99..b8cb032e 100644 --- a/src/cython/gudhi.pyx +++ b/src/cython/gudhi.pyx @@ -29,3 +29,4 @@ include "src/cython/mini_simplex_tree.pyx" include "src/cython/rips_complex.pyx" include "src/cython/alpha_complex.pyx" include "src/cython/cubical_complex.pyx" +include "src/cython/persistence_graphical_tools.py" diff --git a/src/cython/src/cpp/Alpha_complex_interface.h b/src/cython/src/cpp/Alpha_complex_interface.h index 3378ee6e..c745543a 100644 --- a/src/cython/src/cpp/Alpha_complex_interface.h +++ b/src/cython/src/cpp/Alpha_complex_interface.h @@ -4,7 +4,7 @@ * * Author(s): Vincent Rouvreau * - * Copyright (C) 2016 INRIA Saclay (France) + * 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 diff --git a/src/cython/src/cpp/Cubical_complex_interface.h b/src/cython/src/cpp/Cubical_complex_interface.h index b817198d..1bed6fd1 100644 --- a/src/cython/src/cpp/Cubical_complex_interface.h +++ b/src/cython/src/cpp/Cubical_complex_interface.h @@ -4,7 +4,7 @@ * * Author(s): Vincent Rouvreau * - * Copyright (C) 2016 INRIA Saclay (France) + * 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 diff --git a/src/cython/src/cpp/Persistent_cohomology_interface.h b/src/cython/src/cpp/Persistent_cohomology_interface.h index 53aea58e..58421799 100644 --- a/src/cython/src/cpp/Persistent_cohomology_interface.h +++ b/src/cython/src/cpp/Persistent_cohomology_interface.h @@ -4,7 +4,7 @@ * * Author(s): Vincent Rouvreau * - * Copyright (C) 2016 INRIA Saclay (France) + * 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 diff --git a/src/cython/src/cpp/Simplex_tree_interface.h b/src/cython/src/cpp/Simplex_tree_interface.h index 223590aa..9aee630b 100644 --- a/src/cython/src/cpp/Simplex_tree_interface.h +++ b/src/cython/src/cpp/Simplex_tree_interface.h @@ -4,7 +4,7 @@ * * Author(s): Vincent Rouvreau * - * Copyright (C) 2016 INRIA Saclay (France) + * 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 diff --git a/src/cython/src/cython/alpha_complex.pyx b/src/cython/src/cython/alpha_complex.pyx index 5df7a659..0d44cbce 100644 --- a/src/cython/src/cython/alpha_complex.pyx +++ b/src/cython/src/cython/alpha_complex.pyx @@ -8,7 +8,7 @@ from libcpp.utility cimport pair Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ from libcpp.utility cimport pair """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" cdef extern from "Alpha_complex_interface.h" namespace "Gudhi": diff --git a/src/cython/src/cython/cubical_complex.pyx b/src/cython/src/cython/cubical_complex.pyx index d513191c..002e99c9 100644 --- a/src/cython/src/cython/cubical_complex.pyx +++ b/src/cython/src/cython/cubical_complex.pyx @@ -8,7 +8,7 @@ from libcpp.utility cimport pair Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ from libcpp.utility cimport pair """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" cdef extern from "Cubical_complex_interface.h" namespace "Gudhi": diff --git a/src/cython/src/cython/mini_simplex_tree.pyx b/src/cython/src/cython/mini_simplex_tree.pyx index a5077820..3d216fe2 100644 --- a/src/cython/src/cython/mini_simplex_tree.pyx +++ b/src/cython/src/cython/mini_simplex_tree.pyx @@ -8,7 +8,7 @@ from libcpp.utility cimport pair Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ from libcpp.utility cimport pair """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": diff --git a/src/cython/src/cython/persistence_graphical_tools.py b/src/cython/src/cython/persistence_graphical_tools.py new file mode 100755 index 00000000..b845e405 --- /dev/null +++ b/src/cython/src/cython/persistence_graphical_tools.py @@ -0,0 +1,82 @@ +import matplotlib.pyplot as plt +import numpy as np + +"""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" + +""" +Only 13 colors for the palette +""" +palette = ['#ff0000', '#00ff00', '#0000ff', '#00ffff', '#ff00ff', '#ffff00', + '#000000', '#880000', '#008800', '#000088', '#888800', '#880088', + '#008888'] + +def show_palette_values(): + colors = [] + for color in palette: + colors.append(color) + + y_pos = np.arange(len(palette)) + + plt.barh(y_pos, y_pos + 1, align='center', alpha=0.4, color=colors) + plt.ylabel('Dimension') + plt.title('Dimension palette values') + + plt.show() + +def bar_code_persistence(persistence): + # Look for minimum birth date and maximum death date for plot optimisation + max_death = 0 + min_birth = persistence[0][1][0] + for interval in reversed(persistence): + if float(interval[1][1]) != float('inf'): + if float(interval[1][1]) > max_death: + max_death = float(interval[1][1]) + if float(interval[1][0]) > max_death: + max_death = float(interval[1][0]) + if float(interval[1][0]) < min_birth: + min_birth = float(interval[1][0]) + + ind = 0 + delta = ((max_death - min_birth) / 10.0) + infinity = max_death + delta + axis_start = min_birth - delta + # Draw horizontal bars in loop + for interval in reversed(persistence): + if float(interval[1][1]) != float('inf'): + # Finite death case + plt.barh(ind, (interval[1][1] - interval[1][0]), height=0.8, + left = interval[1][0], alpha=0.4, + color = palette[interval[0]]) + else: + # Infinite death case for diagram to be nicer + plt.barh(ind, (infinity - interval[1][0]), height=0.8, + left = interval[1][0], alpha=0.4, + color = palette[interval[0]]) + ind = ind + 1 + # Ends plot on infinity value and starts a little bit before min_birth + plt.axis([axis_start, infinity, 0, ind]) + plt.show() diff --git a/src/cython/src/cython/rips_complex.pyx b/src/cython/src/cython/rips_complex.pyx index d01f79cb..52a3cfd8 100644 --- a/src/cython/src/cython/rips_complex.pyx +++ b/src/cython/src/cython/rips_complex.pyx @@ -8,7 +8,7 @@ from libcpp.utility cimport pair Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ from libcpp.utility cimport pair """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": diff --git a/src/cython/src/cython/simplex_tree.pyx b/src/cython/src/cython/simplex_tree.pyx index 071b19e3..b84b7758 100644 --- a/src/cython/src/cython/simplex_tree.pyx +++ b/src/cython/src/cython/simplex_tree.pyx @@ -8,7 +8,7 @@ from libcpp.utility cimport pair Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ from libcpp.utility cimport pair """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": diff --git a/src/cython/test/test_alpha_complex.py b/src/cython/test/test_alpha_complex.py index 8a346bb9..a1e57294 100755 --- a/src/cython/test/test_alpha_complex.py +++ b/src/cython/test/test_alpha_complex.py @@ -8,7 +8,7 @@ import gudhi Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ import gudhi """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" diff --git a/src/cython/test/test_mini_simplex_tree.py b/src/cython/test/test_mini_simplex_tree.py index 6622fa57..ec1f5044 100755 --- a/src/cython/test/test_mini_simplex_tree.py +++ b/src/cython/test/test_mini_simplex_tree.py @@ -8,7 +8,7 @@ import gudhi Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ import gudhi """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" diff --git a/src/cython/test/test_rips_complex.py b/src/cython/test/test_rips_complex.py index 3ad26b53..ecc676c7 100755 --- a/src/cython/test/test_rips_complex.py +++ b/src/cython/test/test_rips_complex.py @@ -8,7 +8,7 @@ import gudhi Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ import gudhi """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" diff --git a/src/cython/test/test_simplex_tree.py b/src/cython/test/test_simplex_tree.py index 3451ca4b..7663ed70 100755 --- a/src/cython/test/test_simplex_tree.py +++ b/src/cython/test/test_simplex_tree.py @@ -8,7 +8,7 @@ import gudhi Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA Saclay (France) + 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 @@ -25,7 +25,7 @@ import gudhi """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" -- cgit v1.2.3