diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp | 3 | ||||
-rw-r--r-- | src/Rips_complex/include/gudhi/Rips_complex.h | 15 | ||||
-rw-r--r-- | src/Simplex_tree/example/simple_simplex_tree.cpp | 77 | ||||
-rw-r--r-- | src/cython/cython/simplex_tree.pyx | 20 | ||||
-rwxr-xr-x | src/cython/test/test_simplex_tree.py | 35 |
5 files changed, 148 insertions, 2 deletions
diff --git a/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp b/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp index 3fd69ebc..da915ecb 100644 --- a/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp +++ b/src/Rips_complex/example/example_one_skeleton_rips_from_points.cpp @@ -30,7 +30,8 @@ int main() { Rips_complex rips_complex_from_points(points, threshold, Euclidean_distance()); Simplex_tree stree; - rips_complex_from_points.create_complex(stree, 1); + rips_complex_from_points.create_complex(stree, 3); + stree.initialize_filtration(); // ---------------------------------------------------------------------------- // Display information about the one skeleton Rips complex // ---------------------------------------------------------------------------- diff --git a/src/Rips_complex/include/gudhi/Rips_complex.h b/src/Rips_complex/include/gudhi/Rips_complex.h index 1e4b76a7..42669e8b 100644 --- a/src/Rips_complex/include/gudhi/Rips_complex.h +++ b/src/Rips_complex/include/gudhi/Rips_complex.h @@ -116,6 +116,21 @@ class Rips_complex { // insert the proximity graph in the simplicial complex complex.insert_graph(rips_skeleton_graph_); + + std::cout << "********************************************************************\n"; + // Display the complex + std::cout << "* The complex contains " << complex.num_simplices() << " simplices\n"; + std::cout << " - dimension " << complex.dimension() << " - filtration " << complex.filtration() << "\n"; + std::cout << "* Iterator on Simplices in the filtration, with [filtration value]:\n"; + for (auto f_simplex : complex.filtration_simplex_range()) { + std::cout << " " << "[" << complex.filtration(f_simplex) << "] "; + for (auto vertex : complex.simplex_vertex_range(f_simplex)) { + std::cout << static_cast<int>(vertex) << " "; + } + std::cout << std::endl; + } + + // expand the graph until dimension dim_max complex.expansion(dim_max); } diff --git a/src/Simplex_tree/example/simple_simplex_tree.cpp b/src/Simplex_tree/example/simple_simplex_tree.cpp index 60f9a35e..19073305 100644 --- a/src/Simplex_tree/example/simple_simplex_tree.cpp +++ b/src/Simplex_tree/example/simple_simplex_tree.cpp @@ -250,5 +250,80 @@ int main(int argc, char * const argv[]) { std::cout << "***+ YES IT IS!\n"; else std::cout << "***- NO IT ISN'T\n"; - return 0; + //return 0; + + /* [0] 0 + [0] 1 + [0] 2 + [0] 3 + [0] 4 + [0] 5 + [0] 6 + [5] 3 2 + [5.38516] 5 4 + [5.83095] 2 0 + [6.08276] 1 0 + [6.32456] 3 1 + [6.7082] 2 1 + [7.28011] 6 5 + [8.94427] 4 2 + [9.43398] 3 0 + [9.48683] 6 4 + [11] 6 3 + */ + Simplex_tree stree; + typeVectorVertex graph = { 3, 2 }; + stree.insert_simplex(graph, Filtration_value(0.1)); + graph = { 2, 0 }; + stree.insert_simplex(graph, Filtration_value(0.1)); + graph = { 1, 0 }; + stree.insert_simplex(graph, Filtration_value(0.1)); + graph = { 3, 1 }; + stree.insert_simplex(graph, Filtration_value(0.1)); + graph = { 2, 1 }; + stree.insert_simplex(graph, Filtration_value(0.1)); + graph = { 6, 5 }; + stree.insert_simplex(graph, Filtration_value(0.1)); + graph = { 4, 2 }; + stree.insert_simplex(graph, Filtration_value(0.1)); + graph = { 3, 0 }; + stree.insert_simplex(graph, Filtration_value(0.1)); + graph = { 6, 4 }; + stree.insert_simplex(graph, Filtration_value(0.1)); + graph = { 6, 3 }; + stree.insert_simplex(graph, Filtration_value(0.1)); + + + // ++ GENERAL VARIABLE SET + stree.set_filtration(0.1); // Max filtration value + stree.set_dimension(2); // Max dimension = 2 -> (2,1,0) + + std::cout << "********************************************************************\n"; + // Display the stree + std::cout << "* The complex contains " << stree.num_simplices() << " simplices\n"; + std::cout << " - dimension " << stree.dimension() << " - filtration " << stree.filtration() << "\n"; + std::cout << "* Iterator on Simplices in the filtration, with [filtration value]:\n"; + for (auto f_simplex : stree.filtration_simplex_range()) { + std::cout << " " << "[" << stree.filtration(f_simplex) << "] "; + for (auto vertex : stree.simplex_vertex_range(f_simplex)) { + std::cout << static_cast<int>(vertex) << " "; + } + std::cout << std::endl; + } + + stree.expansion(2); + stree.initialize_filtration(); + + std::cout << "********************************************************************\n"; + // Display the stree + std::cout << "* The complex contains " << stree.num_simplices() << " simplices\n"; + std::cout << " - dimension " << stree.dimension() << " - filtration " << stree.filtration() << "\n"; + std::cout << "* Iterator on Simplices in the filtration, with [filtration value]:\n"; + for (auto f_simplex : stree.filtration_simplex_range()) { + std::cout << " " << "[" << stree.filtration(f_simplex) << "] "; + for (auto vertex : stree.simplex_vertex_range(f_simplex)) { + std::cout << static_cast<int>(vertex) << " "; + } + std::cout << std::endl; + } } diff --git a/src/cython/cython/simplex_tree.pyx b/src/cython/cython/simplex_tree.pyx index bb6fd1db..489c711f 100644 --- a/src/cython/cython/simplex_tree.pyx +++ b/src/cython/cython/simplex_tree.pyx @@ -52,6 +52,7 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": vector[pair[vector[int], double]] get_cofaces(vector[int] simplex, int dimension) void remove_maximal_simplex(vector[int] simplex) + void expansion(int max_dim) 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>>": @@ -304,6 +305,25 @@ cdef class SimplexTree: """ self.thisptr.remove_maximal_simplex(simplex) + def expansion(self, max_dim): + """Expands the Simplex_tree containing only its one skeleton + until dimension max_dim. + + The expanded simplicial complex until dimension :math:`d` + attached to a graph :math:`G` is the maximal simplicial complex of + dimension at most :math:`d` admitting the graph :math:`G` as + :math:`1`-skeleton. + The filtration value assigned to a simplex is the maximal filtration + value of one of its edges. + + The Simplex_tree must contain no simplex of dimension bigger than + 1 when calling the method. + + :param max_dim: The maximal dimension. + :type max_dim: int. + """ + self.thisptr.expansion(max_dim) + def persistence(self, homology_coeff_field=11, min_persistence=0, persistence_dim_max = False): """This function returns the persistence of the simplicial complex. diff --git a/src/cython/test/test_simplex_tree.py b/src/cython/test/test_simplex_tree.py index 7466bf1d..db61f84c 100755 --- a/src/cython/test/test_simplex_tree.py +++ b/src/cython/test/test_simplex_tree.py @@ -96,3 +96,38 @@ def test_insertion(): assert st.persistent_betti_numbers(3.9, 10000.0) == [1, 0] assert st.persistent_betti_numbers(4.0, 10000.0) == [1, 1] assert st.persistent_betti_numbers(9999.0, 10000.0) == [1, 1] + +def test_expansion(): + st = SimplexTree() + assert st.__is_defined() == True + assert st.__is_persistence_defined() == False + + # insert test + assert st.insert([3, 2], 0.1) == True + assert st.insert([2, 0], 0.2) == True + assert st.insert([1, 0], 0.3) == True + assert st.insert([3, 1], 0.4) == True + assert st.insert([2, 1], 0.5) == True + assert st.insert([6, 5], 0.6) == True + assert st.insert([4, 2], 0.7) == True + assert st.insert([3, 0], 0.8) == True + assert st.insert([6, 4], 0.9) == True + assert st.insert([6, 3], 1.0) == True + + assert st.num_vertices() == 7 + assert st.num_simplices() == 17 + assert st.get_filtered_tree() == [([2], 0.1), ([3], 0.1), ([2, 3], 0.1), + ([0], 0.2), ([0, 2], 0.2), ([1], 0.3), ([0, 1], 0.3), ([1, 3], 0.4), + ([1, 2], 0.5), ([5], 0.6), ([6], 0.6), ([5, 6], 0.6), ([4], 0.7), + ([2, 4], 0.7), ([0, 3], 0.8), ([4, 6], 0.9), ([3, 6], 1.0)] + + st.expansion(3) + assert st.num_vertices() == 7 + assert st.num_simplices() == 22 + st.initialize_filtration() + + assert st.get_filtered_tree() == [([2], 0.1), ([3], 0.1), ([2, 3], 0.1), + ([0], 0.2), ([0, 2], 0.2), ([1], 0.3), ([0, 1], 0.3), ([1, 3], 0.4), + ([1, 2], 0.5), ([0, 1, 2], 0.5), ([1, 2, 3], 0.5), ([5], 0.6), ([6], 0.6), + ([5, 6], 0.6), ([4], 0.7), ([2, 4], 0.7), ([0, 3], 0.8), ([0, 1, 3], 0.8), + ([0, 2, 3], 0.8), ([0, 1, 2, 3], 0.8), ([4, 6], 0.9), ([3, 6], 1.0)] |