summaryrefslogtreecommitdiff
path: root/src/python
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2020-03-24 14:50:53 +0100
committerMarc Glisse <marc.glisse@inria.fr>2020-03-24 15:23:44 +0100
commitec4a9583adaa73c01b05a4b30425581ed7256379 (patch)
treeec5d9bb90fb86489c4dd1c7ea6a4b0d26083c31e /src/python
parentb7e19cf798e1dbf203380f1fe48aa0709177d7de (diff)
Remove min_persistence from generators
It is supposed to be handled in persistence() already.
Diffstat (limited to 'src/python')
-rw-r--r--src/python/CMakeLists.txt1
-rw-r--r--src/python/gudhi/simplex_tree.pxd4
-rw-r--r--src/python/gudhi/simplex_tree.pyx18
-rw-r--r--src/python/include/Persistent_cohomology_interface.h8
-rwxr-xr-xsrc/python/test/test_simplex_generators.py2
5 files changed, 10 insertions, 23 deletions
diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt
index f00966a5..fb219884 100644
--- a/src/python/CMakeLists.txt
+++ b/src/python/CMakeLists.txt
@@ -374,6 +374,7 @@ if(PYTHONINTERP_FOUND)
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/example/simplex_tree_example.py)
add_gudhi_py_test(test_simplex_tree)
+ add_gudhi_py_test(test_simplex_generators)
# Witness
add_test(NAME witness_complex_from_nearest_landmark_table_py_test
diff --git a/src/python/gudhi/simplex_tree.pxd b/src/python/gudhi/simplex_tree.pxd
index 44789365..4038b41d 100644
--- a/src/python/gudhi/simplex_tree.pxd
+++ b/src/python/gudhi/simplex_tree.pxd
@@ -75,5 +75,5 @@ cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi":
vector[pair[double,double]] intervals_in_dimension(int dimension)
void write_output_diagram(string diagram_file_name)
vector[pair[vector[int], vector[int]]] persistence_pairs()
- pair[vector[vector[int]], vector[vector[int]]] lower_star_generators(double)
- pair[vector[vector[int]], vector[vector[int]]] flag_generators(double)
+ pair[vector[vector[int]], vector[vector[int]]] lower_star_generators()
+ pair[vector[vector[int]], vector[vector[int]]] flag_generators()
diff --git a/src/python/gudhi/simplex_tree.pyx b/src/python/gudhi/simplex_tree.pyx
index faa9f9d8..beb40bc4 100644
--- a/src/python/gudhi/simplex_tree.pyx
+++ b/src/python/gudhi/simplex_tree.pyx
@@ -526,15 +526,10 @@ cdef class SimplexTree:
print("intervals_in_dim function requires persistence function"
" to be launched first.")
- def lower_star_persistence_generators(self, min_persistence=0.):
+ def lower_star_persistence_generators(self):
"""Assuming this is a lower-star filtration, this function returns the persistence pairs,
where each simplex is replaced with the vertex that gave it its filtration value.
- :param min_persistence: The minimum persistence value to take into
- account (strictly greater than min_persistence). Default value is
- 0.0.
- Set min_persistence to -1.0 to see all values.
- :type min_persistence: float.
:returns: First the regular persistence pairs, grouped by dimension, with one vertex per extremity,
and second the essential features, grouped by dimension, with one vertex each
:rtype: Tuple[List[numpy.array[int] of shape (n,2)], List[numpy.array[int] of shape (m,)]]
@@ -542,22 +537,17 @@ cdef class SimplexTree:
:note: lower_star_persistence_generators requires that `persistence()` be called first.
"""
if self.pcohptr != NULL:
- gen = self.pcohptr.lower_star_generators(min_persistence)
+ gen = self.pcohptr.lower_star_generators()
normal = [np_array(d).reshape(-1,2) for d in gen.first]
infinite = [np_array(d) for d in gen.second]
return (normal, infinite)
else:
print("lower_star_persistence_generators() requires that persistence() be called first.")
- def flag_persistence_generators(self, min_persistence=0.):
+ def flag_persistence_generators(self):
"""Assuming this is a flag complex, this function returns the persistence pairs,
where each simplex is replaced with the vertices of the edges that gave it its filtration value.
- :param min_persistence: The minimum persistence value to take into
- account (strictly greater than min_persistence). Default value is
- 0.0.
- Set min_persistence to -1.0 to see all values.
- :type min_persistence: float.
:returns: First the regular persistence pairs of dimension 0, with one vertex for birth and two for death;
then the other regular persistence pairs, grouped by dimension, with 2 vertices per extremity;
then the connected components, with one vertex each;
@@ -567,7 +557,7 @@ cdef class SimplexTree:
:note: flag_persistence_generators requires that `persistence()` be called first.
"""
if self.pcohptr != NULL:
- gen = self.pcohptr.flag_generators(min_persistence)
+ gen = self.pcohptr.flag_generators()
if len(gen.first) == 0:
normal0 = numpy.empty((0,3))
normals = []
diff --git a/src/python/include/Persistent_cohomology_interface.h b/src/python/include/Persistent_cohomology_interface.h
index 3ce40af5..3074389c 100644
--- a/src/python/include/Persistent_cohomology_interface.h
+++ b/src/python/include/Persistent_cohomology_interface.h
@@ -100,7 +100,7 @@ persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomol
// - an option to return only some of those vectors?
typedef std::pair<std::vector<std::vector<int>>, std::vector<std::vector<int>>> Generators;
- Generators lower_star_generators(double min_persistence) {
+ Generators lower_star_generators() {
Generators out;
// diags[i] should be interpreted as vector<array<int,2>>
auto& diags = out.first;
@@ -109,8 +109,6 @@ persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomol
for (auto pair : Base::get_persistent_pairs()) {
auto s = std::get<0>(pair);
auto t = std::get<1>(pair);
- if(stptr_->filtration(t) - stptr_->filtration(s) <= min_persistence)
- continue;
int dim = stptr_->dimension(s);
auto v = stptr_->vertex_with_same_filtration(s);
if(t == stptr_->null_simplex()) {
@@ -128,7 +126,7 @@ persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomol
// An alternative, to avoid those different sizes, would be to "pad" vertex generator v as (v, v) or (v, -1). When using it as index, this corresponds to adding the vertex filtration values either on the diagonal of the distance matrix, or as an extra row or column.
// We could also merge the vectors for different dimensions into a single one, with an extra column for the dimension (converted to type double).
- Generators flag_generators(double min_persistence) {
+ Generators flag_generators() {
Generators out;
// diags[0] should be interpreted as vector<array<int,3>> and other diags[i] as vector<array<int,4>>
auto& diags = out.first;
@@ -137,8 +135,6 @@ persistent_cohomology::Persistent_cohomology<FilteredComplex, persistent_cohomol
for (auto pair : Base::get_persistent_pairs()) {
auto s = std::get<0>(pair);
auto t = std::get<1>(pair);
- if(stptr_->filtration(t) - stptr_->filtration(s) <= min_persistence)
- continue;
int dim = stptr_->dimension(s);
bool infinite = t == stptr_->null_simplex();
if(infinite) {
diff --git a/src/python/test/test_simplex_generators.py b/src/python/test/test_simplex_generators.py
index efb5f8e3..e3bdc094 100755
--- a/src/python/test/test_simplex_generators.py
+++ b/src/python/test/test_simplex_generators.py
@@ -37,7 +37,7 @@ def test_lower_star_generators():
st.assign_filtration([1], 2)
st.make_filtration_non_decreasing()
st.persistence(min_persistence=-1)
- g = st.lower_star_persistence_generators(min_persistence=-1)
+ g = st.lower_star_persistence_generators()
assert len(g[0]) == 2
assert np.array_equal(g[0][0], [[0, 0], [3, 0], [1, 1]])
assert np.array_equal(g[0][1], [[1, 1]])