Function Repository Resource:

HypergraphAdjacencyMatrix

Source Notebook

Find the adjacency matrix for vertices in a hypergraph

Contributed by: Stephen Wolfram

ResourceFunction["HypergraphAdjacencyMatrix"][hg]

finds the adjacency matrix for the hypergraph hg.

Details and Options

The entries in the hypergraph adjacency matrix count the number of cooccurrences of vertices within edges.
A hypergraph is represented by a list of edge lists, with each edge list containing a list of vertices in that edge.
ResourceFunction["HypergraphAdjacencyMatrix"] returns a SparseArray object, which can be converted to an ordinary matrix using Normal.

Examples

Basic Examples (3) 

Make an adjacency matrix from a fairly simple hypergraph:

In[1]:=
m = ResourceFunction[
  "HypergraphAdjacencyMatrix"][{{1, 0, 0}, {1, 0, 2}, {4, 3, 1}, {4, 0, 5}, {7, 6, 4}, {7, 0, 8}, {10, 9, 7}, {10, 0, 11}, {13, 12, 10}, {13, 0, 14}, {13, 16, 16}, {16, 15, 13}, {16, 0, 17}, {18, 0,
     16}}]
Out[1]=

Use MatrixPlot to visualize the matrix:

In[2]:=
MatrixPlot[m]
Out[2]=

See the adjacency matrix:

In[3]:=
MatrixForm[Normal[m]]
Out[3]=

Version History

  • 2.0.0 – 17 March 2020
  • 1.0.0 – 04 December 2019

Related Resources

License Information