toponetx.CombinatorialComplex#
- class toponetx.CombinatorialComplex(cells: Collection | None = None, ranks: Collection | None = None, graph_based: bool = False, **kwargs)[source]#
Bases:
ColoredHyperGraph
Class for Combinatorial Complex.
A Combinatorial Complex (CCC) is a triple $CCC = (S, X, rk)$ where: - $S$ is an abstract set of entities, - $X$ a subset of the power set of $S$, and - $rk$ is the a rank function that associates for every set x in X a rank, a positive integer.
The rank function $rk$ must satisfy $x subseteq y$ then $rk(x) leq rk(y)$. We call this condition the CCC condition.
A CCC is a generalization of graphs, hypergraphs, cellular and simplicial complexes.
Mathematical Example:
Let $S = {1, 2, 3, 4}$ be a set of abstract entities. Let $X = {{1, 2}, {1, 2, 3}, {1, 3}, {1, 4}}$ be a subset of the power set of $S$. Let rk be the ranking function that assigns the length of a set as its rank, i.e. $rk({1, 2}) = 2$, $rk({1, 2, 3}) = 3$, etc.
Then, $(S, X, rk)$ is a combinatorial complex.
- Parameters:
- cellsCollection, optional
A collection of cells to add to the combinatorial complex.
- ranksCollection, optional
When cells is an iterable or dictionary, ranks cannot be None and it must be iterable/dict of the same size as cells.
- graph_basedbool, default=False
When true rank 1 edges must have cardinality equals to 1.
- **kwargskeyword arguments, optional
Attributes to add to the complex as key=value pairs.
- Attributes:
- complexdict
A dictionary that can be used to store additional information about the complex.
Methods
add_cell
(cell[, rank])Add a single cells to combinatorial complex.
add_cells_from
(cells[, ranks])Add cells to combinatorial complex.
add_node
(node, **attr)Add a node to a CCC.
adjacency_matrix
(rank, via_rank[, s, index])Sparse weighted s-adjacency matrix.
all_cell_to_node_coadjacency_matrix
([index, s])Compute the cell co-adjacency matrix.
all_ranks_incidence_matrix
(rank[, weight, ...])Compute the incidence matrix for the Colored Hypergraph indexed by cells of rank n and all other cells.
clone
()Return a copy of the simplex.
coadjacency_matrix
(rank, via_rank[, s, index])Compute the coadjacency matrix of self.
degree
(node[, rank, s])Compute the number of cells of certain rank (or all ranks) that contain node.
degree_matrix
(rank[, index])Compute the node-degree matrix.
dirac_operator_matrix
([weight, index])Compute dirac operator matrix of self.
Construct a Colored Hypergraph from a networkx graph.
from_trimesh
(mesh)Import from a trimesh.
Get the adjacency structure dictionary for cells of rank i and j.
get_cell_attributes
(name[, rank])Get node attributes from graph.
Get the incidence structure dictionary for cells of rank i and j.
get_node_attributes
(name)Get node attributes.
incidence_matrix
(rank[, to_rank, ...])Compute incidence matrix for the CCC between rank and to_rank skeleti.
laplacian_matrix
(rank[, sparse, index])Compute Laplacian matrix.
new_hyperedge_key
(hyperedge, rank)Add a new key for the given hyperedge.
node_to_all_cell_adjacnecy_matrix
([index, s])Compute the node/all cell adjacency matrix.
node_to_all_cell_incidence_matrix
([weight, ...])Nodes/all cells incidence matrix for the indexed by nodes X cells.
number_of_cells
([cell_set])Compute the number of cells in cell_set belonging to the CCC.
number_of_nodes
([node_set])Compute the number of nodes in node_set belonging to the CCC.
order
()Compute the number of nodes in the CCC.
remove_cell
(cell)Remove a single cell from CCC.
remove_cells
(cell_set)Remove cells from CCC.
remove_node
(node)Remove node from cells.
remove_nodes
(node_set)Remove nodes from cells.
Construct new CCC with singleton cells removed.
restrict_to_cells
(cell_set)Construct a Colored Hypergraph using a subset of the cells.
restrict_to_nodes
(node_set)Restrict to a set of nodes.
set_cell_attributes
(values[, name])Set cell attributes.
set_node_attributes
(values[, name])Set node attributes.
Return a list of singleton cell.
size
(cell)Compute the number of nodes in the colored hypergraph that belong to a specific cell.
skeleton
(rank[, level])Skeleton of the CCC.
- Raises:
- TypeError
If cells is not given as an Iterable.
- ValueError
If input cells is not an instance of HyperEdge when rank is None. If input HyperEdge has None rank when rank is specified. If cells and ranks do not have an equal number of elements.
Examples
Define an empty combinatorial complex:
>>> CCC = tnx.CombinatorialComplex()
Add cells to the combinatorial complex:
>>> CCC = tnx.CombinatorialComplex() >>> CCC.add_cell([1, 2], rank=1) >>> CCC.add_cell([3, 4], rank=1) >>> CCC.add_cell([1, 2, 3, 4], rank=2) >>> CCC.add_cell([1, 2, 4], rank=2) >>> CCC.add_cell([1, 2, 3, 4, 5, 6, 7], rank=3)
- __init__(cells: Collection | None = None, ranks: Collection | None = None, graph_based: bool = False, **kwargs) None [source]#
Initialize a new instance of the Complex class.
- Parameters:
- **kwargskeyword arguments, optional
Attributes to add to the complex as key=value pairs.
Methods
__init__
([cells, ranks, graph_based])Initialize a new instance of the Complex class.
add_cell
(cell[, rank])Add a single cells to combinatorial complex.
add_cells_from
(cells[, ranks])Add cells to combinatorial complex.
add_node
(node, **attr)Add a node to a CCC.
adjacency_matrix
(rank, via_rank[, s, index])Sparse weighted s-adjacency matrix.
all_cell_to_node_coadjacency_matrix
([index, s])Compute the cell co-adjacency matrix.
all_ranks_incidence_matrix
(rank[, weight, ...])Compute the incidence matrix for the Colored Hypergraph indexed by cells of rank n and all other cells.
clone
()Return a copy of the simplex.
coadjacency_matrix
(rank, via_rank[, s, index])Compute the coadjacency matrix of self.
degree
(node[, rank, s])Compute the number of cells of certain rank (or all ranks) that contain node.
degree_matrix
(rank[, index])Compute the node-degree matrix.
dirac_operator_matrix
([weight, index])Compute dirac operator matrix of self.
Construct a Colored Hypergraph from a networkx graph.
from_trimesh
(mesh)Import from a trimesh.
Get the adjacency structure dictionary for cells of rank i and j.
get_cell_attributes
(name[, rank])Get node attributes from graph.
Get the incidence structure dictionary for cells of rank i and j.
get_node_attributes
(name)Get node attributes.
incidence_matrix
(rank[, to_rank, ...])Compute incidence matrix for the CCC between rank and to_rank skeleti.
laplacian_matrix
(rank[, sparse, index])Compute Laplacian matrix.
new_hyperedge_key
(hyperedge, rank)Add a new key for the given hyperedge.
node_to_all_cell_adjacnecy_matrix
([index, s])Compute the node/all cell adjacency matrix.
node_to_all_cell_incidence_matrix
([weight, ...])Nodes/all cells incidence matrix for the indexed by nodes X cells.
number_of_cells
([cell_set])Compute the number of cells in cell_set belonging to the CCC.
number_of_nodes
([node_set])Compute the number of nodes in node_set belonging to the CCC.
order
()Compute the number of nodes in the CCC.
remove_cell
(cell)Remove a single cell from CCC.
remove_cells
(cell_set)Remove cells from CCC.
remove_node
(node)Remove node from cells.
remove_nodes
(node_set)Remove nodes from cells.
Construct new CCC with singleton cells removed.
restrict_to_cells
(cell_set)Construct a Colored Hypergraph using a subset of the cells.
restrict_to_nodes
(node_set)Restrict to a set of nodes.
set_cell_attributes
(values[, name])Set cell attributes.
set_node_attributes
(values[, name])Set node attributes.
Return a list of singleton cell.
size
(cell)Compute the number of nodes in the colored hypergraph that belong to a specific cell.
skeleton
(rank[, level])Skeleton of the CCC.
Attributes
Object associated with self._cells.
Return the dimension of the colored hypergraph.
Return dict keyed by cell uids with values the uids of nodes in each cell.
Object associated with self.elements.
Return the sorted list of ranks in the colored hypergraph.
Return shape.
complex
- add_cell(cell, rank=None, **attr) None [source]#
Add a single cells to combinatorial complex.
- Parameters:
- cellhashable, iterable or HyperEdge
If hashable the cell returned will be empty.
- rankint
Rank of the cell.
- **attrkeyword arguments, optional
Attributes to add to the cell as key=value pairs.
- add_cells_from(cells, ranks: Iterable[int] | int | None = None) None [source]#
Add cells to combinatorial complex.
- Parameters:
- cellsiterable of hashables
For hashables the cells returned will be empty.
- ranksiterable or int, optional
When iterable, len(ranks) == len(cells).
- add_node(node, **attr) None [source]#
Add a node to a CCC.
- Parameters:
- nodeHashable
The node to add to this combinatorial complex.
- **attrkeyword arguments, optional
Attributes to add to the node as key=value pairs.
- adjacency_matrix(rank, via_rank, s: int = 1, index: bool = False)[source]#
Sparse weighted s-adjacency matrix.
- Parameters:
- rank, via_rankint
Two ranks for skeletons in the input combinatorial complex.
- sint, default=1
Minimum number of edges shared by neighbors with node.
- indexbool, default=False
Whether to return the indices of the rows and columns of the adjacency matrix.
- Returns:
- indiceslist
List identifying the rows and columns of the adjacency matrix with the cells of the combinatorial complex. Only returned if index is True.
- adjacency_matrixscipy.sparse.csr.csr_matrix
The adjacency matrix of this combinatorial complex.
Examples
>>> CCC = tnx.CombinatorialComplex() >>> CCC.add_cell([1, 2], rank=1) >>> CCC.add_cell([3, 4], rank=1) >>> CCC.add_cell([1, 2, 3, 4], rank=2) >>> CCC.add_cell([1, 2, 4], rank=2) >>> CCC.add_cell([1, 2, 3, 4, 5, 6, 7], rank=3) >>> CCC.adjacency_matrix(0, 1)
- all_cell_to_node_coadjacency_matrix(index: bool = False, s: int = 1)#
Compute the cell co-adjacency matrix.
- Parameters:
- indexbool, optional, default=False
If True, return a row dictionary of row to node uid.
- sint, default=1
Minimum number of edges shared by neighbors with a node.
- Returns:
- row dictionarydict
Dictionary identifying rows with nodes. If False, this does not exist.
- all cells co-adjacency matrixscipy.sparse.csr.csr_matrix
Cell co-adjacency matrix.
- all_ranks_incidence_matrix(rank, weight: str | None = None, sparse: bool = True, index: bool = False)#
Compute the incidence matrix for the Colored Hypergraph indexed by cells of rank n and all other cells.
- Parameters:
- rankint
The rank which filters the cells based on which the incidence matrix is computed.
- weightstr, optional
If not given, all nonzero entries are 1.
- sparsebool, optional
The output will be sparse.
- indexbool, optional, default False
If True, the return will include a dictionary of node uid : row number and cell uid : column number.
- Returns:
- incidence_matrixscipy.sparse.csr.csr_matrix or np.ndarray
The incidence matrix.
- row dictionarydict
Dictionary identifying rows with nodes.
- column dictionarydict
Dictionary identifying columns with cells.
Notes
The all_ranks_incidence_matrix method computes the incidence matrix for the Colored Hypergraph, focusing on cells of rank n and all other cells. The weight parameter allows specifying the weight of the entries in the matrix. If index is True, dictionaries mapping node and cell identifiers to row and column numbers are included in the return.
- property cells#
Object associated with self._cells.
- Returns:
- HyperEdgeView
Returns all the present cells in the combinatorial complex along with their rank.
- clone() Self [source]#
Return a copy of the simplex.
The clone method by default returns an independent shallow copy of the simplex and attributes. That is, if an attribute is a container, that container is shared by the original and the copy. Use Python’s copy.deepcopy for new containers.
- Returns:
- CombinatorialComplex
A copy of this combinatorial complex.
- coadjacency_matrix(rank, via_rank, s: int = 1, index: bool = False)[source]#
Compute the coadjacency matrix of self.
- Parameters:
- rank, via_rankint
Two ranks for skeletons in the input combinatorial complex , such that r>k.
- sint, default=1
Minimum number of edges shared by neighbors with node.
- indexbool, default=False
Whether to return the indices of the rows and columns of the coadjacency matrix.
- Returns:
- indiceslist
List identifying the rows and columns of the coadjacency matrix with the cells of the combinatorial complex. Only returned if index is True.
- coadjacency_matrixscipy.sparse.csr.csr_matrix
The coadjacency matrix of this combinatorial complex.
- degree(node, rank: int = 1, s: int = 0) int #
Compute the number of cells of certain rank (or all ranks) that contain node.
- Parameters:
- nodehashable
Identifier for the node.
- rankint, optional
The rank at which the degree of the node is computed. When None, degree of the input node is computed with respect to cells of all ranks.
- sint, optional
Smallest size of cell to consider in degree.
- Returns:
- int
Number of cells of certain rank (or all ranks) that contain node.
- degree_matrix(rank: int, index: bool = False)#
Compute the node-degree matrix.
- Parameters:
- rankint
The rank (color) in the Colored Hypergraph to which the degree matrix is computed.
- indexbool, default: False
If True, return will include a dictionary of row number to node uid.
- Returns:
- row dictionarydict
Dictionary identifying rows with nodes. If False, this does not exist.
- degree_matrixscipy.sparse.csr.csr_matrix
The degree matrix.
- Raises:
- ValueError
If the rank is not in the range of the Colored Hypergraph.
- property dim: int#
Return the dimension of the colored hypergraph.
- Returns:
- int
The dimension of the colored hypergraph.
- dirac_operator_matrix(weight: str | None = None, index: bool = False)[source]#
Compute dirac operator matrix of self.
- Parameters:
- weightstr, optional
The name of the cell attribute to use as weights for the dirac operator matrix. If None, the matrix is binary.
- indexbool, default=False
If True, return will include a dictionary of all cells in the complex uid.
- Returns:
- scipy.sparse.csr.csc_matrix | tuple[dict, dict, scipy.sparse.csc_matrix]
The dirac operator matrix, if index is False; otherwise, row_indices, col_indices : dict List identifying rows and columns of the dirac operator matrix. Only returned if index is True. dirac_matrix : scipy.sparse.csr.csc_matrix The dirac operator matrix of this combinatorial complex.
Examples
>>> CCC = tnx.CombinatorialComplex() >>> CCC.add_cell([1, 2, 3, 4], rank=2) >>> CCC.add_cell([1, 2], rank=1) >>> CCC.add_cell([2, 3], rank=1) >>> CCC.add_cell([1, 4], rank=1) >>> CCC.add_cell([3, 4, 8], rank=2) >>> CCC.dirac_operator_matrix()
- from_networkx_graph(G) None #
Construct a Colored Hypergraph from a networkx graph.
- Parameters:
- GNetworkX graph
A networkx graph.
- Returns:
- None
The method modifies the current Colored Hypergraph.
Examples
>>> G = nx.Graph() >>> G.add_edge(0, 1) >>> G.add_edge(0, 4) >>> G.add_edge(0, 7) >>> CHG = tnx.ColoredHyperGraph() >>> CHG.from_networkx_graph(G) >>> CHG.nodes NodeView([(0,), (1,), (4,), (7,)])
- classmethod from_trimesh(mesh: Trimesh)#
Import from a trimesh.
- Parameters:
- meshtrimesh.Trimesh
The trimesh object to import.
Examples
>>> import trimesh >>> mesh = trimesh.Trimesh( ... vertices=[[0, 0, 0], [0, 0, 1], [0, 1, 0]], ... faces=[[0, 1, 2]], ... process=False, ... ) >>> CHG = tnx.ColoredHyperGraph.from_trimesh(mesh) >>> CHG.nodes
- get_adjacency_structure_dict(i, j)#
Get the adjacency structure dictionary for cells of rank i and j.
- Parameters:
- iint
The rank (color) of the first set of cells.
- jint
The rank (color) of the second set of cells.
- Returns:
- dict
The adjacency structure dictionary representing the relationship between cells of rank i and j.
Notes
The adjacency structure dictionary has cells of rank i as keys and lists of cells of rank j adjacent to them as values.
- get_cell_attributes(name: str, rank: int | None = None)[source]#
Get node attributes from graph.
- Parameters:
- namestr
Attribute name.
- rankint
Restrict the returned attribute values to cells of a specific rank.
- Returns:
- dict
Dictionary of attributes keyed by cell or k-cells if k is not None.
Examples
>>> G = nx.path_graph(3) >>> CCC = tnx.CombinatorialComplex(G) >>> d = { ... (1, 2): {"color": "red", "attr2": 1}, ... (0, 1): {"color": "blue", "attr2": 3}, ... } >>> CCC.set_cell_attributes(d) >>> cell_color = CCC.get_cell_attributes("color") >>> cell_color[frozenset({0, 1})] 'blue'
- get_incidence_structure_dict(i, j)#
Get the incidence structure dictionary for cells of rank i and j.
- Parameters:
- iint
The rank (color) of the first set of cells.
- jint
The rank (color) of the second set of cells.
- Returns:
- dict
The incidence structure dictionary representing the relationship between cells of rank i and j.
Notes
The incidence structure dictionary has cells of rank i as keys and lists of cells of rank j incident to them as values.
- get_node_attributes(name: str) dict[Hashable, Any] [source]#
Get node attributes.
- Parameters:
- namestr
Attribute name.
- Returns:
- dict[Hashable, Any]
Dictionary mapping each node to the value of the given attribute name.
Examples
>>> G = nx.path_graph(3) >>> CCC = tnx.CombinatorialComplex(G) >>> d = {0: {"color": "red", "attr2": 1}, 1: {"color": "blue", "attr2": 3}} >>> CCC.set_node_attributes(d) >>> CCC.get_node_attributes("color") {0: 'red', 1: 'blue'}
>>> G = nx.Graph() >>> G.add_nodes_from([1, 2, 3], color="blue") >>> CCC = tnx.CombinatorialComplex(G) >>> nodes_color = CCC.get_node_attributes("color") >>> nodes_color[1] 'blue'
- property incidence_dict#
Return dict keyed by cell uids with values the uids of nodes in each cell.
- Returns:
- dict
Dictionary of cell uids with values.
- incidence_matrix(rank: int, to_rank=None, incidence_type: Literal['up', 'down'] = 'up', weight: str | None = None, sparse: bool = True, index: bool = False)[source]#
Compute incidence matrix for the CCC between rank and to_rank skeleti.
- Parameters:
- rank, to_rankint
For which rank of cells to compute the incidence matrix.
- incidence_type{“up”, “down”}, default=”up”
Whether to compute the up or down incidence matrix.
- weightbool, default=False
The name of the cell attribute to use as weights for the incidence matrix. If None, all cell weights are considered to be one.
- sparsebool, default=True
Whether to return a sparse or dense incidence matrix.
- indexbool, default=False
Whether to return the indices of the rows and columns of the incidence matrix.
- Returns:
- row_indices, col_indicesdict
Dictionary assigning each row and column of the incidence matrix to a cell.
- incidence_matrixscipy.sparse.csr.csr_matrix
The incidence matrix.
- laplacian_matrix(rank, sparse=False, index=False)#
Compute Laplacian matrix.
- Parameters:
- rankint
The rank (or color) in the complex to which the Laplacian matrix is computed.
- sparsebool, default: False
Specifies whether the output matrix is a scipy sparse matrix or a numpy matrix.
- indexbool, default: False
If True, return will include a dictionary of node uid: row number.
- Returns:
- numpy.ndarray, scipy.sparse.csr.csr_matrix
Array of dimension (N, N), where N is the number of nodes in the Colored Hypergraph. If index is True, return a dictionary mapping node uid to row number.
- Raises:
- ValueError
If the rank is not in the range of the Colored Hypergraph.
References
[1]Lucas, M., Cencetti, G., & Battiston, F. (2020). Multiorder Laplacian for synchronization in higher-order networks. Physical Review Research, 2(3), 033410.
- new_hyperedge_key(hyperedge, rank)#
Add a new key for the given hyperedge.
- Parameters:
- hyperedgetuple or HyperEdge
Representing node elements of the hyperedge.
- rankint
Rank (color) of the input hyperedge.
- Returns:
- int
The new key assigned to the hyperedge.
Notes
In the standard ColoredHyperGraph class, the new key is determined by counting the number of existing hyperedges between the nodes that define the input hyperedge. The count is increased if necessary to ensure the key is unused. The first hyperedge will have key 0, then 1, and so on. If a hyperedge is removed, further new_hyperedge_keys may not be in this order.
- node_to_all_cell_adjacnecy_matrix(index: bool = False, s: int = 1)#
Compute the node/all cell adjacency matrix.
- Parameters:
- indexbool, optional
If True, will return a rowdict of row to node uid.
- sint, default=1
Minimum number of edges shared by neighbors with the node.
- Returns:
- row dictionarydict
Dictionary identifying rows with nodes. If False, this does not exist.
- cell adjacency matrixscipy.sparse.csr.csr_matrix
The cell adjacency matrix.
- node_to_all_cell_incidence_matrix(weight: str | None = None, index: bool = False) csc_matrix | tuple[dict, dict, csc_matrix] #
Nodes/all cells incidence matrix for the indexed by nodes X cells.
- Parameters:
- weightstr, optional
If not given, all nonzero entries are 1.
- indexbool, default=False
If True return will include a dictionary of node uid : row number and cell uid : column number.
- Returns:
- scipy.sparse.csr.csc_matrix | tuple[dict, dict, scipy.sparse.csc_matrix]
The incidence matrix, if index is False, otherwise lower (row) index dict, upper (col) index dict, incidence matrix where the index dictionaries map from the entity (as Hashable or tuple) to the row or col index of the matrix.
- property nodes#
Object associated with self.elements.
- Returns:
- NodeView
Returns all the nodes of the combinatorial complex.
- number_of_cells(cell_set=None) int [source]#
Compute the number of cells in cell_set belonging to the CCC.
- Parameters:
- cell_setiterable of HyperEdge, optional
If None, then return the number of cells.
- Returns:
- int
The number of cells in cell_set belonging to this combinatorial complex.
- number_of_nodes(node_set=None) int [source]#
Compute the number of nodes in node_set belonging to the CCC.
- Parameters:
- node_setiterable of Entities, optional
If None, then return the number of nodes in the CCC.
- Returns:
- int
The number of nodes in node_set belonging to this combinatorial complex.
- order() int [source]#
Compute the number of nodes in the CCC.
- Returns:
- int
The number of nodes in this combinatorial complex.
- property ranks#
Return the sorted list of ranks in the colored hypergraph.
- Returns:
- list
The sorted list of ranks.
- remove_cell(cell) None [source]#
Remove a single cell from CCC.
- Parameters:
- cellhashable or RankedEntity
The cell to remove from this combinatorial complex.
Notes
Deletes reference to cell from all of its nodes. If any of its nodes do not belong to any other cells the node is dropped from self.
- remove_cells(cell_set) None [source]#
Remove cells from CCC.
- Parameters:
- cell_setiterable of hashables
The cells to remove from this combinatorial complex.
- remove_node(node) None [source]#
Remove node from cells.
This also deletes any reference in the nodes of the CCC. This also deletes cell references in higher ranks for the particular node.
- Parameters:
- nodehashable or HyperEdge
The node to remove from this combinatorial complex.
- remove_nodes(node_set) None [source]#
Remove nodes from cells.
This also deletes references in combinatorial complex nodes.
- Parameters:
- node_setan iterable of hashables
The nodes to remove from this combinatorial complex.
- remove_singletons()[source]#
Construct new CCC with singleton cells removed.
- Returns:
- CombinatorialComplex
A copy of this combinatorial complex with singleton cells removed.
- restrict_to_cells(cell_set)#
Construct a Colored Hypergraph using a subset of the cells.
- Parameters:
- cell_sethashable
A subset of elements of the Colored Hypergraph cells.
- Returns:
- ColoredHyperGraph
The Colored Hypergraph constructed from the specified subset of cells.
- restrict_to_nodes(node_set)#
Restrict to a set of nodes.
Constructs a new Colored Hypergraph by restricting the cells in the Colored Hypergraph to the nodes referenced by node_set.
- Parameters:
- node_setiterable of hashables
References a subset of elements of self.nodes.
- Returns:
- ColoredHyperGraph
A new Colored Hypergraph restricted to the specified node_set.
- set_cell_attributes(values, name: str | None = None) None [source]#
Set cell attributes.
- Parameters:
- valuesdict
Dictionary of cell attributes to set keyed by cell name.
- namestr, optional
Attribute name.
Examples
After computing some property of the cell of a combinatorial complex, you may want to assign a cell attribute to store the value of that property for each cell:
>>> CCC = tnx.CombinatorialComplex() >>> CCC.add_cell([1, 2, 3, 4], rank=2) >>> CCC.add_cell([1, 2, 4], rank=2) >>> CCC.add_cell([3, 4], rank=2) >>> d = {(1, 2, 3, 4): "red", (1, 2, 3): "blue", (3, 4): "green"} >>> CCC.set_cell_attributes(d, name="color") >>> CCC.cells[(3, 4)]["color"] 'green'
If you provide a dictionary of dictionaries as the second argument, the entire dictionary will be used to update edge attributes:
>>> G = nx.path_graph(3) >>> CCC = tnx.CombinatorialComplex(G) >>> d = { ... (1, 2): {"color": "red", "attr2": 1}, ... (0, 1): {"color": "blue", "attr2": 3}, ... } >>> CCC.set_cell_attributes(d) >>> CCC.cells[(0, 1)]["color"] 'blue' 3
Note that if the dict contains cells that are not in self.cells, they are silently ignored.
- set_node_attributes(values, name: str | None = None) None #
Set node attributes.
- Parameters:
- valuesdict
A dictionary where keys are nodes and values are the attributes to set.
- namestr or None, optional
The name of the attribute to set for all nodes. If None, attributes will be set individually for each node.
- Returns:
- None
Set the attributes of the nodes.
- property shape#
Return shape.
This is: (number of cells[i], for i in range(0,dim(CCC)) )
- Returns:
- tuple of ints
Shape of the CC object.
- singletons()[source]#
Return a list of singleton cell.
A singleton cell is a node of degree 0.
- Returns:
- list
A list of cells uids.
Examples
>>> CCC = tnx.CombinatorialComplex() >>> CCC.add_cell([1, 2], rank=1) >>> CCC.add_cell([3, 4], rank=1) >>> CCC.add_cell([9], rank=0) >>> CCC.singletons() [frozenset({9})]
- size(cell)#
Compute the number of nodes in the colored hypergraph that belong to a specific cell.
- Parameters:
- cellhashable or HyperEdge
The cell for which to compute the size.
- Returns:
- int
The number of nodes in the colored hypergraph that belong to the specified cell.
- Raises:
- ValueError
If the input cell is not in the cells of the colored hypergraph.
- skeleton(rank: int, level: Literal['equal', 'upper', 'up', 'lower', 'down', 'uppereq', 'upeq', 'lowereq', 'downeq'] = 'equal')[source]#
Skeleton of the CCC.
- Parameters:
- rankint
The rank of the skeleton.
- levelstr, default=”equal”
Level of the skeleton.
- Returns:
- list of HyperEdge
The skeleton of the CCC.