xgi.linalg.laplacian_matrix

Laplacian matrices associated to hypergraphs.

Note that the order of the rows and columns of the matrices in this module correspond to the order in which nodes/edges are added to the hypergraph or simplicial complex. If the node and edge IDs are able to be sorted, the following is an example to sort by the node and edge IDs.

>>> import xgi
>>> import pandas as pd
>>> H = xgi.Hypergraph([[1, 2, 3, 7], [4], [5, 6, 7]])
>>> I, nodedict, edgedict = xgi.incidence_matrix(H, sparse=False, index=True)
>>> # Sorting the resulting numpy array:
>>> sortedI = I.copy()
>>> sortedI = sortedI[sorted(nodedict, key=nodedict.get), :]
>>> sortedI = sortedI[:, sorted(edgedict, key=edgedict.get)]
>>> sortedI
array([[1, 0, 0],
       [1, 0, 0],
       [1, 0, 0],
       [0, 1, 0],
       [0, 0, 1],
       [0, 0, 1],
       [1, 0, 1]])
>>> # Indexing a Pandas dataframe by the node/edge IDs
>>> df = pd.DataFrame(I, index=nodedict.values(), columns=edgedict.values())

If the nodes are already sorted, this order can be preserved by adding the nodes to the hypergraph prior to adding edges. For example,

>>> import xgi
>>> H = xgi.Hypergraph()
>>> H.add_nodes_from(range(1, 8))
>>> H.add_edges_from([[1, 2, 3, 7], [4], [5, 6, 7]])
>>> xgi.incidence_matrix(H, sparse=False)
array([[1, 0, 0],
       [1, 0, 0],
       [1, 0, 0],
       [0, 1, 0],
       [0, 0, 1],
       [0, 0, 1],
       [1, 0, 1]])

Functions

xgi.linalg.laplacian_matrix.laplacian(H, order=1, sparse=False, rescale_per_node=False, index=False)[source]

Laplacian matrix of order d, see [1].

Parameters:
  • HG (Hypergraph) – Hypergraph

  • order (int) – Order of interactions to consider. If order=1 (default), returns the usual graph Laplacian.

  • sparse (bool, default: False) – Specifies whether the output matrix is a scipy sparse matrix or a numpy matrix.

  • index (bool, default: False) – Specifies whether to output disctionaries mapping the node and edge IDs to indices.

Returns:

  • L_d (numpy array) – Array of dim (N, N)

  • if index is True – return rowdict

References

xgi.linalg.laplacian_matrix.multiorder_laplacian(H, orders, weights, sparse=False, rescale_per_node=False, index=False)[source]

Multiorder Laplacian matrix, see [1].

Parameters:
  • HG (Hypergraph) – Hypergraph

  • orders (list of int) – Orders of interactions to consider.

  • weights (list of float) – Weights associated to each order, i.e coupling strengths gamma_i in [1].

  • sparse (bool, default: False) – Specifies whether the output matrix is a scipy sparse matrix or a numpy matrix

  • rescale_per_node (bool, (default=False)) – Whether to rescale each Laplacian of order d by d (per node).

  • index (bool, default: False) – Specifies whether to output dictionaries mapping the node and edge IDs to indices.

Returns:

  • L_multi (numpy array) – Array of dim (N, N)

  • if index is True – return rowdict

See also

laplacian

References

xgi.linalg.laplacian_matrix.normalized_hypergraph_laplacian(H, sparse=True, index=False)[source]

Compute the normalized Laplacian.

Parameters:
  • H (Hypergraph) – Hypergraph

  • sparse (bool, optional) – whether or not the laplacian is sparse, by default True

  • index (bool, optional) – whether to return a dictionary mapping IDs to rows, by default False

Returns:

  • array – csr_array if sparse and if not, a numpy ndarray

  • dict – a dictionary mapping node IDs to rows and columns if index is True.

Raises:

XGIError – If there are isolated nodes.

References

“Learning with Hypergraphs: Clustering, Classification, and Embedding” by Dengyong Zhou, Jiayuan Huang, Bernhard Schölkopf Advances in Neural Information Processing Systems (2006)