summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-08-17 11:08:46 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-08-17 11:08:46 +0000
commit777ed59f7d723139114b072682729eaed8596881 (patch)
tree680a581443271457f8e0b160f6e193e2358dccaa /src
parent15ad63c814fbb30783c240c57b079e1a66094aa9 (diff)
Fix persistent_betti_numbers in Persistent_cohomology to make it work with cubical
Cython examples renaming and fixing git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1439 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ab84ba3acd6241257f1787e29ac2e3ac005bbd80
Diffstat (limited to 'src')
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h5
-rw-r--r--src/cython/CMakeLists.txt3
-rwxr-xr-xsrc/cython/cython/persistence_graphical_tools.py9
-rwxr-xr-xsrc/cython/doc/conf.py5
-rw-r--r--src/cython/doc/img/graphical_tools_representation.pngbin0 -> 10846 bytes
-rw-r--r--src/cython/doc/index.rst5
-rwxr-xr-xsrc/cython/doc/pyplots/barcode_persistence.py5
-rwxr-xr-xsrc/cython/doc/pyplots/diagram_persistence.py6
-rwxr-xr-xsrc/cython/doc/pyplots/show_palette_values.py2
-rwxr-xr-xsrc/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py (renamed from src/cython/example/alpha_complex_from_file_example.py)47
-rwxr-xr-xsrc/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py (renamed from src/cython/example/cubical_complex_from_perseus_file_example.py)46
-rw-r--r--src/cython/include/Persistent_cohomology_interface.h2
12 files changed, 87 insertions, 48 deletions
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
index a7d1e463..5b371f2b 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
@@ -598,7 +598,7 @@ class Persistent_cohomology {
*/
std::vector<int> betti_numbers() const {
// Init Betti numbers vector with zeros until Simplicial complex dimension
- std::vector<int> betti_numbers(cpx_->dimension(), 0);
+ std::vector<int> betti_numbers(dim_max_, 0);
for (auto pair : persistent_pairs_) {
// Count never ended persistence intervals
@@ -637,8 +637,7 @@ class Persistent_cohomology {
*/
std::vector<int> persistent_betti_numbers(Filtration_value from, Filtration_value to) const {
// Init Betti numbers vector with zeros until Simplicial complex dimension
- std::vector<int> betti_numbers(cpx_->dimension(), 0);
-
+ std::vector<int> betti_numbers(dim_max_, 0);
for (auto pair : persistent_pairs_) {
// Count persistence intervals that covers the given interval
// null_simplex test : if the function is called with to=+infinity, we still get something useful. And it will
diff --git a/src/cython/CMakeLists.txt b/src/cython/CMakeLists.txt
index 823d5bb6..383dd08a 100644
--- a/src/cython/CMakeLists.txt
+++ b/src/cython/CMakeLists.txt
@@ -103,6 +103,9 @@ if(PYTHON_PATH AND CYTHON_PATH)
file(GLOB GUDHI_CUBICAL_PERSEUS_FILES "${CMAKE_SOURCE_DIR}/data/bitmap/*cubicalcomplexdoc.txt")
file(COPY ${GUDHI_CUBICAL_PERSEUS_FILES} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/doc/")
file(COPY "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/doc/")
+ # Persistence graphical tools examples
+ file(COPY "${CMAKE_SOURCE_DIR}/data/bitmap/3d_torus.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/doc/")
+ file(COPY "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/doc/")
if (UNIX)
add_custom_target(html
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc
diff --git a/src/cython/cython/persistence_graphical_tools.py b/src/cython/cython/persistence_graphical_tools.py
index 247e119e..2a3d9f63 100755
--- a/src/cython/cython/persistence_graphical_tools.py
+++ b/src/cython/cython/persistence_graphical_tools.py
@@ -57,8 +57,7 @@ palette = ['#ff0000', '#00ff00', '#0000ff', '#00ffff', '#ff00ff', '#ffff00',
def show_palette_values(alpha=0.6):
"""This function shows palette color values in function of the dimension.
- :param alpha: alpha value in [0.0, 1.0] for horizontal bars (default is
- 0.6).
+ :param alpha: alpha value in [0.0, 1.0] for horizontal bars (default is 0.6).
:type alpha: float.
:returns: plot -- An horizontal bar plot of dimensions color.
"""
@@ -79,8 +78,7 @@ def barcode_persistence(persistence, alpha=0.6):
:param persistence: The persistence to plot.
:type persistence: list of tuples(dimension, tuple(birth, death)).
- :param alpha: alpha value in [0.0, 1.0] for horizontal bars (default is
- 0.6).
+ :param alpha: alpha value in [0.0, 1.0] for horizontal bars (default is 0.6).
:type alpha: float.
:returns: plot -- An horizontal bar plot of persistence.
"""
@@ -115,8 +113,7 @@ def diagram_persistence(persistence, alpha=0.6):
:param persistence: The persistence to plot.
:type persistence: list of tuples(dimension, tuple(birth, death)).
- :param alpha: alpha value in [0.0, 1.0] for points and horizontal infinity
- line (default is 0.6).
+ :param alpha: alpha value in [0.0, 1.0] for points and horizontal infinity line (default is 0.6).
:type alpha: float.
:returns: plot -- An diagram plot of persistence.
"""
diff --git a/src/cython/doc/conf.py b/src/cython/doc/conf.py
index 85b700a8..8d6483af 100755
--- a/src/cython/doc/conf.py
+++ b/src/cython/doc/conf.py
@@ -32,10 +32,10 @@ sys.path.insert(0, os.path.abspath('..'))
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
+ 'matplotlib.sphinxext.plot_directive',
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.todo',
- 'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
@@ -43,6 +43,9 @@ extensions = [
]
todo_include_todos = True
+# plot option : do not show hyperlinks (Source code, png, hires.png, pdf)
+plot_html_show_source_link = False
+plot_html_show_formats = False
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
diff --git a/src/cython/doc/img/graphical_tools_representation.png b/src/cython/doc/img/graphical_tools_representation.png
new file mode 100644
index 00000000..9759f7ba
--- /dev/null
+++ b/src/cython/doc/img/graphical_tools_representation.png
Binary files differ
diff --git a/src/cython/doc/index.rst b/src/cython/doc/index.rst
index 5245d69d..89e09d70 100644
--- a/src/cython/doc/index.rst
+++ b/src/cython/doc/index.rst
@@ -61,3 +61,8 @@ Persistence cohomology
======================
.. include:: persistent_cohomology_sum.rst
+
+Persistence graphical tools
+===========================
+
+.. include:: persistence_graphical_tools_sum.rst
diff --git a/src/cython/doc/pyplots/barcode_persistence.py b/src/cython/doc/pyplots/barcode_persistence.py
new file mode 100755
index 00000000..95bbd343
--- /dev/null
+++ b/src/cython/doc/pyplots/barcode_persistence.py
@@ -0,0 +1,5 @@
+import gudhi
+
+periodic_cc = gudhi.PeriodicCubicalComplex(perseus_file='../3d_torus.txt')
+diag = periodic_cc.persistence()
+gudhi.barcode_persistence(diag)
diff --git a/src/cython/doc/pyplots/diagram_persistence.py b/src/cython/doc/pyplots/diagram_persistence.py
new file mode 100755
index 00000000..ceeeceb3
--- /dev/null
+++ b/src/cython/doc/pyplots/diagram_persistence.py
@@ -0,0 +1,6 @@
+import gudhi
+
+alpha_complex = gudhi.AlphaComplex(off_file='../tore3D_300.off')
+alpha_complex.initialize_filtration()
+diag = alpha_complex.persistence()
+gudhi.diagram_persistence(diag)
diff --git a/src/cython/doc/pyplots/show_palette_values.py b/src/cython/doc/pyplots/show_palette_values.py
new file mode 100755
index 00000000..e72a55fd
--- /dev/null
+++ b/src/cython/doc/pyplots/show_palette_values.py
@@ -0,0 +1,2 @@
+import gudhi
+gudhi.show_palette_values(alpha=1.0)
diff --git a/src/cython/example/alpha_complex_from_file_example.py b/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py
index 81c4c0b7..8e534061 100755
--- a/src/cython/example/alpha_complex_from_file_example.py
+++ b/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
import gudhi
-import pandas
import argparse
"""This file is part of the Gudhi Library. The Gudhi library
@@ -30,35 +29,35 @@ __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.',
+ 'points read in a OFF file.',
epilog='Example: '
- 'example/alpha_complex_from_file_example.py '
- 'data/500_random_points_on_3D_Torus.csv '
+ 'example/alpha_complex_diagram_persistence_from_off_file_example.py '
+ '../data/points/tore3D_1307.off '
'- 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'))
+parser.add_argument("-f", "--file", type=str, required=True)
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)
-
-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())
-
-if args.no_diagram == False:
- gudhi.diagram_persistence(diag)
- gudhi.barcode_persistence(diag)
+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)
+
+ diag = alpha_complex.persistence(homology_coeff_field=2, min_persistence=0.1)
+
+ print("betti_numbers()=")
+ print(alpha_complex.betti_numbers())
+
+ if args.no_diagram == False:
+ gudhi.diagram_persistence(diag)
+ else:
+ print(args.file, "is not a valid OFF file")
+
+ f.close()
diff --git a/src/cython/example/cubical_complex_from_perseus_file_example.py b/src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py
index 23f7ece6..e6ba94e1 100755
--- a/src/cython/example/cubical_complex_from_perseus_file_example.py
+++ b/src/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py
@@ -1,10 +1,7 @@
#!/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++
@@ -32,25 +29,48 @@ __author__ = "Vincent Rouvreau"
__copyright__ = "Copyright (C) 2016 INRIA"
__license__ = "GPL v3"
-parser = argparse.ArgumentParser(description='Cubical complex from a perseus'
- 'file style name.',
+def is_file_perseus(file):
+ num_lines = open(file).read().count('\n')
+ try:
+ f = open(file)
+ num_dim = int(f.readline())
+ coeff = 1
+ for dim in range(0, num_dim):
+ try:
+ line = int(f.readline())
+ coeff *= abs(line)
+ except ValueError:
+ return False
+ if num_lines == (1 + num_dim + coeff):
+ return True
+ else:
+ return False
+ except ValueError:
+ return False
+
+parser = argparse.ArgumentParser(description='Periodic cubical complex from a '
+ 'perseus file style name.',
epilog='Example: '
- './cubical_complex_from_perseus_file_example.py'
+ './periodic_cubical_complex_from_perseus_file_example.py'
' -f ../data/bitmap/CubicalTwoSphere.txt')
parser.add_argument("-f", "--file", type=str, required=True)
+parser.add_argument('--no-barcode', default=False, action='store_true' , help='Flag for not to display the barcodes')
args = parser.parse_args()
-if os.access(args.file, os.R_OK):
+if is_file_perseus(args.file):
print("#####################################################################")
- print("CubicalComplex creation")
- cubical_complex = gudhi.CubicalComplex(perseus_file=args.file)
+ print("PeriodicCubicalComplex creation")
+ periodic_cubical_complex = gudhi.PeriodicCubicalComplex(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("persistence(homology_coeff_field=3, min_persistence=0)=")
+ diag = periodic_cubical_complex.persistence(homology_coeff_field=3, min_persistence=0)
+ print(diag)
print("betti_numbers()=")
- print(cubical_complex.betti_numbers())
+ print(periodic_cubical_complex.betti_numbers())
+ if args.no_barcode == False:
+ gudhi.barcode_persistence(diag)
else:
- print(args.file, "is unreachable")
+ print(args.file, "is not a valid perseus style file")
diff --git a/src/cython/include/Persistent_cohomology_interface.h b/src/cython/include/Persistent_cohomology_interface.h
index 58421799..faabc497 100644
--- a/src/cython/include/Persistent_cohomology_interface.h
+++ b/src/cython/include/Persistent_cohomology_interface.h
@@ -56,7 +56,7 @@ persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomol
public:
Persistent_cohomology_interface(FilteredComplex* stptr)
- : persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomology::Field_Zp>(*stptr),
+ : persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomology::Field_Zp>(*stptr, true),
stptr_(stptr) { }
std::vector<std::pair<int, std::pair<double, double>>> get_persistence(int homology_coeff_field, double min_persistence) {