summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-11-30 10:33:56 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2016-11-30 10:33:56 +0000
commitd7d59f1e4245af3595c8eafd0abc0abdc4b5805d (patch)
treebef4d3b905d018d15609e5c35c61412fe1b6dcaa
parent97d80185d6ec4d5e8f81b4cd4936d29a6d63b05b (diff)
Doc, examples and tests updates for tangential
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1805 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 56d080f79a7a0c3b6eb3ed38b376e899cb17c8f9
-rw-r--r--src/cython/cython/simplex_tree.pyx7
-rw-r--r--src/cython/cython/tangential_complex.pyx12
-rw-r--r--src/cython/doc/tangential_complex_user.rst23
-rwxr-xr-xsrc/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py3
-rwxr-xr-xsrc/cython/example/tangential_complex_plain_homology_from_off_file_example.py66
-rw-r--r--src/cython/include/Tangential_complex_interface.h9
-rwxr-xr-xsrc/cython/test/test_tangential_complex.py56
7 files changed, 164 insertions, 12 deletions
diff --git a/src/cython/cython/simplex_tree.pyx b/src/cython/cython/simplex_tree.pyx
index 06e2eb90..8f909398 100644
--- a/src/cython/cython/simplex_tree.pyx
+++ b/src/cython/cython/simplex_tree.pyx
@@ -1,6 +1,7 @@
from cython cimport numeric
from libcpp.vector cimport vector
from libcpp.utility cimport pair
+from libcpp cimport bool
"""This file is part of the Gudhi Library. The Gudhi library
(Geometric Understanding in Higher Dimensions) is a generic C++
@@ -54,7 +55,7 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi":
cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi":
cdef cppclass Simplex_tree_persistence_interface "Gudhi::Persistent_cohomology_interface<Gudhi::Simplex_tree<Gudhi::Simplex_tree_options_full_featured>>":
- Simplex_tree_persistence_interface(Simplex_tree_interface_full_featured * st)
+ Simplex_tree_persistence_interface(Simplex_tree_interface_full_featured * 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)
@@ -295,7 +296,7 @@ cdef class SimplexTree:
"""
self.thisptr.remove_maximal_simplex(simplex)
- def persistence(self, homology_coeff_field=11, min_persistence=0):
+ def persistence(self, homology_coeff_field=11, min_persistence=0, persistence_dim_max = False):
"""This function returns the persistence of the simplicial complex.
:param homology_coeff_field: The homology coefficient field. Must be a
@@ -311,7 +312,7 @@ cdef class SimplexTree:
"""
if self.pcohptr != NULL:
del self.pcohptr
- self.pcohptr = new Simplex_tree_persistence_interface(self.thisptr)
+ self.pcohptr = new Simplex_tree_persistence_interface(self.thisptr, persistence_dim_max)
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/tangential_complex.pyx b/src/cython/cython/tangential_complex.pyx
index f0e4eb02..5a7ebd1a 100644
--- a/src/cython/cython/tangential_complex.pyx
+++ b/src/cython/cython/tangential_complex.pyx
@@ -43,6 +43,7 @@ cdef extern from "Tangential_complex_interface.h" namespace "Gudhi":
unsigned number_of_inconsistent_simplices()
unsigned number_of_inconsistent_stars()
void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree)
+ void fix_inconsistencies_using_perturbation(double max_perturb, double time_limit)
# TangentialComplex python interface
cdef class TangentialComplex:
@@ -149,3 +150,14 @@ cdef class TangentialComplex:
simplex_tree = SimplexTree()
self.thisptr.create_simplex_tree(simplex_tree.thisptr)
return simplex_tree
+
+ def fix_inconsistencies_using_perturbation(self, max_perturb, time_limit=-1.0):
+ """Attempts to fix inconsistencies by perturbing the point positions.
+ :param max_perturb: Maximum length of the translations used by the
+ perturbation.
+ :type max_perturb: double
+ :param time_limit: Time limit in seconds. If -1, no time limit is set.
+ :type time_limit: double
+ """
+ self.thisptr.fix_inconsistencies_using_perturbation(max_perturb,
+ time_limit)
diff --git a/src/cython/doc/tangential_complex_user.rst b/src/cython/doc/tangential_complex_user.rst
index 33c03e34..30c97b8f 100644
--- a/src/cython/doc/tangential_complex_user.rst
+++ b/src/cython/doc/tangential_complex_user.rst
@@ -111,12 +111,12 @@ itself and/or after the perturbation process.
Simple example
--------------
-This example builds the Tangential complex of point set.
+This example builds the Tangential complex of point set read in an OFF file.
.. testcode::
import gudhi
- tc = gudhi.TangentialComplex(points=[[1, 1], [7, 0], [4, 6], [9, 6], [0, 14], [2, 19], [9, 17]])
+ tc = gudhi.TangentialComplex(off_file='alphacomplexdoc.off')
result_str = 'Tangential contains ' + repr(tc.num_simplices()) + \
' simplices - ' + repr(tc.num_vertices()) + ' vertices.'
print(result_str)
@@ -169,11 +169,24 @@ This example builds the Tangential complex of a point set, then tries to solve
inconsistencies by perturbing the positions of points involved in inconsistent
simplices.
-testcode::
+.. testcode::
import gudhi
- tc = gudhi.TangentialComplex(points=[[1, 1], [7, 0], [4, 6], [9, 6], [0, 14], [2, 19], [9, 17]])
+ tc = gudhi.TangentialComplex(points=[[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]])
+ result_str = 'Tangential contains ' + repr(tc.num_vertices()) + ' vertices.'
+ print(result_str)
+
+ if tc.num_inconsistent_simplices() > 0:
+ print('Tangential contains inconsistencies.')
+
+ tc.fix_inconsistencies_using_perturbation(10, 60)
+ if tc.num_inconsistent_simplices() == 0:
+ print('Inconsistencies has been fixed.')
The output is:
-testoutput::
+.. testoutput::
+
+ Tangential contains 4 vertices.
+ Tangential contains inconsistencies.
+ Inconsistencies has been fixed.
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 6cdd5506..ae03aa67 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
@@ -35,8 +35,7 @@ parser = argparse.ArgumentParser(description='AlphaComplex creation from '
'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 file. File format '
- 'is X1, X2, ..., Xn')
+ '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('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams')
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
new file mode 100755
index 00000000..be4c40be
--- /dev/null
+++ b/src/cython/example/tangential_complex_plain_homology_from_off_file_example.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+
+import gudhi
+import argparse
+
+"""This file is part of the Gudhi Library. The Gudhi library
+ (Geometric Understanding in Higher Dimensions) is a generic C++
+ library for computational topology.
+
+ Author(s): Vincent Rouvreau
+
+ Copyright (C) 2016 INRIA
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+
+__author__ = "Vincent Rouvreau"
+__copyright__ = "Copyright (C) 2016 INRIA"
+__license__ = "GPL v3"
+
+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'
+ '- Constructs a tangential complex with the '
+ 'points from the given OFF file')
+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()
+
+with open(args.file, 'r') as f:
+ first_line = f.readline()
+ if (first_line == 'OFF\n') or (first_line == 'nOFF\n'):
+ print("#####################################################################")
+ print("TangentialComplex creation from points read in a OFF file")
+
+ tc = gudhi.TangentialComplex(off_file=args.file)
+ st = tc.create_simplex_tree()
+
+ message = "Number of simplices=" + repr(st.num_simplices())
+ print(message)
+
+ diag = st.persistence(persistence_dim_max = True)
+
+ print("betti_numbers()=")
+ print(st.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/include/Tangential_complex_interface.h b/src/cython/include/Tangential_complex_interface.h
index c7fce557..9da32757 100644
--- a/src/cython/include/Tangential_complex_interface.h
+++ b/src/cython/include/Tangential_complex_interface.h
@@ -53,7 +53,7 @@ class Tangential_complex_interface {
Dynamic_kernel k;
unsigned intrisic_dim = 0;
if (points.size() > 0)
- intrisic_dim = points[0].size();
+ intrisic_dim = points[0].size() - 1;
tangential_complex_ = new TC(points, intrisic_dim, k);
tangential_complex_->compute_tangential_complex();
@@ -66,7 +66,7 @@ class Tangential_complex_interface {
unsigned intrisic_dim = 0;
std::vector<Point_d> points = off_reader.get_point_cloud();
if (points.size() > 0)
- intrisic_dim = points[0].size();
+ intrisic_dim = points[0].size() - 1;
tangential_complex_ = new TC(points, intrisic_dim, k);
tangential_complex_->compute_tangential_complex();
@@ -99,6 +99,11 @@ class Tangential_complex_interface {
return num_inconsistencies_.num_inconsistent_stars;
}
+ void fix_inconsistencies_using_perturbation(double max_perturb, double time_limit) {
+ tangential_complex_->fix_inconsistencies_using_perturbation(max_perturb, time_limit);
+ num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices();
+ }
+
void create_simplex_tree(Simplex_tree<>* simplex_tree) {
int max_dim = tangential_complex_->create_complex<Gudhi::Simplex_tree<Gudhi::Simplex_tree_options_full_featured>>(*simplex_tree);
// FIXME
diff --git a/src/cython/test/test_tangential_complex.py b/src/cython/test/test_tangential_complex.py
new file mode 100755
index 00000000..8e1b5c51
--- /dev/null
+++ b/src/cython/test/test_tangential_complex.py
@@ -0,0 +1,56 @@
+from gudhi import TangentialComplex, SimplexTree
+
+"""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 <http://www.gnu.org/licenses/>.
+"""
+
+__author__ = "Vincent Rouvreau"
+__copyright__ = "Copyright (C) 2016 INRIA"
+__license__ = "GPL v3"
+
+
+def test_tangential():
+ point_list = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]]
+ tc = TangentialComplex(points=point_list)
+ assert tc.__is_defined() == True
+ assert tc.num_vertices() == 4
+
+ st = tc.create_simplex_tree()
+ assert st.__is_defined() == True
+ assert st.__is_persistence_defined() == False
+
+ assert st.num_simplices() == 13
+ assert st.num_vertices() == 4
+
+ assert st.get_filtered_tree() == \
+ [([0], 0.0), ([1], 0.0), ([0, 1], 0.0), ([2], 0.0), ([0, 2], 0.0),
+ ([1, 2], 0.0), ([3], 0.0), ([0, 3], 0.0), ([1, 3], 0.0),
+ ([0, 1, 3], 0.0), ([2, 3], 0.0), ([0, 2, 3], 0.0),
+ ([1, 2, 3], 0.0)]
+ assert st.get_coface_tree([0], 1) == \
+ [([0, 1], 0.0), ([0, 2], 0.0), ([0, 3], 0.0)]
+
+ assert point_list[0] == tc.get_point(0)
+ assert point_list[1] == tc.get_point(1)
+ assert point_list[2] == tc.get_point(2)
+ assert point_list[3] == tc.get_point(3)
+ assert tc.get_point(4) == []
+ assert tc.get_point(125) == []