complexes.SimplexTree.SimplexTree
complexes.SimplexTree.SimplexTree(self, simplices=None)
SimplexTree provides lightweight wrapper around a Simplex Tree data structure: an ordered, trie-like structure whose nodes are in bijection with the faces of the complex. This class exposes a native extension module wrapping a simplex tree implemented with modern C++.
The Simplex Tree was originally introduced in the paper > Boissonnat, Jean-Daniel, and Clément Maria. “The simplex tree: An efficient data structure for general simplicial complexes.” Algorithmica 70.3 (2014): 406-427.
Attributes
Name | Type | Description |
---|---|---|
n_simplices | ndarray | number of simplices |
dimension | int | maximal dimension of the complex |
id_policy | str | policy for generating new vertex ids |
Properties:
Name | Type | Description |
---|---|---|
vertices | ndarray | vertices of the complex |
Methods
Name | Description |
---|---|
adjacent | Checks for adjacencies between simplices. |
card | Returns the cardinality of various skeleta of the complex. |
coface_roots | Returns the simplex ‘roots’ of a given simplex whose subtrees generate its cofaces. |
cofaces | Returns the p-cofaces of a given simplex. |
collapse | Performs an elementary collapse on two given simplices. |
degree | Computes the degree of select vertices in the trie. |
expand | Performs a k-expansion of the complex. |
faces | Wrapper for simplices function. |
find | Finds whether simplices exist in Simplex Tree. |
insert | Inserts simplices into the Simplex Tree. |
link | Returns all simplices in the link of a given simplex. |
maximal | Returns the maximal simplices in the complex. |
remove | Removes simplices into the Simplex Tree. |
simplices | Returns the p-simplices in the complex. |
skeleton | Returns the simplices in the p-skeleton of the complex. |
traverse | Traverses the simplex tree in the specified order, calling ‘f’ on each simplex encountered. |
vertex_collapse | Maps a pair of vertices into a single vertex. |
adjacent
complexes.SimplexTree.SimplexTree.adjacent(self, simplices)
Checks for adjacencies between simplices.
card
complexes.SimplexTree.SimplexTree.card(self, p=None)
Returns the cardinality of various skeleta of the complex.
coface_roots
complexes.SimplexTree.SimplexTree.coface_roots(self, sigma=\[\])
Returns the simplex ‘roots’ of a given simplex whose subtrees generate its cofaces.
cofaces
complexes.SimplexTree.SimplexTree.cofaces(self, sigma=\[\])
Returns the p-cofaces of a given simplex.
Parameters
p : requiredcoface dimension to restrict to
sigma : optional (default=[])the simplex to obtain cofaces of
Returns
list : list[SimplexLike],the p-cofaces of sigma
collapse
complexes.SimplexTree.SimplexTree.collapse(self, tau, sigma)
Performs an elementary collapse on two given simplices.
Checks whether its possible to collapse \sigma through \tau, and if so, both simplices are removed. A simplex \sigma is said to be collapsible through one of its faces \tau if \sigma is the only coface of \tau (excluding \tau itself).
Parameters
sigma : requiredmaximal simplex to collapse
tau : requiredface of sigma to collapse
Returns
bool : None,whether the pair was collapsed
Examples
from splex import SimplexTree st = SimplexTree([[0,1,2]]) print(st)
st.collapse([1,2], [0,1,2])
print(st)
degree
complexes.SimplexTree.SimplexTree.degree(self, vertices=None)
Computes the degree of select vertices in the trie.
Parameters
vertices : numpy.typing.ArrayLike, optional (default=None)Retrieves vertex degrees If no vertices are specified, all degrees are computed. Non-existing vertices by default have degree 0.
Returns
list : Union[ArrayLike, int],degree of each vertex id given in ‘vertices’
expand
complexes.SimplexTree.SimplexTree.expand(self, k)
Performs a k-expansion of the complex.
This function is particularly useful for expanding clique complexes beyond their 1-skeleton.
Parameters
k : requiredmaximum dimension to expand to.
Examples
from splex import SimplexTree from itertools import combinations st = SimplexTree(combinations(range(8), 2)) print(st)
st.expand(k=2) print(st)
faces
complexes.SimplexTree.SimplexTree.faces(self, p=None, **kwargs)
Wrapper for simplices function.
find
complexes.SimplexTree.SimplexTree.find(self, simplices)
Finds whether simplices exist in Simplex Tree.
Parameters
simplices : Iterable[SimplexLike], requiredIterable of simplices to insert (each of which are SimplexLike)
Returns
**** :found (ndarray) : boolean array indicating whether each simplex was found in the complex
If the iterable is an 2-dim np.ndarray, then the p-simplex to find is given by each contiguous p+1 stride.
Otherwise, each element of the iterable to casted to a Simplex and then searched for in the tree.
insert
complexes.SimplexTree.SimplexTree.insert(self, simplices)
Inserts simplices into the Simplex Tree.
By definition, inserting a simplex also inserts all of its faces. If the simplex already exists in the complex, the tree is not modified.
Parameters
simplices : Iterable[SimplexConvertible], requiredIterable of simplices to insert (each of which are SimplexLike)
If the iterable is an 2-dim np.ndarray, then a p-simplex is inserted along each contiguous p+1 stride.
Otherwise, each element of the iterable to casted to a Simplex and then inserted into the tree.
link
complexes.SimplexTree.SimplexTree.link(self, sigma=\[\])
Returns all simplices in the link of a given simplex.
maximal
complexes.SimplexTree.SimplexTree.maximal(self)
Returns the maximal simplices in the complex.
remove
complexes.SimplexTree.SimplexTree.remove(self, simplices)
Removes simplices into the Simplex Tree.
By definition, removing a face also removes all of its cofaces. If the simplex does not exist in the complex, the tree is not modified.
Parameters
simplices : Iterable[SimplexLike], requiredIterable of simplices to insert (each of which are SimplexLike).
If the iterable is an 2-dim np.ndarray, then a p-simplex is removed along each contiguous p+1 stride.
Otherwise, each element of the iterable to casted to a Simplex and then removed from the tree.
Examples
st = SimplexTree([range(3)]) print(st) st.remove([[0,1]]) print(st)
simplices
complexes.SimplexTree.SimplexTree.simplices(self, p=None)
Returns the p-simplices in the complex.
skeleton
complexes.SimplexTree.SimplexTree.skeleton(self, p=None, sigma=\[\])
Returns the simplices in the p-skeleton of the complex.
traverse
complexes.SimplexTree.SimplexTree.traverse(self, order='preorder', f=print, sigma=\[\], p=0)
Traverses the simplex tree in the specified order, calling ‘f’ on each simplex encountered.
Supported traversals: - breadth-first / level order (“bfs”, “levelorder”) - depth-first / prefix (“dfs”, “preorder”) - faces (“faces”) - cofaces (“cofaces”) - coface roots - p-skeleton - p-simplices - maximal simplices - link To select one of these options, set order to one of [“bfs”, “levelorder”, “dfs”, “preorder”]
Parameters
order : optional (default=‘preorder’)the type of traversal to do
f : optional (default=print)a function to evaluate on every simplex in the traversal. Defaults to print.
sigma : optional (default=[])simplex to start the traversal at, where applicable. Defaults to the root node (empty set)
p : optional (default=0)dimension of simplices to restrict to, where applicable.
vertex_collapse
complexes.SimplexTree.SimplexTree.vertex_collapse(self, u, v, w)
Maps a pair of vertices into a single vertex.
Parameters
u : int, requiredthe first vertex in the free pair.
v : int, requiredthe second vertex in the free pair.
w : int, requiredthe target vertex to collapse to.