Chapter 1
Introduction
This chapter explains why group interactions call for a representation of their own, shows on a four-vertex example how much a graph forgets, and maps the rest of the book onto the questions a hypergraph helps to answer. It then places hatvis among the existing hypergraph software, fixes the notation used in every chapter, describes the conventions shared by all functions of the package, and ends with a first session that builds, prints, and draws a hypergraph.
1.1 Problem and idea
Network science describes a system by its parts and by the pairs of parts that interact. The description is powerful because the pair is the simplest relation that still has structure: from pairs one obtains paths, distances, degrees, clusters, flows, and the whole apparatus of graph algorithms. Many relations, however, are not pairs. A machining step needs an operator, a machine, and a fixture at the same time; a scientific paper has a set of authors; a chemical reaction consumes a set of reactants; a customer requirement of a product is satisfied by a combination of engineering solutions; a news article mentions a set of themes; a shopping basket holds a set of items. The natural object in each case is a set of parts, and the system is a family of such sets. Recent reviews have argued in detail that these higher-order interactions change the structure and the dynamics of complex systems, not only their bookkeeping [11, 12, 13, 14].
A family of subsets of a vertex set is a hypergraph [15, 16, 17]. The usual way to analyze it with graph tools is to project it: either onto a graph on the vertices, linking two vertices whenever they appear together in some set (the clique expansion), or onto a bipartite graph whose two kinds of nodes are the vertices and the sets (the star expansion). Both projections are useful, and much of this book uses them, but the first one loses information that cannot be recovered. Figure 1.1 shows the simplest case. A team of three people and three separate pairs have the same clique expansion, a triangle; so do a team of four and the six pairs inside it, or a team of four and four teams of three. Whether the three people ever worked together, whether a requirement needs all three solutions or any two of them, whether a basket contained the three items at once or never more than two, is exactly the information the projection discards.
The idea of the book follows from this example. Instead of choosing one projection and forgetting the hypergraph, we keep the hypergraph as the primary object and derive from it, explicitly and with known losses, whatever representation a question needs: the incidence matrix for seriation and biclustering, the bipartite graph for drawing and for partitioning, the clique expansion for spectral methods, the -line graphs for walks that require a minimum overlap, the adjacency tensor for centralities that respect the group, the transaction database for pattern mining. Each of these is a view of the same data, and the analysis is honest when the reader knows which view produced which number.
1.2 What the hypergraph view buys
The chapters of the book are organized by the question asked, not by the mathematical object. Figure 1.2 shows the flow: data become a hypergraph, the hypergraph is represented in several ways, the representations feed the views and the analyses, and the analyses feed decisions. Five advantages of the hypergraph view recur throughout and are summarized in chapter 13.
- Lossless storage.
-
The incidence matrix stores the groups exactly, with weights, multiplicities, and attributes. Every other representation is computed from it, and the losses of each are known (chapter 2).
- Group-aware distances.
-
Two hyperedges are adjacent in the -line graph only if they share at least vertices. Walks and centralities parametrized by distinguish a strongly connected cell from a chain of weak contacts, which no pairwise distance can do (chapter 6).
- Group-aware objectives.
-
Hypergraph modularity, cut, and covering objectives count a group once, as a whole, rather than once per pair; a graph objective over-weights large groups quadratically (chapters 7 and 10).
- Patterns as hyperedges.
-
A frequent itemset, a validated group, or a motif is a hyperedge of a derived hypergraph; mining, validation, and visualization therefore use the same machinery (chapters 8 and 9).
- Nonlinear group effects.
-
Contagion that requires a critical mass in a group, and consensus that depends on the agreement within a group, produce phenomena (hysteresis, bistability, accelerated or slowed convergence) that have no pairwise analogue (chapter 11).
1.3 The software landscape
Hypergraph software has grown quickly in the last five years, and the packages differ more in their purpose than in their data structures. Table 1.1 lists the packages that hatvis interoperates with or builds upon.
The Hypergraph Analysis Toolbox (HAT) [18], available for MATLAB and Python, was the first general package to base hypergraph analysis on tensor algebra; it contains the hypergraph similarity measures of Surana, Chen, and Rajapakse [19] and methods for controllability and dynamics. HyperNetX [20], developed at the Pacific Northwest National Laboratory, implements the -walk framework of Aksoy et al. [21] and draws hypergraphs as Euler-type diagrams in Matplotlib and in an interactive widget. XGI [22] represents higher-order interaction networks with a rich statistics interface, a collection of empirical data sets, and drawing functions for hypergraphs and simplicial complexes. Hypergraphx [23] gathers many recent methods of the network-physics community, among them higher-order motifs, statistically validated hyperedges, community models, and dynamical processes. EasyHypergraph [24], a module of the EasyGraph framework, aims at speed and memory efficiency for both analysis and hypergraph neural networks, and the DeepHypergraph library accompanies the HGNN family of neural models [25]. The Hypergraph Interchange Format (HIF) [26], written jointly by maintainers of several of these packages, defines a JSON schema for undirected and directed hypergraphs and simplicial complexes with attributes on vertices, hyperedges, and incidences; it is the natural way to move data between them.
Two tools of the authors’ group are the direct ancestors of hatvis. HAT-VIS [1] is a MATLAB tool for the similarity-based visualization of hypergraphs; its pipeline (weighted Jaccard similarity, transitive closure, multidimensional scaling, minimal-spanning-tree hyperedges, seriated incidence matrix) is the subject of chapter 5. HyperGodot [2] is an interactive viewer built on the Godot engine with force-directed and circular layouts, padded convex hulls, and comparative views of several system variants; its layout and drawing model is the subject of chapter 4.
Package | Language | Main focus | Interop |
HAT [18] | MATLAB, Python | tensor methods, similarity, controllability | HIF |
HyperNetX [20] | Python | -walks, Euler-type drawings, widget | converter, HIF |
XGI [22] | Python | statistics, data sets, drawing | converter, HIF |
Hypergraphx [23] | Python | motifs, validation, communities, dynamics | converter, HIF |
EasyHypergraph [24] | Python | fast analysis and learning | incidence / edge list |
HAT-VIS [1] | MATLAB | similarity-based visualization | reimplemented |
HyperGodot [2] | Godot (GDScript) | interactive layouts and comparison | text format, reimplemented |
hatvis does not try to replace these packages. Its aims are narrower and complementary: to put the visualization methods of HAT-VIS and HyperGodot, the manufacturing and quality-engineering applications of the group, and the most useful analysis methods of the literature into one consistent, documented, and tested Python API; to make every representation explicit; and to give each method a worked example and a chapter that explains when it should be used.
1.4 Notation
The notation of table 1.2 is used in every chapter, in the docstrings of the package, and in the online documentation. Index always runs over vertices and over hyperedges. A vertex is also called a node; the book says vertex, the code says node, as in NetworkX, HyperNetX, and XGI.
Symbol | Meaning | Code |
| hypergraph: vertices, hyperedges, weights | Hypergraph |
, | numbers of vertices and hyperedges | H.n_nodes, H.n_edges |
| incidence matrix, iff | H.incidence |
, | hyperedge weights | H.weights |
| size (cardinality) of hyperedge | H.edge_sizes() |
| (weighted) degree of vertex | H.degrees() |
, | diagonal degree and size matrices |
|
| dual hypergraph, incidence | H.dual() |
| -line graph: | s_line_graph(H, s) |
| clique-expansion adjacency | clique_adjacency(H) |
| a hypergraph Laplacian | laplacian(H, kind) |
, | vertex similarity and dissimilarity | vertex_similarity(H) |
, | layout coordinates | dict label -> (x, y) |
| transaction database | hypergraph_to_transactions |
| relative support of itemset | frequent_itemsets |
| partition (community labels) | pandas.Series of int |
1.5 Conventions of the package
Every function of hatvis follows the same small set of rules, so that the results of one method can be passed to another without conversion.
- Functions take the hypergraph as their first argument:
hv.s_betweenness(H, s=2),hv.modularity(H, partition). - Results at the level of vertices or hyperedges are pandas.Series indexed by the labels; tables are pandas.DataFrame; matrices are NumPy arrays aligned with H.nodes and H.edges, or SciPy sparse arrays where this is stated.
- Partitions are pandas.Series of consecutive integers indexed by the vertex labels.
- Randomness is controlled by a random_state argument (None, an integer, or a NumPy Generator); all examples use random_state=0.
- Layout functions are called layout_* and return a dictionary from vertex label to a NumPy array of two coordinates; every drawing function accepts such a dictionary as pos.
- Plotting functions are called plot_* or, for node-link drawings, draw_*; they take an optional Matplotlib ax, return it, and never call plt.show(). Categorical colors come from the Okabe–Ito palette [27], which remains distinguishable for the common forms of color-vision deficiency.
- Optional dependencies (HyperNetX, XGI, Hypergraphx, openpyxl) are imported only inside the functions that need them.
- Hypergraphs are immutable in spirit: every transformation (restriction, dual, collapse, filtering, -cut) returns a new object and leaves the original unchanged.
The package depends on NumPy, SciPy, pandas, NetworkX, scikit-learn, and Matplotlib. The integer programs of chapter 10 use the HiGHS solver [28] through scipy.optimize.milp.
1.6 A first session
The smallest example of the HAT-VIS paper [1] has five vertices and three hyperedges of three vertices each. It is built from a dictionary that maps hyperedge labels to member lists; lists of member sets, incidence matrices, and long-format data frames are accepted as well (section 2.4).
H = hv.Hypergraph({"e1": ["v1", "v2", "v3"], "e2": ["v1", "v2", "v4"], "e3": ["v3", "v4", "v5"]}) print(H.to_dataframe().astype(int)) print(H.degrees().to_dict(), H.edge_sizes().to_dict()) D = H.dual() print(D.edge_dict())
The incidence matrix has a row per vertex and a column per hyperedge. The degrees are and ; all three hyperedges have size 3. The dual hypergraph exchanges the two roles: its vertices are , and every original vertex becomes a hyperedge listing the hyperedges that contain it, so becomes and the singleton . The two views of fig. 1.3 are complete descriptions of the same object: the matrix shows every incidence explicitly and scales to thousands of rows, while the drawing shows at a glance which groups overlap. Neither is a projection; both can be computed back into the other. Already this small example has a feature that the following chapters return to: and belong to exactly the same hyperedges, so no analysis based on incidences alone can tell them apart, and a similarity-based layout places them on top of each other (chapter 5).
1.7 Further reading
Berge’s monographs [15, 16] remain the standard reference for the combinatorics of hypergraphs, and Bretto [17] gives a modern introduction. The review of Battiston et al. [11] surveys the structure and dynamics of networks beyond pairwise interactions; Bick et al. [13] compare hypergraphs, simplicial complexes, and other higher-order models from a mathematical viewpoint, and Torres et al. [14] discuss when each representation of a complex system is appropriate. Lee et al. [29] survey the structural patterns observed in real-world hypergraphs and the tools and generators used to find them. For visualization, the surveys of Alsallakh et al. on set visualization [30] and of Fischer et al. on hypergraph visualization [31] are the best starting points.