summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/pandas/2000_random_points_on_3D_Torus.csv (renamed from src/cython/data/2000_random_points_on_3D_Torus.csv)0
-rw-r--r--data/pandas/2500_random_points_on_5D_Sphere.csv (renamed from src/cython/data/2500_random_points_on_5D_Sphere.csv)0
-rw-r--r--data/pandas/500_random_points_on_3D_Torus.csv (renamed from src/cython/data/500_random_points_on_3D_Torus.csv)0
-rw-r--r--src/cython/cython/cubical_complex.pyx27
-rw-r--r--src/cython/cython/periodic_cubical_complex.pyx28
-rwxr-xr-xsrc/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py15
-rwxr-xr-xsrc/cython/example/periodic_cubical_complex_barcode_persistence_from_perseus_file_example.py2
-rwxr-xr-xsrc/cython/example/random_cubical_complex_persistence_example.py (renamed from src/cython/example/random_cubical_complex_example.py)8
-rwxr-xr-xsrc/cython/example/rips_complex_diagram_persistence_with_pandas_interface_example.py (renamed from src/cython/example/rips_complex_from_file_example.py)24
-rwxr-xr-xsrc/cython/example/rips_complex_from_points_example.py (renamed from src/cython/example/rips_complex_example.py)3
-rwxr-xr-xsrc/cython/example/simplex_tree_example.py3
-rw-r--r--src/cython/include/Persistent_cohomology_interface.h14
-rwxr-xr-xsrc/cython/test/test_cubical_complex.py4
13 files changed, 67 insertions, 61 deletions
diff --git a/src/cython/data/2000_random_points_on_3D_Torus.csv b/data/pandas/2000_random_points_on_3D_Torus.csv
index c1fefb9f..c1fefb9f 100644
--- a/src/cython/data/2000_random_points_on_3D_Torus.csv
+++ b/data/pandas/2000_random_points_on_3D_Torus.csv
diff --git a/src/cython/data/2500_random_points_on_5D_Sphere.csv b/data/pandas/2500_random_points_on_5D_Sphere.csv
index f7cc8e84..f7cc8e84 100644
--- a/src/cython/data/2500_random_points_on_5D_Sphere.csv
+++ b/data/pandas/2500_random_points_on_5D_Sphere.csv
diff --git a/src/cython/data/500_random_points_on_3D_Torus.csv b/data/pandas/500_random_points_on_3D_Torus.csv
index adb6e1da..adb6e1da 100644
--- a/src/cython/data/500_random_points_on_3D_Torus.csv
+++ b/data/pandas/500_random_points_on_3D_Torus.csv
diff --git a/src/cython/cython/cubical_complex.pyx b/src/cython/cython/cubical_complex.pyx
index 3441b2e9..321fc22a 100644
--- a/src/cython/cython/cubical_complex.pyx
+++ b/src/cython/cython/cubical_complex.pyx
@@ -2,6 +2,7 @@ from cython cimport numeric
from libcpp.vector cimport vector
from libcpp.utility cimport pair
from libcpp.string cimport string
+from libcpp cimport bool
import os
"""This file is part of the Gudhi Library. The Gudhi library
@@ -39,7 +40,7 @@ cdef extern from "Cubical_complex_interface.h" namespace "Gudhi":
cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi":
cdef cppclass Cubical_complex_persistence_interface "Gudhi::Persistent_cohomology_interface<Gudhi::Cubical_complex::Cubical_complex_interface<>>":
- Cubical_complex_persistence_interface(Bitmap_cubical_complex_base_interface * st)
+ Cubical_complex_persistence_interface(Bitmap_cubical_complex_base_interface * st, bool persistence_dim_max)
vector[pair[int, pair[double, double]]] get_persistence(int homology_coeff_field, double min_persistence)
vector[int] betti_numbers()
vector[int] persistent_betti_numbers(double from_value, double to_value)
@@ -75,20 +76,16 @@ cdef class CubicalComplex:
# The real cython constructor
def __cinit__(self, dimensions=None, top_dimensional_cells=None,
perseus_file=''):
- if ((dimensions is not None) or (top_dimensional_cells is not None) and
- (perseus_file is not '')):
- print("CubicalComplex can be constructed from dimensions and "
- "top_dimensional_cells or from a perseus file style name.")
- else:
- if dimensions is not None:
- if top_dimensional_cells is not None:
- self.thisptr = new Bitmap_cubical_complex_base_interface(dimensions, top_dimensional_cells)
+ if (dimensions is not None) and (top_dimensional_cells is not None) and (perseus_file is ''):
+ self.thisptr = new Bitmap_cubical_complex_base_interface(dimensions, top_dimensional_cells)
+ elif (dimensions is None) and (top_dimensional_cells is None) and (perseus_file is not ''):
+ if os.path.isfile(perseus_file):
+ self.thisptr = new Bitmap_cubical_complex_base_interface(perseus_file)
else:
- if perseus_file is not '':
- if os.path.isfile(perseus_file):
- self.thisptr = new Bitmap_cubical_complex_base_interface(perseus_file)
- else:
- print("file " + perseus_file + " not found.")
+ print("file " + perseus_file + " not found.")
+ else:
+ print("CubicalComplex can be constructed from dimensions and "
+ "top_dimensional_cells or from a perseus file style name.")
def __dealloc__(self):
if self.thisptr != NULL:
@@ -138,7 +135,7 @@ cdef class CubicalComplex:
if self.pcohptr != NULL:
del self.pcohptr
if self.thisptr != NULL:
- self.pcohptr = new Cubical_complex_persistence_interface(self.thisptr)
+ self.pcohptr = new Cubical_complex_persistence_interface(self.thisptr, True)
cdef vector[pair[int, pair[double, double]]] persistence_result
if self.pcohptr != NULL:
persistence_result = self.pcohptr.get_persistence(homology_coeff_field, min_persistence)
diff --git a/src/cython/cython/periodic_cubical_complex.pyx b/src/cython/cython/periodic_cubical_complex.pyx
index d56eb5b1..c1b25f31 100644
--- a/src/cython/cython/periodic_cubical_complex.pyx
+++ b/src/cython/cython/periodic_cubical_complex.pyx
@@ -2,6 +2,7 @@ from cython cimport numeric
from libcpp.vector cimport vector
from libcpp.utility cimport pair
from libcpp.string cimport string
+from libcpp cimport bool
import os
"""This file is part of the Gudhi Library. The Gudhi library
@@ -39,7 +40,7 @@ cdef extern from "Cubical_complex_interface.h" namespace "Gudhi":
cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi":
cdef cppclass Periodic_cubical_complex_persistence_interface "Gudhi::Persistent_cohomology_interface<Gudhi::Cubical_complex::Cubical_complex_interface<Gudhi::cubical_complex::Bitmap_cubical_complex_periodic_boundary_conditions_base<double>>>":
- Periodic_cubical_complex_persistence_interface(Periodic_cubical_complex_base_interface * st)
+ Periodic_cubical_complex_persistence_interface(Periodic_cubical_complex_base_interface * st, bool persistence_dim_max)
vector[pair[int, pair[double, double]]] get_persistence(int homology_coeff_field, double min_persistence)
vector[int] betti_numbers()
vector[int] persistent_betti_numbers(double from_value, double to_value)
@@ -75,21 +76,16 @@ cdef class PeriodicCubicalComplex:
# The real cython constructor
def __cinit__(self, dimensions=None, top_dimensional_cells=None,
perseus_file=''):
- if ((dimensions is not None) or (top_dimensional_cells is not None) and
- (perseus_file is not '')):
- print("PeriodicCubicalComplex can be constructed from dimensions"
- " and top_dimensional_cells or from a perseus file style "
- "name.")
- else:
- if dimensions is not None:
- if top_dimensional_cells is not None:
- self.thisptr = new Periodic_cubical_complex_base_interface(dimensions, top_dimensional_cells)
+ if (dimensions is not None) and (top_dimensional_cells is not None) and (perseus_file is ''):
+ self.thisptr = new Periodic_cubical_complex_base_interface(dimensions, top_dimensional_cells)
+ elif (dimensions is None) and (top_dimensional_cells is None) and (perseus_file is not ''):
+ if os.path.isfile(perseus_file):
+ self.thisptr = new Periodic_cubical_complex_base_interface(perseus_file)
else:
- if perseus_file is not '':
- if os.path.isfile(perseus_file):
- self.thisptr = new Periodic_cubical_complex_base_interface(perseus_file)
- else:
- print("file " + perseus_file + " not found.")
+ print("file " + perseus_file + " not found.")
+ else:
+ print("CubicalComplex can be constructed from dimensions and "
+ "top_dimensional_cells or from a perseus file style name.")
def __dealloc__(self):
if self.thisptr != NULL:
@@ -139,7 +135,7 @@ cdef class PeriodicCubicalComplex:
if self.pcohptr != NULL:
del self.pcohptr
if self.thisptr != NULL:
- self.pcohptr = new Periodic_cubical_complex_persistence_interface(self.thisptr)
+ self.pcohptr = new Periodic_cubical_complex_persistence_interface(self.thisptr, True)
cdef vector[pair[int, pair[double, double]]] persistence_result
if self.pcohptr != NULL:
persistence_result = self.pcohptr.get_persistence(homology_coeff_field, min_persistence)
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_persistence_example.py
index 147eaa49..1c55f777 100755
--- a/src/cython/example/random_cubical_complex_example.py
+++ b/src/cython/example/random_cubical_complex_persistence_example.py
@@ -34,10 +34,10 @@ __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).')
+ './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')
diff --git a/src/cython/example/rips_complex_from_file_example.py b/src/cython/example/rips_complex_diagram_persistence_with_pandas_interface_example.py
index fae72443..bcf2fbcb 100755
--- a/src/cython/example/rips_complex_from_file_example.py
+++ b/src/cython/example/rips_complex_diagram_persistence_with_pandas_interface_example.py
@@ -36,27 +36,33 @@ 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 '
+ '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('file', type=argparse.FileType('r'))
+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)
-print("RipsComplex with max_edge_length=0.7")
+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=0.7)
+ 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(homology_coeff_field=2, min_persistence=0.3)
+diag = rips_complex.persistence()
print("betti_numbers()=")
print(rips_complex.betti_numbers())
-gudhi.diagram_persistence(diag)
-
-gudhi.barcode_persistence(diag)
+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_from_points_example.py
index 65246c9c..1a22d8e3 100755
--- a/src/cython/example/rips_complex_example.py
+++ b/src/cython/example/rips_complex_from_points_example.py
@@ -36,6 +36,3 @@ rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]],
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/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))
diff --git a/src/cython/include/Persistent_cohomology_interface.h b/src/cython/include/Persistent_cohomology_interface.h
index faabc497..1ff0e09b 100644
--- a/src/cython/include/Persistent_cohomology_interface.h
+++ b/src/cython/include/Persistent_cohomology_interface.h
@@ -34,6 +34,7 @@ template<class FilteredComplex>
class Persistent_cohomology_interface : public
persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomology::Field_Zp> {
private:
+
/*
* Compare two intervals by dimension, then by length.
*/
@@ -56,18 +57,23 @@ persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomol
public:
Persistent_cohomology_interface(FilteredComplex* stptr)
- : persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomology::Field_Zp>(*stptr, true),
+ : persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomology::Field_Zp>(*stptr),
+ stptr_(stptr) { }
+
+ Persistent_cohomology_interface(FilteredComplex* stptr, bool persistence_dim_max)
+ : persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomology::Field_Zp>(*stptr,
+ persistence_dim_max),
stptr_(stptr) { }
std::vector<std::pair<int, std::pair<double, double>>> get_persistence(int homology_coeff_field, double min_persistence) {
persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomology::Field_Zp>::init_coefficients(homology_coeff_field);
persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomology::Field_Zp>::compute_persistent_cohomology(min_persistence);
-
+
// Custom sort and output persistence
cmp_intervals_by_dim_then_length cmp(stptr_);
auto persistent_pairs = persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomology::Field_Zp>::get_persistent_pairs();
std::sort(std::begin(persistent_pairs), std::end(persistent_pairs), cmp);
-
+
std::vector<std::pair<int, std::pair<double, double>>> persistence;
for (auto pair : persistent_pairs) {
persistence.push_back(std::make_pair(stptr_->dimension(get<0>(pair)),
@@ -77,7 +83,7 @@ persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomol
return persistence;
}
-
+
private:
// A copy
FilteredComplex* stptr_;
diff --git a/src/cython/test/test_cubical_complex.py b/src/cython/test/test_cubical_complex.py
index af4c34ef..c8df8089 100755
--- a/src/cython/test/test_cubical_complex.py
+++ b/src/cython/test/test_cubical_complex.py
@@ -82,5 +82,5 @@ def test_dimension_constructor():
assert cub.__is_persistence_defined() == False
assert cub.persistence() == [(1, (0.0, 100.0)), (0, (0.0, 1.8446744073709552e+19))]
assert cub.__is_persistence_defined() == True
- assert cub.betti_numbers() == [1, 0]
- assert cub.persistent_betti_numbers(0, 1000) == [1, 0]
+ assert cub.betti_numbers() == [1, 0, 0]
+ assert cub.persistent_betti_numbers(0, 1000) == [1, 0, 0]