diff options
Diffstat (limited to 'cython/cython')
-rw-r--r-- | cython/cython/alpha_complex.pyx | 4 | ||||
-rw-r--r-- | cython/cython/bottleneck_distance.pyx | 4 | ||||
-rw-r--r-- | cython/cython/cubical_complex.pyx | 29 | ||||
-rw-r--r-- | cython/cython/euclidean_strong_witness_complex.pyx | 4 | ||||
-rw-r--r-- | cython/cython/euclidean_witness_complex.pyx | 4 | ||||
-rw-r--r-- | cython/cython/off_reader.pyx | 5 | ||||
-rw-r--r-- | cython/cython/periodic_cubical_complex.pyx | 29 | ||||
-rwxr-xr-x | cython/cython/persistence_graphical_tools.py | 107 | ||||
-rw-r--r-- | cython/cython/reader_utils.pyx | 4 | ||||
-rw-r--r-- | cython/cython/rips_complex.pyx | 39 | ||||
-rw-r--r-- | cython/cython/simplex_tree.pyx | 45 | ||||
-rw-r--r-- | cython/cython/strong_witness_complex.pyx | 4 | ||||
-rw-r--r-- | cython/cython/subsampling.pyx | 4 | ||||
-rw-r--r-- | cython/cython/tangential_complex.pyx | 19 | ||||
-rw-r--r-- | cython/cython/witness_complex.pyx | 4 |
15 files changed, 168 insertions, 137 deletions
diff --git a/cython/cython/alpha_complex.pyx b/cython/cython/alpha_complex.pyx index a0e8f9b7..4f772e31 100644 --- a/cython/cython/alpha_complex.pyx +++ b/cython/cython/alpha_complex.pyx @@ -11,7 +11,7 @@ import os Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -28,7 +28,7 @@ import os """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Alpha_complex_interface.h" namespace "Gudhi": diff --git a/cython/cython/bottleneck_distance.pyx b/cython/cython/bottleneck_distance.pyx index 9fb377ff..76ef81f4 100644 --- a/cython/cython/bottleneck_distance.pyx +++ b/cython/cython/bottleneck_distance.pyx @@ -9,7 +9,7 @@ import os Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -26,7 +26,7 @@ import os """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Bottleneck_distance_interface.h" namespace "Gudhi::persistence_diagram": diff --git a/cython/cython/cubical_complex.pyx b/cython/cython/cubical_complex.pyx index ffc85130..e94cd539 100644 --- a/cython/cython/cubical_complex.pyx +++ b/cython/cython/cubical_complex.pyx @@ -11,7 +11,7 @@ import os Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -28,7 +28,7 @@ import os """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Cubical_complex_interface.h" namespace "Gudhi": @@ -104,22 +104,21 @@ cdef class CubicalComplex: return self.pcohptr != NULL def num_simplices(self): - """This function returns the number of simplices of the simplicial - complex. + """This function returns the number of all cubes in the complex. - :returns: int -- the simplicial complex number of simplices. + :returns: int -- the number of all cubes in the complex. """ return self.thisptr.num_simplices() def dimension(self): - """This function returns the dimension of the simplicial complex. + """This function returns the dimension of the complex. - :returns: int -- the simplicial complex dimension. + :returns: int -- the complex dimension. """ return self.thisptr.dimension() def persistence(self, homology_coeff_field=11, min_persistence=0): - """This function returns the persistence of the simplicial complex. + """This function returns the persistence of the complex. :param homology_coeff_field: The homology coefficient field. Must be a prime number @@ -130,7 +129,7 @@ cdef class CubicalComplex: Sets min_persistence to -1.0 to see all values. :type min_persistence: float. :returns: list of pairs(dimension, pair(birth, death)) -- the - persistence of the simplicial complex. + persistence of the complex. """ if self.pcohptr != NULL: del self.pcohptr @@ -142,12 +141,15 @@ cdef class CubicalComplex: return persistence_result def betti_numbers(self): - """This function returns the Betti numbers of the simplicial complex. + """This function returns the Betti numbers of the complex. :returns: list of int -- The Betti numbers ([B0, B1, ..., Bn]). :note: betti_numbers function requires persistence function to be launched first. + + :note: betti_numbers function always returns [1, 0, 0, ...] as infinity + filtration cubes are not removed from the complex. """ cdef vector[int] bn_result if self.pcohptr != NULL: @@ -155,8 +157,7 @@ cdef class CubicalComplex: return bn_result def persistent_betti_numbers(self, from_value, to_value): - """This function returns the persistent Betti numbers of the - simplicial complex. + """This function returns the persistent Betti numbers of the complex. :param from_value: The persistence birth limit to be added in the numbers (persistent birth <= from_value). @@ -177,8 +178,8 @@ cdef class CubicalComplex: return pbn_result def persistence_intervals_in_dimension(self, dimension): - """This function returns the persistence intervals of the simplicial - complex in a specific dimension. + """This function returns the persistence intervals of the complex in a + specific dimension. :param dimension: The specific dimension. :type from_value: int. diff --git a/cython/cython/euclidean_strong_witness_complex.pyx b/cython/cython/euclidean_strong_witness_complex.pyx index c1523892..62b7cf71 100644 --- a/cython/cython/euclidean_strong_witness_complex.pyx +++ b/cython/cython/euclidean_strong_witness_complex.pyx @@ -8,7 +8,7 @@ from libcpp.utility cimport pair Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -25,7 +25,7 @@ from libcpp.utility cimport pair """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Euclidean_strong_witness_complex_interface.h" namespace "Gudhi": diff --git a/cython/cython/euclidean_witness_complex.pyx b/cython/cython/euclidean_witness_complex.pyx index 7c443b6b..c10ca73d 100644 --- a/cython/cython/euclidean_witness_complex.pyx +++ b/cython/cython/euclidean_witness_complex.pyx @@ -8,7 +8,7 @@ from libcpp.utility cimport pair Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -25,7 +25,7 @@ from libcpp.utility cimport pair """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Euclidean_witness_complex_interface.h" namespace "Gudhi": diff --git a/cython/cython/off_reader.pyx b/cython/cython/off_reader.pyx index b6e107ef..b939013f 100644 --- a/cython/cython/off_reader.pyx +++ b/cython/cython/off_reader.pyx @@ -9,7 +9,7 @@ import os Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -26,7 +26,7 @@ import os """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Off_reader_interface.h" namespace "Gudhi": @@ -46,4 +46,5 @@ def read_off(off_file=''): return read_points_from_OFF_file(str.encode(off_file)) else: print("file " + off_file + " not found.") + return [] diff --git a/cython/cython/periodic_cubical_complex.pyx b/cython/cython/periodic_cubical_complex.pyx index 3025f125..e626950b 100644 --- a/cython/cython/periodic_cubical_complex.pyx +++ b/cython/cython/periodic_cubical_complex.pyx @@ -11,7 +11,7 @@ import os Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -28,7 +28,7 @@ import os """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Cubical_complex_interface.h" namespace "Gudhi": @@ -106,22 +106,21 @@ cdef class PeriodicCubicalComplex: return self.pcohptr != NULL def num_simplices(self): - """This function returns the number of simplices of the simplicial - complex. + """This function returns the number of all cubes in the complex. - :returns: int -- the simplicial complex number of simplices. + :returns: int -- the number of all cubes in the complex. """ return self.thisptr.num_simplices() def dimension(self): - """This function returns the dimension of the simplicial complex. + """This function returns the dimension of the complex. - :returns: int -- the simplicial complex dimension. + :returns: int -- the complex dimension. """ return self.thisptr.dimension() def persistence(self, homology_coeff_field=11, min_persistence=0): - """This function returns the persistence of the simplicial complex. + """This function returns the persistence of the complex. :param homology_coeff_field: The homology coefficient field. Must be a prime number @@ -132,7 +131,7 @@ cdef class PeriodicCubicalComplex: Sets min_persistence to -1.0 to see all values. :type min_persistence: float. :returns: list of pairs(dimension, pair(birth, death)) -- the - persistence of the simplicial complex. + persistence of the complex. """ if self.pcohptr != NULL: del self.pcohptr @@ -144,12 +143,15 @@ cdef class PeriodicCubicalComplex: return persistence_result def betti_numbers(self): - """This function returns the Betti numbers of the simplicial complex. + """This function returns the Betti numbers of the complex. :returns: list of int -- The Betti numbers ([B0, B1, ..., Bn]). :note: betti_numbers function requires persistence function to be launched first. + + :note: betti_numbers function always returns [1, 0, 0, ...] as infinity + filtration cubes are not removed from the complex. """ cdef vector[int] bn_result if self.pcohptr != NULL: @@ -157,8 +159,7 @@ cdef class PeriodicCubicalComplex: return bn_result def persistent_betti_numbers(self, from_value, to_value): - """This function returns the persistent Betti numbers of the - simplicial complex. + """This function returns the persistent Betti numbers of the complex. :param from_value: The persistence birth limit to be added in the numbers (persistent birth <= from_value). @@ -179,8 +180,8 @@ cdef class PeriodicCubicalComplex: return pbn_result def persistence_intervals_in_dimension(self, dimension): - """This function returns the persistence intervals of the simplicial - complex in a specific dimension. + """This function returns the persistence intervals of the complex in a + specific dimension. :param dimension: The specific dimension. :type from_value: int. diff --git a/cython/cython/persistence_graphical_tools.py b/cython/cython/persistence_graphical_tools.py index fb837e29..216ab8d6 100755 --- a/cython/cython/persistence_graphical_tools.py +++ b/cython/cython/persistence_graphical_tools.py @@ -1,4 +1,5 @@ import matplotlib.pyplot as plt +import matplotlib.patches as mpatches import numpy as np import os @@ -8,7 +9,7 @@ import os Author(s): Vincent Rouvreau, Bertrand Michel - Copyright (C) 2016 INRIA + 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 @@ -25,16 +26,16 @@ import os """ __author__ = "Vincent Rouvreau, Bertrand Michel" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" -def __min_birth_max_death(persistence, band_boot=0.): +def __min_birth_max_death(persistence, band=0.): """This function returns (min_birth, max_death) from the persistence. :param persistence: The persistence to plot. :type persistence: list of tuples(dimension, tuple(birth, death)). - :param band_boot: bootstrap band - :type band_boot: float. + :param band: band + :type band: float. :returns: (float, float) -- (min_birth, max_death). """ # Look for minimum birth date and maximum death date for plot optimisation @@ -48,8 +49,8 @@ def __min_birth_max_death(persistence, band_boot=0.): max_death = float(interval[1][0]) if float(interval[1][0]) < min_birth: min_birth = float(interval[1][0]) - if band_boot > 0.: - max_death += band_boot + if band > 0.: + max_death += band return (min_birth, max_death) """ @@ -59,37 +60,27 @@ palette = ['#ff0000', '#00ff00', '#0000ff', '#00ffff', '#ff00ff', '#ffff00', '#000000', '#880000', '#008800', '#000088', '#888800', '#880088', '#008888'] -def show_palette_values(alpha=0.6): - """This function shows palette color values in function of the dimension. +def plot_persistence_barcode(persistence=[], persistence_file='', alpha=0.6, + max_barcodes=1000, inf_delta=0.1, legend=False): + """This function plots the persistence bar code from persistence values list + or from a :doc:`persistence file <fileformats>`. - :param alpha: alpha value in [0.0, 1.0] for horizontal bars (default is 0.6). - :type alpha: float. - :returns: plot the dimension palette values. - """ - colors = [] - for color in palette: - colors.append(color) - - y_pos = np.arange(len(palette)) - - plt.barh(y_pos, y_pos + 1, align='center', alpha=alpha, color=colors) - plt.ylabel('Dimension') - plt.title('Dimension palette values') - return plt - -def plot_persistence_barcode(persistence=[], persistence_file='', alpha=0.6, max_barcodes=0): - """This function plots the persistence bar code. - - :param persistence: The persistence to plot. + :param persistence: Persistence values list. :type persistence: list of tuples(dimension, tuple(birth, death)). - :param persistence_file: A persistence file style name (reset persistence if both are set). + :param persistence_file: A :doc:`persistence file <fileformats>` style name + (reset persistence if both are set). :type persistence_file: string - :param alpha: alpha value in [0.0, 1.0] for horizontal bars (default is 0.6). + :param alpha: barcode transparency value (0.0 transparent through 1.0 opaque - default is 0.6). :type alpha: float. - :param max_barcodes: number of maximal barcodes to be displayed + :param max_barcodes: number of maximal barcodes to be displayed. + Set it to 0 to see all, Default value is 1000. (persistence will be sorted by life time if max_barcodes is set) :type max_barcodes: int. - :returns: plot -- An horizontal bar plot of persistence. + :param inf_delta: Infinity is placed at ((max_death - min_birth) x inf_delta). + A reasonable value is between 0.05 and 0.5 - default is 0.1. + :type inf_delta: float. + :returns: A matplotlib object containing horizontal bar plot of persistence + (launch `show()` method on it to display it). """ if persistence_file is not '': if os.path.isfile(persistence_file): @@ -107,9 +98,11 @@ def plot_persistence_barcode(persistence=[], persistence_file='', alpha=0.6, max # Sort by life time, then takes only the max_plots elements persistence = sorted(persistence, key=lambda life_time: life_time[1][1]-life_time[1][0], reverse=True)[:max_barcodes] + persistence = sorted(persistence, key=lambda birth: birth[1][0]) + (min_birth, max_death) = __min_birth_max_death(persistence) ind = 0 - delta = ((max_death - min_birth) / 10.0) + delta = ((max_death - min_birth) * inf_delta) # Replace infinity values with max_death + delta for bar code to be more # readable infinity = max_death + delta @@ -120,33 +113,49 @@ def plot_persistence_barcode(persistence=[], persistence_file='', alpha=0.6, max # Finite death case plt.barh(ind, (interval[1][1] - interval[1][0]), height=0.8, left = interval[1][0], alpha=alpha, - color = palette[interval[0]]) + color = palette[interval[0]], + linewidth=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=alpha, - color = palette[interval[0]]) + color = palette[interval[0]], + linewidth=0) ind = ind + 1 + if legend: + dimensions = list(set(item[0] for item in persistence)) + plt.legend(handles=[mpatches.Patch(color=palette[dim], + label=str(dim)) for dim in dimensions], + loc='lower right') plt.title('Persistence barcode') # Ends plot on infinity value and starts a little bit before min_birth plt.axis([axis_start, infinity, 0, ind]) return plt -def plot_persistence_diagram(persistence=[], persistence_file='', alpha=0.6, band_boot=0., max_plots=0): - """This function plots the persistence diagram with an optional confidence band. +def plot_persistence_diagram(persistence=[], persistence_file='', alpha=0.6, + band=0., max_plots=1000, inf_delta=0.1, legend=False): + """This function plots the persistence diagram from persistence values list + or from a :doc:`persistence file <fileformats>`. - :param persistence: The persistence to plot. + :param persistence: Persistence values list. :type persistence: list of tuples(dimension, tuple(birth, death)). - :param persistence_file: A persistence file style name (reset persistence if both are set). + :param persistence_file: A :doc:`persistence file <fileformats>` style name + (reset persistence if both are set). :type persistence_file: string - :param alpha: alpha value in [0.0, 1.0] for points and horizontal infinity line (default is 0.6). + :param alpha: plot transparency value (0.0 transparent through 1.0 opaque - default is 0.6). :type alpha: float. - :param band_boot: bootstrap band (not displayed if :math:`\leq` 0.) - :type band_boot: float. + :param band: band (not displayed if :math:`\leq` 0. - default is 0.) + :type band: float. :param max_plots: number of maximal plots to be displayed + Set it to 0 to see all, Default value is 1000. + (persistence will be sorted by life time if max_plots is set) :type max_plots: int. - :returns: plot -- A diagram plot of persistence. + :param inf_delta: Infinity is placed at ((max_death - min_birth) x inf_delta). + A reasonable value is between 0.05 and 0.5 - default is 0.1. + :type inf_delta: float. + :returns: A matplotlib object containing diagram plot of persistence + (launch `show()` method on it to display it). """ if persistence_file is not '': if os.path.isfile(persistence_file): @@ -164,9 +173,9 @@ def plot_persistence_diagram(persistence=[], persistence_file='', alpha=0.6, ban # Sort by life time, then takes only the max_plots elements persistence = sorted(persistence, key=lambda life_time: life_time[1][1]-life_time[1][0], reverse=True)[:max_plots] - (min_birth, max_death) = __min_birth_max_death(persistence, band_boot) + (min_birth, max_death) = __min_birth_max_death(persistence, band) ind = 0 - delta = ((max_death - min_birth) / 10.0) + delta = ((max_death - min_birth) * inf_delta) # Replace infinity values with max_death + delta for diagram to be more # readable infinity = max_death + delta @@ -179,8 +188,8 @@ def plot_persistence_diagram(persistence=[], persistence_file='', alpha=0.6, ban plt.plot(x, [infinity] * len(x), linewidth=1.0, color='k', alpha=alpha) plt.text(axis_start, infinity, r'$\infty$', color='k', alpha=alpha) # bootstrap band - if band_boot > 0.: - plt.fill_between(x, x, x+band_boot, alpha=alpha, facecolor='red') + if band > 0.: + plt.fill_between(x, x, x+band, alpha=alpha, facecolor='red') # Draw points in loop for interval in reversed(persistence): @@ -194,6 +203,10 @@ def plot_persistence_diagram(persistence=[], persistence_file='', alpha=0.6, ban color = palette[interval[0]]) ind = ind + 1 + if legend: + dimensions = list(set(item[0] for item in persistence)) + plt.legend(handles=[mpatches.Patch(color=palette[dim], label=str(dim)) for dim in dimensions]) + plt.title('Persistence diagram') plt.xlabel('Birth') plt.ylabel('Death') diff --git a/cython/cython/reader_utils.pyx b/cython/cython/reader_utils.pyx index 3a17c5a0..e4572db0 100644 --- a/cython/cython/reader_utils.pyx +++ b/cython/cython/reader_utils.pyx @@ -11,7 +11,7 @@ import os Author(s): Vincent Rouvreau - Copyright (C) 2017 INRIA + Copyright (C) 2017 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 @@ -28,7 +28,7 @@ import os """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2017 INRIA" +__copyright__ = "Copyright (C) 2017 Inria" __license__ = "GPL v3" cdef extern from "Reader_utils_interface.h" namespace "Gudhi": diff --git a/cython/cython/rips_complex.pyx b/cython/cython/rips_complex.pyx index ad9b0a4d..59c16bff 100644 --- a/cython/cython/rips_complex.pyx +++ b/cython/cython/rips_complex.pyx @@ -11,7 +11,7 @@ import os Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -28,14 +28,12 @@ import os """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Rips_complex_interface.h" namespace "Gudhi": cdef cppclass Rips_complex_interface "Gudhi::rips_complex::Rips_complex_interface": Rips_complex_interface(vector[vector[double]] values, double threshold, bool euclidean) - # bool from_file is a workaround for cython to find the correct signature - Rips_complex_interface(string file_name, double threshold, bool euclidean, bool from_file) void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, int dim_max) # RipsComplex python interface @@ -49,7 +47,7 @@ cdef class RipsComplex: cdef Rips_complex_interface * thisptr # Fake constructor that does nothing but documenting the constructor - def __init__(self, points=None, off_file='', distance_matrix=None, csv_file='', max_edge_length=float('inf')): + def __init__(self, points=None, distance_matrix=None, max_edge_length=float('inf')): """RipsComplex constructor. :param max_edge_length: Rips value. @@ -60,41 +58,14 @@ cdef class RipsComplex: Or - :param off_file: An OFF file style name. - :type off_file: string - - Or - :param distance_matrix: A distance matrix (full square or lower triangular). :type points: list of list of double - - Or - - :param csv_file: A csv file style name containing a full square or a - lower triangular distance matrix. - :type csv_file: string """ # The real cython constructor - def __cinit__(self, points=None, off_file='', distance_matrix=None, csv_file='', max_edge_length=float('inf')): - if off_file is not '': - if os.path.isfile(off_file): - self.thisptr = new Rips_complex_interface(str.encode(off_file), - max_edge_length, - True, - True) - else: - print("file " + off_file + " not found.") - elif csv_file is not '': - if os.path.isfile(csv_file): - self.thisptr = new Rips_complex_interface(str.encode(csv_file), - max_edge_length, - False, - True) - else: - print("file " + csv_file + " not found.") - elif distance_matrix is not None: + def __cinit__(self, points=None, distance_matrix=None, max_edge_length=float('inf')): + if distance_matrix is not None: self.thisptr = new Rips_complex_interface(distance_matrix, max_edge_length, False) else: if points is None: diff --git a/cython/cython/simplex_tree.pyx b/cython/cython/simplex_tree.pyx index 0cb575d2..e302486b 100644 --- a/cython/cython/simplex_tree.pyx +++ b/cython/cython/simplex_tree.pyx @@ -10,7 +10,7 @@ from libcpp.string cimport string Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -27,7 +27,7 @@ from libcpp.string cimport string """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": @@ -55,6 +55,7 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": void expansion(int max_dim) void remove_maximal_simplex(vector[int] simplex) bool prune_above_filtration(double filtration) + bool make_filtration_non_decreasing() 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>>": @@ -64,6 +65,7 @@ cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi": vector[int] persistent_betti_numbers(double from_value, double to_value) 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() # SimplexTree python interface cdef class SimplexTree: @@ -399,6 +401,26 @@ cdef class SimplexTree: """ self.thisptr.expansion(max_dim) + def make_filtration_non_decreasing(self): + """This function ensures that each simplex has a higher filtration + value than its faces by increasing the filtration values. + + :returns: The filtration modification information. + :rtype: bint + + + .. note:: + + Some simplex tree functions require the filtration to be valid. + make_filtration_non_decreasing function is not launching + :func:`initialize_filtration()<gudhi.SimplexTree.initialize_filtration>` + but returns the filtration modification + information. If the complex has changed , please call + :func:`initialize_filtration()<gudhi.SimplexTree.initialize_filtration>` + to recompute it. + """ + return self.thisptr.make_filtration_non_decreasing() + def persistence(self, homology_coeff_field=11, min_persistence=0, persistence_dim_max = False): """This function returns the persistence of the simplicial complex. @@ -486,6 +508,25 @@ cdef class SimplexTree: " to be launched first.") return intervals_result + def persistence_pairs(self): + """This function returns the persistence pairs of the simplicial + complex. + + :returns: The persistence intervals. + :rtype: list of pair of list of int + + :note: intervals_in_dim function requires + :func:`persistence()<gudhi.SimplexTree.persistence>` + function to be launched first. + """ + cdef vector[pair[vector[int],vector[int]]] persistence_pairs_result + if self.pcohptr != NULL: + persistence_pairs_result = self.pcohptr.persistence_pairs() + else: + print("persistence_pairs function requires persistence function" + " to be launched first.") + return persistence_pairs_result + def write_persistence_diagram(self, persistence_file=''): """This function writes the persistence intervals of the simplicial complex in a user given file name. diff --git a/cython/cython/strong_witness_complex.pyx b/cython/cython/strong_witness_complex.pyx index 770b46f5..74c5cb05 100644 --- a/cython/cython/strong_witness_complex.pyx +++ b/cython/cython/strong_witness_complex.pyx @@ -8,7 +8,7 @@ from libcpp.utility cimport pair Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -25,7 +25,7 @@ from libcpp.utility cimport pair """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Strong_witness_complex_interface.h" namespace "Gudhi": diff --git a/cython/cython/subsampling.pyx b/cython/cython/subsampling.pyx index 894a4fbe..ac09b7a3 100644 --- a/cython/cython/subsampling.pyx +++ b/cython/cython/subsampling.pyx @@ -10,7 +10,7 @@ import os Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -27,7 +27,7 @@ import os """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Subsampling_interface.h" namespace "Gudhi::subsampling": diff --git a/cython/cython/tangential_complex.pyx b/cython/cython/tangential_complex.pyx index d55bb050..4bb07076 100644 --- a/cython/cython/tangential_complex.pyx +++ b/cython/cython/tangential_complex.pyx @@ -11,7 +11,7 @@ import os Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -28,14 +28,14 @@ import os """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Tangential_complex_interface.h" namespace "Gudhi": cdef cppclass Tangential_complex_interface "Gudhi::tangential_complex::Tangential_complex_interface": - Tangential_complex_interface(vector[vector[double]] points) + Tangential_complex_interface(int intrisic_dim, vector[vector[double]] points) # bool from_file is a workaround for cython to find the correct signature - Tangential_complex_interface(string off_file, bool from_file) + Tangential_complex_interface(int intrisic_dim, string off_file, bool from_file) vector[double] get_point(unsigned vertex) unsigned number_of_vertices() unsigned number_of_simplices() @@ -54,9 +54,12 @@ cdef class TangentialComplex: cdef Tangential_complex_interface * thisptr # Fake constructor that does nothing but documenting the constructor - def __init__(self, points=None, off_file=''): + def __init__(self, intrisic_dim, points=None, off_file=''): """TangentialComplex constructor. + :param intrisic_dim: Intrinsic dimension of the manifold. + :type intrisic_dim: integer + :param points: A list of points in d-Dimension. :type points: list of list of double @@ -67,17 +70,17 @@ cdef class TangentialComplex: """ # The real cython constructor - def __cinit__(self, points=None, off_file=''): + def __cinit__(self, intrisic_dim, points=None, off_file=''): if off_file is not '': if os.path.isfile(off_file): - self.thisptr = new Tangential_complex_interface(str.encode(off_file), True) + self.thisptr = new Tangential_complex_interface(intrisic_dim, str.encode(off_file), True) else: print("file " + off_file + " not found.") else: if points is None: # Empty tangential construction points=[] - self.thisptr = new Tangential_complex_interface(points) + self.thisptr = new Tangential_complex_interface(intrisic_dim, points) def __dealloc__(self): diff --git a/cython/cython/witness_complex.pyx b/cython/cython/witness_complex.pyx index 96d122bb..8591465a 100644 --- a/cython/cython/witness_complex.pyx +++ b/cython/cython/witness_complex.pyx @@ -8,7 +8,7 @@ from libcpp.utility cimport pair Author(s): Vincent Rouvreau - Copyright (C) 2016 INRIA + 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 @@ -25,7 +25,7 @@ from libcpp.utility cimport pair """ __author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" +__copyright__ = "Copyright (C) 2016 Inria" __license__ = "GPL v3" cdef extern from "Witness_complex_interface.h" namespace "Gudhi": |