Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiparameter simplextree #817

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6f3aa21
added a first implementation of multiparameter simplextrees
DavidLapous Feb 15, 2023
8abadb5
Fixes and renaming
DavidLapous Feb 15, 2023
8ab7de0
Doc, cleaning
DavidLapous Feb 15, 2023
8e6ef26
Warning remove: Comment OpenMP parallel pragmas (need to rewrite this…
DavidLapous Feb 15, 2023
9525fe7
Removed unnecessary files, multi_filtration class, insert_batch, cleanup
DavidLapous Feb 17, 2023
3ab6d2c
Better filtration_domination citation
DavidLapous Feb 17, 2023
87821b9
Merge branch 'GUDHI:master' into master
DavidLapous Feb 21, 2023
7ac6fab
Merge branch 'GUDHI:master' into master
DavidLapous Mar 10, 2023
a603ef7
cleaner Filtration_type class
DavidLapous Mar 10, 2023
0b0cd34
Merge branch 'master' of github.com:DavidLapous/gudhi-devel-multi
DavidLapous Mar 10, 2023
a4ea7d0
Merge branch 'GUDHI:master' into master
DavidLapous Mar 21, 2023
a7d1609
fixed make_filtration_non_decreasing, disabled simplex insert filtrat…
DavidLapous Mar 26, 2023
ff0c9b9
Merge branch 'GUDHI:master' into master
DavidLapous Mar 26, 2023
44c89a4
Merge branch 'GUDHI:master' into master
DavidLapous Mar 28, 2023
3129205
merge with upstream
DavidLapous Sep 5, 2023
cb5eb3c
Merge branch 'GUDHI:master' into master
DavidLapous Sep 6, 2023
18054a3
update
DavidLapous Sep 6, 2023
a67628c
simplextree signatures fix
DavidLapous Sep 6, 2023
3b5734b
Merge branch 'GUDHI:master' into master
DavidLapous Sep 8, 2023
44abf0d
namespace multiparameter, added options to tests
DavidLapous Sep 11, 2023
dcfc551
Merge branch 'GUDHI:master' into master
DavidLapous Sep 11, 2023
79a42b4
add multipers option to tests of pcoh
DavidLapous Sep 11, 2023
79c52cd
set filtration to const by default and add a mutable filtration method
DavidLapous Sep 13, 2023
962f6e3
typo
DavidLapous Sep 13, 2023
b73577f
fixed dummy filtration with ref
DavidLapous Sep 13, 2023
5bb12cc
merge upstream
DavidLapous Sep 15, 2023
4f89234
Merge branch 'GUDHI:master' into master
DavidLapous Sep 17, 2023
6267d41
add prune wrt dim
DavidLapous Sep 21, 2023
f4b355a
Merge branch 'master' into master
DavidLapous Sep 21, 2023
32a6a49
Merge branch 'GUDHI:master' into master
DavidLapous Sep 25, 2023
36de642
safe+slow simplextree conversion and optimizations
DavidLapous Sep 25, 2023
82ce7d0
cleaning
DavidLapous Sep 26, 2023
8fd1ccd
Merge branch 'GUDHI:master' into master
DavidLapous Sep 28, 2023
b212c16
Merge branch 'GUDHI:master' into master
DavidLapous Oct 11, 2023
655fd08
Merge branch 'GUDHI:master' into master
DavidLapous Nov 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Simplex_tree/include/gudhi/Simplex_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,17 @@ class Simplex_tree {
/** \brief Upper bound on the dimension of the simplicial complex.*/
int dimension_;
bool dimension_to_be_lowered_ = false;

//MULTIPERS STUFF
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with the option strategy of the simplex tree so far, this (except for the inf_) should be put in a mixin with a dummy like struct Filtration_simplex_base_real and struct Filtration_simplex_base_dummy.

public:
void set_number_of_parameters(unsigned int num){
number_of_parameters_ = num;
}
unsigned int get_number_of_parameters() const{
return number_of_parameters_;
}
private:
unsigned int number_of_parameters_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One extra integer is acceptable, but I wonder if we could make it exist or not depending on the template parameter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find anywhere else to put it. Its not possible on the SimplexTree options (static). I can put it in the python class, but that would imply passing this integer to c++ each time a c++ function is called.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One possibility would be [[no_unique_address]] std::conditional_t<Options::something, int, SomeEmptyType> number_of_parameters_; so that depending on the option, it would not take any space. Or have Simplex_tree derive from Maybe_multi_base<SimplexTreeOptions::plouf> which depending on plouf can be empty or contain an int (and provide 2 methods).
Again, that's not fundamental, I just wanted to mention this possibility.

};

// Print a Simplex_tree in os.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ struct Simplex_tree_node_explicit_storage : SimplexTree::Filtration_simplex_base
typedef typename SimplexTree::Filtration_value Filtration_value;
typedef typename SimplexTree::Simplex_key Simplex_key;

Simplex_tree_node_explicit_storage(Siblings * sib = nullptr,
Filtration_value filtration = 0)
Simplex_tree_node_explicit_storage(Siblings * sib,
Filtration_value filtration) //MULTIPERS : init to 0 not possible
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would Filtration_value filtration = {} work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it will compile with the standard simplextree (Filtration_value is a double)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double d = {}; compiles just fine.

: children_(sib) {
this->assign_filtration(filtration);
}
Simplex_tree_node_explicit_storage() // Empty constructor necessary
: children_(nullptr) {
}

/*
* Assign children to the node
Expand Down
2 changes: 2 additions & 0 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ if(PYTHONINTERP_FOUND)
# Cython modules
set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'off_utils', ")
set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'simplex_tree', ")
set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'simplex_tree_multi', ")
set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'rips_complex', ")
set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'cubical_complex', ")
set(GUDHI_PYTHON_MODULES "${GUDHI_PYTHON_MODULES}'periodic_cubical_complex', ")
Expand Down Expand Up @@ -154,6 +155,7 @@ if(PYTHONINTERP_FOUND)

set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'off_utils', ")
set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'simplex_tree', ")
set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'simplex_tree_multi', ")
set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'rips_complex', ")
set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'cubical_complex', ")
set(GUDHI_CYTHON_MODULES "${GUDHI_CYTHON_MODULES}'periodic_cubical_complex', ")
Expand Down
102 changes: 102 additions & 0 deletions src/python/gudhi/simplex_tree_multi.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
# See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
# Author(s): Vincent Rouvreau
#
# Copyright (C) 2016 Inria
#
# Modification(s):
# - 2022 David Loiseaux, Hannah Schreiber: adapt for multipersistence.
# - YYYY/MM Author: Description of the modification

from cython cimport numeric
from libcpp.vector cimport vector
from libcpp.utility cimport pair
from libcpp cimport bool
from libcpp.string cimport string

__author__ = "Vincent Rouvreau"
__copyright__ = "Copyright (C) 2016 Inria"
__license__ = "MIT"

ctypedef int dimension_type
ctypedef vector[double] point_type
ctypedef double filtration_value_type
ctypedef vector[double] filtration_type
ctypedef vector[int] simplex_type
ctypedef vector[simplex_type] simplex_list
ctypedef vector[pair[pair[int,int], pair[double, double]]] edge_list
ctypedef vector[int] euler_char_list

cdef extern from "Simplex_tree_interface_multi.h" namespace "Gudhi":
cdef cppclass Simplex_tree_options_multidimensional_filtration:
pass

cdef cppclass Simplex_tree_multi_simplex_handle "Gudhi::Simplex_tree_interface<Gudhi::Simplex_tree_options_multidimensional_filtration>::Simplex_handle":
pass

cdef cppclass Simplex_tree_multi_simplices_iterator "Gudhi::Simplex_tree_interface<Gudhi::Simplex_tree_options_multidimensional_filtration>::Complex_simplex_iterator":
Simplex_tree_multi_simplices_iterator() nogil
Simplex_tree_multi_simplex_handle& operator*() nogil
Simplex_tree_multi_simplices_iterator operator++() nogil
bint operator!=(Simplex_tree_multi_simplices_iterator) nogil

cdef cppclass Simplex_tree_multi_skeleton_iterator "Gudhi::Simplex_tree_interface<Gudhi::Simplex_tree_options_multidimensional_filtration>::Skeleton_simplex_iterator":
Simplex_tree_multi_skeleton_iterator() nogil
Simplex_tree_multi_simplex_handle& operator*() nogil
Simplex_tree_multi_skeleton_iterator operator++() nogil
bint operator!=(Simplex_tree_multi_skeleton_iterator) nogil

cdef cppclass Simplex_tree_multi_boundary_iterator "Gudhi::Simplex_tree_interface<Gudhi::Simplex_tree_options_multidimensional_filtration>::Boundary_simplex_iterator":
Simplex_tree_multi_boundary_iterator() nogil
Simplex_tree_multi_simplex_handle& operator*() nogil
Simplex_tree_multi_boundary_iterator operator++() nogil
bint operator!=(Simplex_tree_multi_boundary_iterator) nogil


cdef cppclass Simplex_tree_multi_interface "Gudhi::Simplex_tree_interface<Gudhi::Simplex_tree_options_multidimensional_filtration>":
Simplex_tree_multi_interface() nogil
Simplex_tree_multi_interface(Simplex_tree_multi_interface&) nogil
filtration_type simplex_filtration(vector[int] simplex) nogil
void assign_simplex_filtration(vector[int] simplex, filtration_type filtration) nogil
void initialize_filtration() nogil
int num_vertices() nogil
int num_simplices() nogil
void set_dimension(int dimension) nogil
dimension_type dimension() nogil
dimension_type upper_bound_dimension() nogil
bool find_simplex(vector[int] simplex) nogil
bool insert(vector[int] simplex, filtration_type filtration) nogil
vector[pair[simplex_type, filtration_type]] get_star(vector[int] simplex) nogil
vector[pair[simplex_type, filtration_type]] get_cofaces(vector[int] simplex, int dimension) nogil
void expansion(int max_dim) nogil except +
void remove_maximal_simplex(simplex_type simplex) nogil
bool prune_above_filtration(filtration_type filtration) nogil
# bool make_filtration_non_decreasing() nogil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised how few modifications there are in Simplex_tree.h. Is make_filtration_non_decreasing almost the only function that does not do what you want? Does expansion compute the max of filtration vectors properly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, all function that are not related to either persistence, or relying on filtration comparison, usually work without any issue. I'm not sure the prune_above_filtration works properly. The expansion works for the simplex part, but it calls the make_filtration_non_decreasing afterwards, that is rewritten in the simplex_tree_multi.pyx.
The code for make_filtration_non_decreasing is in python for the moment, so it's super slow.

# void compute_extended_filtration() nogil
Simplex_tree_multi_interface* collapse_edges(int nb_collapse_iteration) nogil except +
void reset_filtration(filtration_type filtration, int dimension) nogil
bint operator==(Simplex_tree_multi_interface) nogil
# Iterators over Simplex tree
pair[simplex_type, filtration_type] get_simplex_and_filtration(Simplex_tree_multi_simplex_handle f_simplex) nogil
Simplex_tree_multi_simplices_iterator get_simplices_iterator_begin() nogil
Simplex_tree_multi_simplices_iterator get_simplices_iterator_end() nogil
vector[Simplex_tree_multi_simplex_handle].const_iterator get_filtration_iterator_begin() nogil
vector[Simplex_tree_multi_simplex_handle].const_iterator get_filtration_iterator_end() nogil
Simplex_tree_multi_skeleton_iterator get_skeleton_iterator_begin(int dimension) nogil
Simplex_tree_multi_skeleton_iterator get_skeleton_iterator_end(int dimension) nogil
pair[Simplex_tree_multi_boundary_iterator, Simplex_tree_multi_boundary_iterator] get_boundary_iterators(vector[int] simplex) nogil except +
# Expansion with blockers
ctypedef bool (*blocker_func_t)(vector[int], void *user_data)
void expansion_with_blockers_callback(int dimension, blocker_func_t user_func, void *user_data)

## MULTIPERS STUFF
void reset_keys() nogil
int get_key(const simplex_type) nogil
void set_key(simplex_type, int) nogil
void fill_lowerstar(vector[double], int) nogil
simplex_list get_simplices_of_dimension(int) nogil
edge_list get_edge_list() nogil
euler_char_list euler_char(vector[filtration_type]) nogil
void resize_all_filtrations(int) nogil
void set_number_of_parameters(int) nogil
int get_number_of_parameters() nogil
Loading