diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-06-09 08:31:11 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-06-09 08:31:11 +0000 |
commit | fee0420f4e8ef4a23934c1966938dfc0f41131be (patch) | |
tree | 2319916df7526524ec97236435e0e3146de8d773 /src/cython | |
parent | 24cf70e130a5e999cb16de3fcecd7c53d98c381b (diff) |
Witness complex cythonization
Review of graphical tools
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1264 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 35d1204190e4324cb9f9e4f8679c13c8ad080f51
Diffstat (limited to 'src/cython')
-rwxr-xr-x | src/cython/example/alpha_complex_from_file_example.py | 2 | ||||
-rwxr-xr-x | src/cython/example/gudhi_graphical_tools_example.py | 9 | ||||
-rwxr-xr-x | src/cython/example/rips_complex_from_file_example.py | 2 | ||||
-rwxr-xr-x | src/cython/example/witness_complex_from_file_example.py | 70 | ||||
-rw-r--r-- | src/cython/gudhi.pyx | 1 | ||||
-rw-r--r-- | src/cython/src/cpp/Witness_complex_interface.h | 187 | ||||
-rwxr-xr-x | src/cython/src/cython/persistence_graphical_tools.py | 35 | ||||
-rw-r--r-- | src/cython/src/cython/witness_complex.pyx | 309 |
8 files changed, 597 insertions, 18 deletions
diff --git a/src/cython/example/alpha_complex_from_file_example.py b/src/cython/example/alpha_complex_from_file_example.py index d1040e83..beb5d101 100755 --- a/src/cython/example/alpha_complex_from_file_example.py +++ b/src/cython/example/alpha_complex_from_file_example.py @@ -59,4 +59,4 @@ print(alpha_complex.betti_numbers()) gudhi.diagram_persistence(diag) -gudhi.bar_code_persistence(diag) +gudhi.barcode_persistence(diag) diff --git a/src/cython/example/gudhi_graphical_tools_example.py b/src/cython/example/gudhi_graphical_tools_example.py index c43b2338..40558bee 100755 --- a/src/cython/example/gudhi_graphical_tools_example.py +++ b/src/cython/example/gudhi_graphical_tools_example.py @@ -34,9 +34,14 @@ print("Show palette colors values for dimension") gudhi.show_palette_values() print("#####################################################################") -print("Show bar code persistence example") +print("Show barcode persistence example") persistence = [(2, (1.0, float('inf'))), (1, (1.4142135623730951, float('inf'))), (1, (1.4142135623730951, float('inf'))), (0, (0.0, float('inf'))), (0, (0.0, 1.0)), (0, (0.0, 1.0)), (0, (0.0, 1.0))] -gudhi.bar_code_persistence(persistence) +gudhi.barcode_persistence(persistence) + +print("#####################################################################") +print("Show diagram persistence example") + +gudhi.diagram_persistence(persistence) diff --git a/src/cython/example/rips_complex_from_file_example.py b/src/cython/example/rips_complex_from_file_example.py index 1831a5e9..9385aba0 100755 --- a/src/cython/example/rips_complex_from_file_example.py +++ b/src/cython/example/rips_complex_from_file_example.py @@ -59,4 +59,4 @@ print(rips_complex.betti_numbers()) gudhi.diagram_persistence(diag) -gudhi.bar_code_persistence(diag) +gudhi.barcode_persistence(diag) diff --git a/src/cython/example/witness_complex_from_file_example.py b/src/cython/example/witness_complex_from_file_example.py new file mode 100755 index 00000000..9d1a940f --- /dev/null +++ b/src/cython/example/witness_complex_from_file_example.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python + +import gudhi +import pandas +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" + +print("#####################################################################") +print("WitnessComplex creation from points read in a file") + +parser = argparse.ArgumentParser(description='WitnessComplex creation from ' + 'points read in a file.', + epilog='Example: ' + 'example/witness_complex_from_file_example.py' + ' data/500_random_points_on_3D_Torus.csv ' + '- Constructs a witness complex with the ' + 'points from the given file. File format ' + 'is X1, X2, ..., Xn') +parser.add_argument('file', type=argparse.FileType('r')) +args = parser.parse_args() + +points = pandas.read_csv(args.file, header=None) + +print("WitnessComplex with number_of_landmarks=5") + +witness_complex = gudhi.WitnessComplex(points=points.values, + number_of_landmarks=200) + +print("filtered_tree=", witness_complex.get_filtered_tree()) + +witness_complex.initialize_filtration() +diag = witness_complex.persistence(homology_coeff_field=2, min_persistence=0.1) + +print("diag=", diag) + +gudhi.diagram_persistence(diag) + +""" +print("betti_numbers()=") +print(witness_complex.betti_numbers()) + +gudhi.diagram_persistence(diag) + +gudhi.barcode_persistence(diag) +"""
\ No newline at end of file diff --git a/src/cython/gudhi.pyx b/src/cython/gudhi.pyx index b8cb032e..c16852b8 100644 --- a/src/cython/gudhi.pyx +++ b/src/cython/gudhi.pyx @@ -29,4 +29,5 @@ include "src/cython/mini_simplex_tree.pyx" include "src/cython/rips_complex.pyx" include "src/cython/alpha_complex.pyx" include "src/cython/cubical_complex.pyx" +include "src/cython/witness_complex.pyx" include "src/cython/persistence_graphical_tools.py" diff --git a/src/cython/src/cpp/Witness_complex_interface.h b/src/cython/src/cpp/Witness_complex_interface.h new file mode 100644 index 00000000..bdfea91f --- /dev/null +++ b/src/cython/src/cpp/Witness_complex_interface.h @@ -0,0 +1,187 @@ +/* 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/>. + */ + +#ifndef WITNESS_COMPLEX_INTERFACE_H +#define WITNESS_COMPLEX_INTERFACE_H + +#include <gudhi/Simplex_tree.h> +#include <gudhi/Witness_complex.h> +#include <gudhi/Landmark_choice_by_furthest_point.h> + +#include "Persistent_cohomology_interface.h" + +#include <vector> +#include <utility> // std::pair +#include <iostream> + +namespace Gudhi { + +namespace witness_complex { + +class Witness_complex_interface { + typedef typename Simplex_tree<>::Simplex_handle Simplex_handle; + typedef typename std::pair<Simplex_handle, bool> Insertion_result; + using Simplex = std::vector<Vertex_handle>; + using Filtered_complex = std::pair<Simplex, Filtration_value>; + using Complex_tree = std::vector<Filtered_complex>; + + public: + Witness_complex_interface(std::vector<std::vector<double>>&points, int number_of_landmarks) + : pcoh_(nullptr) { + std::vector<std::vector< int > > knn; + + Gudhi::witness_complex::landmark_choice_by_furthest_point(points, number_of_landmarks, knn); + Gudhi::witness_complex::witness_complex(knn, number_of_landmarks, points[0].size(), simplex_tree_); + + } + + bool find_simplex(const Simplex& vh) { + return (simplex_tree_.find(vh) != simplex_tree_.null_simplex()); + } + + bool insert_simplex_and_subfaces(const Simplex& complex, Filtration_value filtration = 0) { + Insertion_result result = simplex_tree_.insert_simplex_and_subfaces(complex, filtration); + return (result.second); + } + + Filtration_value simplex_filtration(const Simplex& complex) { + return simplex_tree_.filtration(simplex_tree_.find(complex)); + } + + void remove_maximal_simplex(const Simplex& complex) { + return simplex_tree_.remove_maximal_simplex(simplex_tree_.find(complex)); + } + + Complex_tree get_filtered_tree() { + Complex_tree filtered_tree; + for (auto f_simplex : simplex_tree_.filtration_simplex_range()) { + Simplex simplex; + for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { + simplex.insert(simplex.begin(), vertex); + } + filtered_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); + } + return filtered_tree; + + } + + Complex_tree get_skeleton_tree(int dimension) { + Complex_tree skeleton_tree; + for (auto f_simplex : simplex_tree_.skeleton_simplex_range(dimension)) { + Simplex simplex; + for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { + simplex.insert(simplex.begin(), vertex); + } + skeleton_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); + } + return skeleton_tree; + } + + Complex_tree get_star_tree(const Simplex& complex) { + Complex_tree star_tree; + for (auto f_simplex : simplex_tree_.star_simplex_range(simplex_tree_.find(complex))) { + Simplex simplex; + for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { + simplex.insert(simplex.begin(), vertex); + } + star_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); + } + return star_tree; + } + + Complex_tree get_coface_tree(const Simplex& complex, int dimension) { + Complex_tree coface_tree; + for (auto f_simplex : simplex_tree_.cofaces_simplex_range(simplex_tree_.find(complex), dimension)) { + Simplex simplex; + for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { + simplex.insert(simplex.begin(), vertex); + } + coface_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); + } + return coface_tree; + } + + // Specific to Witness complex because no inheritance + Filtration_value filtration() const { + return simplex_tree_.filtration(); + } + + void set_filtration(Filtration_value fil) { + simplex_tree_.set_filtration(fil); + } + + void initialize_filtration() { + simplex_tree_.initialize_filtration(); + } + + size_t num_vertices() const { + return simplex_tree_.num_vertices(); + } + + size_t num_simplices() { + return simplex_tree_.num_simplices(); + } + + int dimension() const { + return simplex_tree_.dimension(); + } + + void set_dimension(int dimension) { + simplex_tree_.set_dimension(dimension); + } + + std::vector<std::pair<int, std::pair<double, double>>> get_persistence(int homology_coeff_field, double min_persistence) { + if (pcoh_ != nullptr) { + delete pcoh_; + } + pcoh_ = new Persistent_cohomology_interface<Simplex_tree<>>(&simplex_tree_); + return pcoh_->get_persistence(homology_coeff_field, min_persistence); + } + + std::vector<int> get_betti_numbers() const { + if (pcoh_ != nullptr) { + return pcoh_->betti_numbers(); + } + std::vector<int> betti_numbers; + return betti_numbers; + } + + std::vector<int> get_persistent_betti_numbers(Filtration_value from, Filtration_value to) const { + if (pcoh_ != nullptr) { + return pcoh_->persistent_betti_numbers(from, to); + } + std::vector<int> persistent_betti_numbers; + return persistent_betti_numbers; + } + + private: + Simplex_tree<> simplex_tree_; + Persistent_cohomology_interface<Simplex_tree<>>* pcoh_; + +}; + +} // namespace witness_complex + +} // namespace Gudhi + +#endif // WITNESS_COMPLEX_INTERFACE_H + diff --git a/src/cython/src/cython/persistence_graphical_tools.py b/src/cython/src/cython/persistence_graphical_tools.py index f25b6b63..247e119e 100755 --- a/src/cython/src/cython/persistence_graphical_tools.py +++ b/src/cython/src/cython/persistence_graphical_tools.py @@ -53,10 +53,13 @@ Only 13 colors for the palette palette = ['#ff0000', '#00ff00', '#0000ff', '#00ffff', '#ff00ff', '#ffff00', '#000000', '#880000', '#008800', '#000088', '#888800', '#880088', '#008888'] - -def show_palette_values(): + +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). + :type alpha: float. :returns: plot -- An horizontal bar plot of dimensions color. """ colors = [] @@ -65,18 +68,20 @@ def show_palette_values(): y_pos = np.arange(len(palette)) - # alpha=0.4 is realy usefull for ugly colors - plt.barh(y_pos, y_pos + 1, align='center', alpha=0.4, color=colors) + plt.barh(y_pos, y_pos + 1, align='center', alpha=alpha, color=colors) plt.ylabel('Dimension') plt.title('Dimension palette values') plt.show() -def bar_code_persistence(persistence): +def barcode_persistence(persistence, alpha=0.6): """This function plots the persistence bar code. :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). + :type alpha: float. :returns: plot -- An horizontal bar plot of persistence. """ (min_birth, max_death) = __min_birth_max_death(persistence) @@ -91,26 +96,28 @@ def bar_code_persistence(persistence): if float(interval[1][1]) != float('inf'): # Finite death case plt.barh(ind, (interval[1][1] - interval[1][0]), height=0.8, - left = interval[1][0], alpha=0.4, + left = interval[1][0], alpha=alpha, color = palette[interval[0]]) else: # Infinite death case for diagram to be nicer plt.barh(ind, (infinity - interval[1][0]), height=0.8, - left = interval[1][0], alpha=0.4, + left = interval[1][0], alpha=alpha, color = palette[interval[0]]) ind = ind + 1 - plt.title('Persistence bar code') - plt.xlabel('Birth - Death') + plt.title('Persistence barcode') # Ends plot on infinity value and starts a little bit before min_birth plt.axis([axis_start, infinity, 0, ind]) plt.show() -def diagram_persistence(persistence): +def diagram_persistence(persistence, alpha=0.6): """This function plots the persistence diagram. :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). + :type alpha: float. :returns: plot -- An diagram plot of persistence. """ (min_birth, max_death) = __min_birth_max_death(persistence) @@ -125,18 +132,18 @@ def diagram_persistence(persistence): x = np.linspace(axis_start, infinity, 1000) # infinity line and text plt.plot(x, x, color='k', linewidth=1.0) - plt.plot(x, [infinity] * len(x), linewidth=1.0, color='k', alpha=0.4) - plt.text(axis_start, infinity, r'$\infty$', color='k', alpha=0.4) + plt.plot(x, [infinity] * len(x), linewidth=1.0, color='k', alpha=alpha) + plt.text(axis_start, infinity, r'$\infty$', color='k', alpha=alpha) # Draw points in loop for interval in reversed(persistence): if float(interval[1][1]) != float('inf'): # Finite death case - plt.scatter(interval[1][0], interval[1][1], alpha=0.4, + plt.scatter(interval[1][0], interval[1][1], alpha=alpha, color = palette[interval[0]]) else: # Infinite death case for diagram to be nicer - plt.scatter(interval[1][0], infinity, alpha=0.4, + plt.scatter(interval[1][0], infinity, alpha=alpha, color = palette[interval[0]]) ind = ind + 1 diff --git a/src/cython/src/cython/witness_complex.pyx b/src/cython/src/cython/witness_complex.pyx new file mode 100644 index 00000000..b9f354d5 --- /dev/null +++ b/src/cython/src/cython/witness_complex.pyx @@ -0,0 +1,309 @@ +from cython cimport numeric +from libcpp.vector cimport vector +from libcpp.utility cimport pair + +"""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" + +cdef extern from "Witness_complex_interface.h" namespace "Gudhi": + cdef cppclass Witness_complex_interface "Gudhi::witness_complex::Witness_complex_interface": + Witness_complex_interface(vector[vector[double]] points, int number_of_landmarks) + double filtration() + double simplex_filtration(vector[int] simplex) + void set_filtration(double filtration) + void initialize_filtration() + int num_vertices() + int num_simplices() + void set_dimension(int dimension) + int dimension() + bint find_simplex(vector[int] simplex) + bint insert_simplex_and_subfaces(vector[int] simplex, + double filtration) + vector[pair[vector[int], double]] get_filtered_tree() + vector[pair[vector[int], double]] get_skeleton_tree(int dimension) + vector[pair[vector[int], double]] get_star_tree(vector[int] simplex) + vector[pair[vector[int], double]] get_coface_tree(vector[int] simplex, + int dimension) + void remove_maximal_simplex(vector[int] simplex) + vector[double] get_point(int vertex) + vector[pair[int, pair[double, double]]] get_persistence(int homology_coeff_field, double min_persistence) + vector[int] get_betti_numbers() + vector[int] get_persistent_betti_numbers(double from_value, double to_value) + +# WitnessComplex python interface +cdef class WitnessComplex: + """WitnessComplex is a simplicial complex constructed from ... + + """ + + cdef Witness_complex_interface * thisptr + + #cdef Witness_complex_persistence_interface * pcohptr + + def __cinit__(self, points=None, number_of_landmarks=5): + """WitnessComplex constructor. + + Args: + points (list): A list of points in d-Dimension. + number_of_landmarks (int): Number of landmarks to build the + WitnessComplex. + """ + if points is not None: + self.thisptr = new Witness_complex_interface(points, + number_of_landmarks) + + def __dealloc__(self): + if self.thisptr != NULL: + del self.thisptr + #if self.pcohptr != NULL: + # del self.pcohptr + + def get_filtration(self): + """This function returns the main simplicial complex filtration value. + + :returns: float -- the simplicial complex filtration value. + """ + return self.thisptr.filtration() + + def filtration(self, simplex): + """This function returns the simplicial complex filtration value for a + given N-simplex. + + :param simplex: The N-simplex, represented by a list of vertex. + :type simplex: list of int. + :returns: float -- the simplicial complex filtration value. + """ + return self.thisptr.simplex_filtration(simplex) + + def set_filtration(self, filtration): + """This function sets the main simplicial complex filtration value. + + :param filtration: The filtration value. + :type filtration: float. + """ + self.thisptr.set_filtration(<double> filtration) + + def initialize_filtration(self): + """This function initializes and sorts the simplicial complex + filtration vector. + + .. note:: + + This function must be launched before persistence, betti_numbers, + persistent_betti_numbers or get_filtered_tree after inserting or + removing simplices. + """ + self.thisptr.initialize_filtration() + + def num_vertices(self): + """This function returns the number of vertices of the simplicial + complex. + + :returns: int -- the simplicial complex number of vertices. + """ + return self.thisptr.num_vertices() + + def num_simplices(self): + """This function returns the number of simplices of the simplicial + complex. + + :returns: int -- the simplicial complex number of simplices. + """ + return self.thisptr.num_simplices() + + def dimension(self): + """This function returns the dimension of the simplicial complex. + + :returns: int -- the simplicial complex dimension. + """ + return self.thisptr.dimension() + + def set_dimension(self, dimension): + """This function sets the dimension of the simplicial complex. + + :param dimension: The new dimension value. + :type dimension: int. + """ + self.thisptr.set_dimension(<int>dimension) + + def find(self, simplex): + """This function returns if the N-simplex was found in the simplicial + complex or not. + + :param simplex: The N-simplex to find, represented by a list of vertex. + :type simplex: list of int. + :returns: bool -- true if the simplex was found, false otherwise. + """ + cdef vector[int] complex + for i in simplex: + complex.push_back(i) + return self.thisptr.find_simplex(complex) + + def insert(self, simplex, filtration=0.0): + """This function inserts the given N-simplex with the given filtration + value (default value is '0.0'). + + :param simplex: The N-simplex to insert, represented by a list of + vertex. + :type simplex: list of int. + :param filtration: The filtration value of the simplex. + :type filtration: float. + :returns: bool -- true if the simplex was found, false otherwise. + """ + cdef vector[int] complex + for i in simplex: + complex.push_back(i) + return self.thisptr.insert_simplex_and_subfaces(complex, + <double>filtration) + + def get_filtered_tree(self): + """This function returns the tree sorted by increasing filtration + values. + + :returns: list of tuples(simplex, filtration) -- the tree sorted by + increasing filtration values. + """ + cdef vector[pair[vector[int], double]] coface_tree \ + = self.thisptr.get_filtered_tree() + ct = [] + for filtered_complex in coface_tree: + v = [] + for vertex in filtered_complex.first: + v.append(vertex) + ct.append((v, filtered_complex.second)) + return ct + + def get_skeleton_tree(self, dimension): + """This function returns the tree skeleton of a maximum given + dimension. + + :param dimension: The skeleton dimension value. + :type dimension: int. + :returns: list of tuples(simplex, filtration) -- the skeleton tree + of a maximum dimension. + """ + cdef vector[pair[vector[int], double]] coface_tree \ + = self.thisptr.get_skeleton_tree(<int>dimension) + ct = [] + for filtered_complex in coface_tree: + v = [] + for vertex in filtered_complex.first: + v.append(vertex) + ct.append((v, filtered_complex.second)) + return ct + + def get_star_tree(self, simplex): + """This function returns the star tree of a given N-simplex. + + :param simplex: The N-simplex, represented by a list of vertex. + :type simplex: list of int. + :returns: list of tuples(simplex, filtration) -- the star tree of a + simplex. + """ + cdef vector[int] complex + for i in simplex: + complex.push_back(i) + cdef vector[pair[vector[int], double]] coface_tree \ + = self.thisptr.get_star_tree(complex) + ct = [] + for filtered_complex in coface_tree: + v = [] + for vertex in filtered_complex.first: + v.append(vertex) + ct.append((v, filtered_complex.second)) + return ct + + def get_coface_tree(self, simplex, codimension): + """This function returns the coface tree of a given N-simplex with a + given codimension. + + :param simplex: The N-simplex, represented by a list of vertex. + :type simplex: list of int. + :param codimension: The codimension. If codimension = 0, all cofaces + are returned (equivalent of get_star_tree function) + :type codimension: int. + :returns: list of tuples(simplex, filtration) -- the coface tree of a + simplex. + """ + cdef vector[int] complex + for i in simplex: + complex.push_back(i) + cdef vector[pair[vector[int], double]] coface_tree \ + = self.thisptr.get_coface_tree(complex, <int>codimension) + ct = [] + for filtered_complex in coface_tree: + v = [] + for vertex in filtered_complex.first: + v.append(vertex) + ct.append((v, filtered_complex.second)) + return ct + + def remove_maximal_simplex(self, simplex): + """This function removes a given maximal N-simplex from the simplicial + complex. + + :param simplex: The N-simplex, represented by a list of vertex. + :type simplex: list of int. + """ + self.thisptr.remove_maximal_simplex(simplex) + + def persistence(self, homology_coeff_field=11, min_persistence=0): + """This function returns the persistence of the simplicial complex. + + :param homology_coeff_field: The homology coefficient field. Must be a + prime number + :type homology_coeff_field: int. + :param min_persistence: The minimum persistence value to take into + account (strictly greater than min_persistence). Default value is 0.0. + Sets min_persistence to -1.0 to see all values. + :type min_persistence: float. + :returns: list of tuples(dimension, tuple(birth, death)) -- the star tree of a + simplex. + """ + return self.thisptr.get_persistence(homology_coeff_field, min_persistence) + + def betti_numbers(self): + """This function returns the Betti numbers of the simplicial complex. + + :returns: list of int -- The Betti numbers ([B0, B1, ..., Bn]). + """ + return self.thisptr.get_betti_numbers() + + def persistent_betti_numbers(self, from_value, to_value): + """This function returns the persistent Betti numbers of the + simplicial complex. + + :param from_value: The persistence birth limit to be added in the + numbers (persistent birth <= from_value). + :type from_value: float. + :param to_value: The persistence death limit to be added in the + numbers (persistent death > to_value). + :type to_value: float. + + :returns: list of int -- The persistent Betti numbers ([B0, B1, ..., + Bn]). + """ + return self.thisptr.get_persistent_betti_numbers(from_value, to_value) |