toponetx.ColoredHyperGraph#

class toponetx.ColoredHyperGraph(cells: Collection | None = None, ranks: Collection | int | None = None, **kwargs)[source]#

Bases: Complex

Class for ColoredHyperGraph Complex.

A Colored Hypergraph (CHG) is a triplet CHG = (S, X, c) where: - S is an abstract set of entities, - X is a subset of the power set of S, and - c is the color function that associates a positive integer color or rank to each set x in X.

A CHG is a generalization of graphs, combinatorial complexes, hypergraphs, cellular, and simplicial complexes.

Parameters:
cellsCollection, optional

The initial collection of cells in the Colored Hypergraph.

ranksCollection, optional

Represents the color of cells.

**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, key])

Add a single cell to Colored Hypergraph.

add_cells_from(cells[, ranks])

Add cells to Colored Hypergraph.

add_node(node, **attr)

Add a node.

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.

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.

from_networkx_graph(G)

Construct a Colored Hypergraph from a networkx graph.

from_trimesh(mesh)

Import from a trimesh.

get_adjacency_structure_dict(i, j)

Get the adjacency structure dictionary for cells of rank i and j.

get_cell_attributes(name[, rank])

Get cell attributes from the colored hypergraph.

get_incidence_structure_dict(i, j)

Get the incidence structure dictionary for cells of rank i and j.

get_node_attributes(name)

Get node attributes.

incidence_matrix(rank, to_rank[, weight, ...])

Compute incidence matrix for the CHG indexed by nodes x cells.

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 the colored hypergraph.

number_of_nodes([node_set])

Compute the number of nodes in node_set belonging to the CHG.

order()

Compute the number of nodes in the CHG.

remove_cell(cell)

Remove a single cell from the ColoredHyperGraph.

remove_cells(cell_set)

Remove cells from this colored hypergraph.

remove_node(node)

Remove a node from the ColoredHyperGraph.

remove_nodes(node_set)

Remove nodes from cells.

remove_singletons()

Construct new CHG 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.

singletons()

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)

Return skeleton.

Examples

Define an empty colored hypergraph:

>>> CHG = tnx.ColoredHyperGraph()

Add cells to the colored hypergraph:

>>> CHG = tnx.ColoredHyperGraph()
>>> CHG.add_cell([1, 2], rank=1)
>>> CHG.add_cell([3, 4], rank=1)
>>> CHG.add_cell([1, 2, 3, 4], rank=2)
>>> CHG.add_cell([1, 2, 4], rank=2)
>>> CHG.add_cell([1, 2, 3, 4, 5, 6, 7], rank=3)

Create a Colored Hypergraph and add groups of friends with corresponding ranks:

>>> CHG = tnx.ColoredHyperGraph()
>>> CHG.add_cell(
...     ["Alice", "Bob"], rank=1
... )  # Alice and Bob are in a close-knit group.
>>> CHG.add_cell(["Charlie", "David"], rank=1)  # Another closely connected group.
>>> CHG.add_cell(
...     ["Alice", "Bob", "Charlie", "David"], rank=2
... )  # Both groups together form a higher-ranked community.
>>> CHG.add_cell(["Alice", "Bob", "David"], rank=2)  # Overlapping connections.
>>> CHG.add_cell(
...     ["Alice", "Bob", "Charlie", "David", "Eve", "Frank", "Grace"], rank=3
... )  # A larger, more influential community.

The code demonstrates how to represent social relationships using a Colored Hypergraph, where each group of friends (hyperedge) is assigned a rank based on the strength of the connection.

__init__(cells: Collection | None = None, ranks: Collection | int | None = None, **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])

Initialize a new instance of the Complex class.

add_cell(cell[, rank, key])

Add a single cell to Colored Hypergraph.

add_cells_from(cells[, ranks])

Add cells to Colored Hypergraph.

add_node(node, **attr)

Add a node.

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.

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.

from_networkx_graph(G)

Construct a Colored Hypergraph from a networkx graph.

from_trimesh(mesh)

Import from a trimesh.

get_adjacency_structure_dict(i, j)

Get the adjacency structure dictionary for cells of rank i and j.

get_cell_attributes(name[, rank])

Get cell attributes from the colored hypergraph.

get_incidence_structure_dict(i, j)

Get the incidence structure dictionary for cells of rank i and j.

get_node_attributes(name)

Get node attributes.

incidence_matrix(rank, to_rank[, weight, ...])

Compute incidence matrix for the CHG indexed by nodes x cells.

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 the colored hypergraph.

number_of_nodes([node_set])

Compute the number of nodes in node_set belonging to the CHG.

order()

Compute the number of nodes in the CHG.

remove_cell(cell)

Remove a single cell from the ColoredHyperGraph.

remove_cells(cell_set)

Remove cells from this colored hypergraph.

remove_node(node)

Remove a node from the ColoredHyperGraph.

remove_nodes(node_set)

Remove nodes from cells.

remove_singletons()

Construct new CHG 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.

singletons()

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)

Return skeleton.

Attributes

cells

Object associated with self._cells.

dim

Return the dimension of the colored hypergraph.

incidence_dict

Return dict keyed by cell uids with values the uids of nodes in each cell.

nodes

Object associated with self.elements.

ranks

Return the sorted list of ranks in the colored hypergraph.

shape

Return shape.

complex

add_cell(cell, rank=None, key=None, **attr)[source]#

Add a single cell to Colored Hypergraph.

Parameters:
cellhashable, iterable, or HyperEdge

If hashable, the cell returned will be empty.

rankint

The rank of a cell.

keyint, optional

Used to distinguish colored hyperedges among nodes.

**attrattributes associated with hyperedge

Attributes of the hyperedge.

Returns:
ColoredHyperGraph

The modified Colored Hypergraph.

Notes

The add_cell method adds a cell to the Colored Hypergraph instance. The cell can be a hashable, iterable, or HyperEdge. If the cell is hashable, the resulting cell will be empty. The rank parameter specifies the rank of the cell.

add_cells_from(cells, ranks=None)[source]#

Add cells to Colored Hypergraph.

Parameters:
cellsiterable of hashables

For hashables, the cells returned will be empty.

ranksIterable or int

When iterable, len(ranks) == len(cells).

Returns:
None

None.

add_node(node, **attr) None[source]#

Add a node.

Parameters:
nodehashable

The node to add.

**attrdict

Additional attributes to assign to the node.

Returns:
None

None.

adjacency_matrix(rank, via_rank, s: int = 1, index: bool = False)[source]#

Sparse weighted s-adjacency matrix.

Parameters:
rank, via_rankint, int

Two ranks for skeletons in the input Colored Hypergraph.

sint, list, optional

Minimum number of edges shared by neighbors with node.

indexbool, optional

If True, will return a rowdict of row to node uid.

Returns:
row dictionarydict

Dictionary identifying rows with nodes. If False, this does not exist.

adjacency_matrixscipy.sparse.csr.csr_matrix

The adjacency matrix.

Examples

>>> G = nx.Graph()  # networkx graph
>>> G.add_edge(0, 1)
>>> G.add_edge(0, 3)
>>> G.add_edge(0, 4)
>>> G.add_edge(1, 4)
>>> CHG = tnx.ColoredHyperGraph(cells=G)
>>> CHG.adjacency_matrix(0, 1)
all_cell_to_node_coadjacency_matrix(index: bool = False, s: int = 1)[source]#

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)[source]#

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

HyperEdgeView of all cells and associated ranks.

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:
ColoredHyperGraph

ColoredHyperGraph.

coadjacency_matrix(rank, via_rank, s: int = 1, index: bool = False)[source]#

Compute the coadjacency matrix.

Parameters:
rankint

The rank for the primary skeleton in the input Colored Hypergraph.

via_rankint

The rank for the secondary skeleton in the input Colored Hypergraph.

sint, optional

Minimum number of edges shared by neighbors with the node.

indexbool, optional

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.

co-adjacency_matrixscipy.sparse.csr.csr_matrix

The co-adjacency matrix.

degree(node, rank: int = 1, s: int = 0) int[source]#

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)[source]#

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.

from_networkx_graph(G) None[source]#

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)[source]#

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)[source]#

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=None)[source]#

Get cell attributes from the colored hypergraph.

Parameters:
namestr

Attribute name.

rankint, optional

Rank of the k-cell. If specified, the function returns attributes for k-cells with the given rank. If not provided, the function returns attributes for all cells.

Returns:
dict

Dictionary of attributes keyed by cell or k-cells if rank is not None.

Examples

>>> G = nx.path_graph(3)
>>> CHG = tnx.ColoredHyperGraph(G)
>>> d = {
...     ((1, 2), 0): {"color": "red", "attr2": 1},
...     ((0, 1), 0): {"color": "blue", "attr2": 3},
... }
>>> CHG.set_cell_attributes(d)
>>> cell_color = CHG.get_cell_attributes("color")
>>> cell_color[(frozenset({0, 1}), 0)]
'blue'
get_incidence_structure_dict(i, j)[source]#

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)[source]#

Get node attributes.

Parameters:
namestr

Attribute name.

Returns:
dict

Dictionary of attributes keyed by node.

Examples

>>> G = nx.path_graph(3)
>>> CHG = tnx.ColoredHyperGraph(G)
>>> d = {0: {"color": "red", "attr2": 1}, 1: {"color": "blue", "attr2": 3}}
>>> CHG.set_node_attributes(d)
>>> CHG.get_node_attributes("color")
{0: 'red', 1: 'blue'}
>>> G = nx.Graph()
>>> G.add_nodes_from([1, 2, 3], color="blue")
>>> CHG = tnx.ColoredHyperGraph(G)
>>> nodes_color = CHG.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: int, weight: str | None = None, sparse: bool = True, index: bool = False)[source]#

Compute incidence matrix for the CHG indexed by nodes x cells.

An incidence matrix indexed by r-ranked hyperedges and k-ranked hyperedges where r != k. When k is None, incidence_type will be considered instead.

Parameters:
rankint

The rank for computing the incidence matrix.

to_rankint

The rank for computing the incidence matrix.

weightstr, default=None

The attribute to use as weight. If None, all weights are considered to be one.

sparsebool, default=True

Whether to return a sparse or dense incidence matrix.

indexbool, default=False

If True, 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.

laplacian_matrix(rank, sparse=False, index=False)[source]#

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)[source]#

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)[source]#

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][source]#

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

NodeView of all nodes.

number_of_cells(cell_set=None)[source]#

Compute the number of cells in the colored hypergraph.

Parameters:
cell_setiterable of HyperEdge, optional

If provided, computes the number of cells belonging to the specified cell_set. If None, returns the total number of cells in the hypergraph.

Returns:
int

The number of cells in the specified cell_set or the total number of cells if cell_set is None.

number_of_nodes(node_set=None)[source]#

Compute the number of nodes in node_set belonging to the CHG.

Parameters:
node_setan interable of Entities, optional

If None, then return the number of nodes in the CHG.

Returns:
int

Number of nodes in node_set belonging to the CHG.

order()[source]#

Compute the number of nodes in the CHG.

Returns:
int

The number of nudes in this hypergraph.

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 the ColoredHyperGraph.

Parameters:
cellHashable or RankedEntity

The cell to be removed.

Returns:
None

The cell is removed in place.

Notes

Deletes the reference to the cell from all of its nodes. If any of its nodes do not belong to any other cells, the node is dropped from the ColoredHyperGraph.

remove_cells(cell_set) None[source]#

Remove cells from this colored hypergraph.

Parameters:
cell_setiterable of hashables

The cells to remove from this colored hypergraph.

remove_node(node) Self[source]#

Remove a node from the ColoredHyperGraph.

This method removes a node from the cells and deletes any reference in the nodes of the CHG.

Parameters:
nodeHyperEdge or Hashable

The node to be removed.

Returns:
ColoredHyperGraph

The ColoredHyperGraph instance after removing the node.

remove_nodes(node_set) None[source]#

Remove nodes from cells.

This also deletes references in colored hypergraph nodes.

Parameters:
node_setan iterable of hashables

The nodes to remove from this colored hypergraph.

remove_singletons()[source]#

Construct new CHG with singleton cells removed.

Returns:
ColoredHyperGraph

Return new CHG with singleton cells removed.

restrict_to_cells(cell_set)[source]#

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)[source]#

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 attributes to set for the cell.

namestr, optional

Name of the attribute to set for the cell.

Returns:
None

Set the attributes of the cells.

Examples

After computing some property of the cell of a Colored Hypergraph, you may want to assign a cell attribute to store the value of that property for each cell:

>>> CHG = tnx.ColoredHyperGraph()
>>> CHG.add_cell([1, 2, 3, 4], rank=2)
>>> CHG.add_cell([1, 2, 4], rank=2)
>>> CHG.add_cell([3, 4], rank=2)
>>> d = {((1, 2, 3, 4), 0): "red", ((1, 2, 4), 0): "blue", ((3, 4), 0): "green"}
>>> CHG.set_cell_attributes(d, name="color")
>>> CHG.cells[((3, 4), 0)]["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)
>>> CHG = tnx.ColoredHyperGraph(G)
>>> d = {
...     ((1, 2), 0): {"color": "red", "attr2": 1},
...     ((0, 1), 0): {"color": "blue", "attr2": 3},
... }
>>> CHG.set_cell_attributes(d)
>>> CHG.cells[((0, 1), 0)]["color"]
'blue'

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[source]#

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: tuple[int, ...]#

Return shape.

This is: (number of cells[i], for i in range(0,dim(CHG)) )

Returns:
tuple of ints

Tuple of number of cells in each rank.

singletons()[source]#

Return a list of singleton cell.

A singleton cell is a cell of size 1 with a node of degree 1.

Returns:
list

A list of cells uids.

size(cell)[source]#

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)[source]#

Return skeleton.

Parameters:
rankint

Rank.

Returns:
int

Number of cells in specified rank.