Chapter 3
Matrix views
The incidence matrix is the only drawing of a hypergraph that never hides an incidence and never needs a layout, but in its original order it is a scatter of dots. This chapter treats the reordering of rows and columns (seriation) as an optimization problem, presents the iterative barycentric method of HAT-VIS together with correspondence analysis and hierarchical clustering with optimal leaf ordering, measures the result with the Moore stress and the bond energy, and extracts biclusters, groups of vertices used together by groups of hyperedges. Two set-oriented matrix views close the chapter: the UpSet plot of intersections and the PAOH view of a hypergraph that changes over time. The examples use the wire-harness manufacturing space of [4] and a synthetic collection of news articles.
3.1 Problem and idea
A node-link drawing of a hypergraph with seventy hyperedges is a tangle of overlapping outlines; the incidence matrix of the same hypergraph is a grid of cells that can be read row by row, column by column, at any size. Its weakness is that the rows and columns have no natural order. Resources are listed by type, activities by the time they occur, and the blocks that matter (a cell of machines and operators that always work together, a group of activities that use the same tools) are spread over the whole matrix. Permuting rows and columns changes nothing in the data and everything in the picture (fig. 3.1).
The idea of seriation is to choose the permutations so that similar rows and similar columns are adjacent, which turns co-occurrence into visible blocks and bands [44, 45]. Once the matrix is ordered, a second step can name the blocks explicitly: a bicluster is a set of rows and a set of columns whose submatrix is dense. In a manufacturing space the biclusters are candidate cells; in a document collection they are topics with their documents; in a market-basket hypergraph they are product families with their customer segments.
3.2 Theory
3.2.1 Seriation as an optimization problem
Let be the incidence matrix (or its 0/1 pattern) and let and be permutations of the rows and columns. Seriation chooses to minimize a loss or maximize a merit of the reordered matrix . Two measures are standard for binary matrices. The Moore stress [46] sums the squared differences between neighboring cells,
|
| (3.1) |
and counts the boundaries between filled and empty cells; it is small when the ones form compact blocks. The bond energy of McCormick, Schweitzer, and White [47],
|
| (3.2) |
counts the pairs of filled cells that touch and is large for the same arrangements. For a 0/1 matrix the two are related: every incidence has four sides, each either shared with another incidence or a boundary, so maximizing the bonds and minimizing the boundaries pull in the same direction, although the treatment of the matrix border makes them differ in detail. Finding the optimal permutations is NP-hard for both measures (the row problem alone contains the traveling salesman problem), so practical methods are heuristics or relaxations [44, 48]. Three of them are implemented in hatvis.
3.2.2 Barycentric seriation
The HAT-VIS scripts [1] order the vertices by an iteration on the co-occurrence matrix of (2.1). Starting from the current rank vector (initially ), every row receives the weighted average of the ranks of the rows it co-occurs with,
|
| (3.3) |
and the rows are re-ranked by ; the columns are ordered in the same way with . The iteration is a discrete form of reciprocal averaging: rows that share many hyperedges pull each other’s ranks together, and after a few rounds tightly co-occurring rows are adjacent. HAT-VIS runs ten iterations; hatvis uses the same default and stops earlier when the order no longer changes (algorithm 3.1). The method is fast, needs only the sparse co-occurrence matrix, and tends to produce a clean order inside the dominant group of rows, at the price of being sensitive to the initial order.
3.2.3 Correspondence analysis
Reciprocal averaging, iterated to convergence with continuous scores instead of ranks, converges to the first non-trivial axis of correspondence analysis [49]. Let , with row sums and column sums , and , . The singular value decomposition of the standardized residual matrix
|
| (3.4) |
gives row scores and column scores from the leading singular vectors; sorting by them yields simultaneous row and column orders. The scores solve a relaxation of the seriation problem in which the ranks are allowed to be real numbers, and they place a row at the weighted average of the columns it touches and a column at the weighted average of its rows, which is exactly the fixed point of (3.3). Correspondence analysis is the method of choice when the matrix has a single dominant gradient, such as the sequence of activities along a production line; when the matrix consists of several unrelated blocks, a single axis can only order them one after another and may interleave their members.
3.2.4 Hierarchical clustering with optimal leaf ordering
The third method clusters the rows (and separately the columns) hierarchically, here with the Jaccard distance between the 0/1 rows and average linkage, and reads the order off the leaves of the dendrogram. A dendrogram with leaves admits leaf orders, since the two children of every internal node can be swapped; Bar-Joseph, Gifford, and Jaakkola [50] gave a polynomial algorithm that finds the swap pattern minimizing the sum of distances between adjacent leaves. The result keeps every cluster contiguous at every level of the hierarchy, so blocks appear as nested rectangles, and it adapts well to matrices composed of several blocks of different shapes. Its weakness is the opposite of correspondence analysis: a global gradient may be broken at the boundaries of the clusters.
3.2.5 Biclusters
A seriated matrix suggests blocks; spectral co-clustering names them. Dhillon [51] treats the incidence matrix as the biadjacency matrix of the star expansion and looks for a partition of its vertices and hyperedges into groups that minimizes the normalized cut of the bipartite graph. The relaxed problem is solved by the singular vectors of the normalized matrix
|
| (3.5) |
the singular vectors with , rescaled by and , are stacked for rows and columns, and -means on the stacked embedding assigns every vertex and every hyperedge to one of co-clusters. Every co-cluster is a candidate bicluster; hatvis reports it with its density, the fraction of ones in its submatrix, and drops blocks below a chosen density. Because rows and columns are clustered together, a block of resources comes with the activities that use it, which is the form in which cells of a manufacturing system or topics of a document collection are needed. The same method reappears as a community detection method for vertices and hyperedges in eq. (7.3).
3.2.6 Set-oriented matrix views
Two further matrix layouts are designed for specific questions about sets.
UpSet. Lex et al. [52] replaced Venn and Euler diagrams of many sets by a matrix in which every column is a set intersection, drawn as a vertical line of dots over the participating sets, with a bar chart of the intersection sizes above and a bar chart of the set sizes on the side. Applied to a hypergraph, the natural reading is that every column is a distinct hyperedge (a combination of vertices) and the bar is its weight or multiplicity; the horizontal bars are the weighted vertex degrees. The view is ideal for frequent itemsets, where the question is which combinations occur and how often (chapter 8), and it scales to dozens of combinations where a Venn diagram fails beyond four sets.
PAOH. The Parallel Aggregated Ordered Hypergraph view of Valdivia et al. [53] draws vertices as horizontal lines and every hyperedge as a vertical segment with dots at its members. For a temporal hypergraph the columns are grouped by time stamp and the groups separated by gaps, so the evolution of the groups can be followed without any node-link clutter. The row order is again a seriation problem; hatvis uses the barycentric order of the aggregated hypergraph so that vertices that often appear together are adjacent in every period.
In a nutshell: Matrix views
- Seriation permutes rows and columns of the incidence matrix to reveal blocks and bands; quality: Moore stress (3.1) (lower is better) and bond energy (3.2) (higher is better). The exact problem is NP-hard.
- Barycentric (HAT-VIS): iterated co-occurrence-weighted averaging of ranks; fast, sparse, depends on the start.
- Correspondence analysis: first non-trivial singular vectors of (3.4); best for one dominant gradient.
- Hierarchical with optimal leaf ordering: nested contiguous clusters; best for several blocks.
- Spectral co-clustering (3.5) assigns vertices and hyperedges jointly to biclusters; report densities.
- UpSet: columns are combinations, bars their weights. PAOH: rows are vertices, columns hyperedges grouped by time.
3.3 Using it in hatvis
seriate(H, method="barycentric", weighted=False, n_iter=10)
- method
-
"barycentric" (HAT-VIS), "correspondence", "hierarchical" (optimal leaf ordering), or "none".
- Returns
-
two label lists: the vertex order and the hyperedge order.
- Related
-
seriation_quality(H, rows, cols) returns the Moore stress and the bond energy; bicluster_blocks(H, n_clusters, random_state, min_density) returns a list of blocks with nodes, edges, and density; the lower-level functions barycentric_order, correspondence_order, and hierarchical_order work on any matrix.
plot_incidence(H, order="barycentric", ax=None, transpose=False, biclusters=None, node_groups=None, labels=True)
- order
-
a seriation method name, a pair of label lists, or None for the stored order.
- transpose
-
hyperedges in rows (as in the figures of [4]).
- biclusters
-
the output of bicluster_blocks, drawn as dashed rectangles.
- node_groups
-
a node_data column whose values color the vertex labels.
- Related
-
plot_paoh(H, time=None, row_order="barycentric"), plot_upset(H, by="edges", max_bars=20), plot_similarity_matrix(S, order).
3.4 Examples
The wire-harness manufacturing space. Nagy et al. [4] model an intelligent collaborative manufacturing space as a hypergraph whose vertices are resources and whose hyperedges are activities. Their benchmark is a wire-harness assembly with two parallel production lines; each line takes wires from a Kanban storage through buffers to two crimping and two assembly stations, and an automated guided vehicle (AGV) transports the material between them. The thirty-one resources are seven operators –, six robots –, the AGV, four crimping machines –, two shared tools , three screwdrivers –, five competences , and three sensors –; the seventy activities – cover loading and unloading the AGV, manual handling, positioning crimps in vises and fixtures, crimping, assembly with robots and screwdrivers, and hand-overs between stations. The original incidence matrix is confidential. hatvis ships a reconstruction (load_wire_harness) with the same resources, the published activity sequence and types, and resource sets derived from the published process description; the results below have the same structure as those of the paper but are not its numbers.
Seriation. The script of fig. 3.2 orders the matrix with the three methods and evaluates each order.
quality = {} orders = {"original": (H.nodes, H.edges)} for method in ("barycentric", "correspondence", "hierarchical"): orders[method] = hv.seriate(H, method) for name, (rows, cols) in orders.items(): quality[name] = hv.seriation.seriation_quality(H, rows, cols) print(pd.DataFrame(quality).T)
| Order | Moore stress | Bond energy |
| original | 644 | 162 |
| barycentric (HAT-VIS) | 569 | 201 |
| correspondence analysis | 579 | 196 |
| hierarchical, optimal leaf order | 398 | 289 |
Table 3.1 and fig. 3.2 show the outcome. All three methods improve on the original order, in which the activities are listed by time and the resources by type, so that the operators of the two lines and the stations they serve are far apart. The barycentric and correspondence orders give similar values: both lay out a dominant gradient as a band and gather the transport activities, which share the AGV, at one end. Hierarchical clustering with optimal leaf ordering reduces the Moore stress by 38% and raises the bond energy by 78% relative to the original order. The reason is visible in the figure: the matrix consists of several nearly separate blocks (transport, crimping, assembly, and the per-line stations) of different shapes, which is the situation in which a nested, cluster-preserving order beats a single global axis.
Biclusters. Spectral co-clustering with six co-clusters, keeping the blocks of density at least 0.3, finds five biclusters.
blocks = hv.seriation.bicluster_blocks(H, n_clusters=6, random_state=0, min_density=0.3) for b in blocks: print(f"{len(b[’nodes’]):2d} resources x {len(b[’edges’]):2d} activities, density {b[’density’]:.2f}:", ", ".join(b["nodes"])) order = hv.seriate(H, "correspondence")
The densest block (0.86) joins the robot and the crimping machine with the seven activities of the second crimping station of line 1, from taking the wire out of the buffer to handing the crimped wire over to assembly; the second (density 0.83) is the transport cell, the operator , the AGV, the loading competence , and the sensor , with the twelve loading and unloading activities of the six AGV transports. A third, smaller block joins , , and the screwdriver with the five activities of the second assembly station of line 1. The two remaining blocks are larger and sparser: a crimping group of eight resources (operators, robots, and machines of the other crimping stations with the crimping competence and the machine-log sensor ) and an assembly group of fourteen resources. Figure 3.3 outlines the blocks on the correspondence-ordered matrix. The structure matches the reading of the paper: the AGV transport, the crimping stations, and the assembly stations are the modules of the system, and the less dense blocks are the places where resources are shared between stations or lines, the natural candidates for reorganization.
A dynamic hypergraph without clutter. The collection of news articles used in chapters 8 and 12 is synthetic, a stand-in for event data of the GDELT type [54]. Each article is a hyperedge whose vertices are its themes; there are twenty-four themes in six planted narratives (climate science, energy, finance, policy, impacts, and society, four themes each). An article mixes one or, with probability 0.4, two narratives, takes between two and four themes from each, and with probability 0.35 adds a random background theme. The popularity of the narratives changes over three periods (2021–2023): finance and loss-and-damage grow strongly, impacts and society grow more slowly, and energy declines. Figure 3.4 shows fourteen articles per period in the PAOH view.
ax = plot_paoh(T, time="time")
The barycentric row order places the themes of every narrative next to each other, so each article appears as one or two short vertical runs, and the periods can be compared at a glance: the climate-science, energy, and policy combinations dominate the first period, while articles that combine finance, aid, loss and damage, and developing countries become frequent in the last.
Frequent combinations. With 150 articles per period, the frequent theme combinations of size at least two are mined (chapter 8) and the eighteen most frequent are shown as an UpSet plot (fig. 3.5).
fi = hv.frequent_itemsets(T, min_support=0.06, min_size=2) IH = hv.itemset_hypergraph(fi.head(18)) fig, axes = plot_upset(IH, title="the 18 most frequent theme combinations")
The most frequent combinations are pairs from the climate-science narrative ( with support 0.18, with 0.17), followed by pairs from energy (, 0.16) and impacts (, 0.16). The dot matrix shows at once that almost all frequent combinations stay inside one narrative, the signature of the planted structure, whereas the vertex bars on the left show which themes take part in many combinations. Exactly this table is hard to read from a node-link drawing, where eighteen overlapping hyperedges on the same few vertices are indistinguishable.
3.5 Further reading
Liiv [44] traces the history of seriation from archaeology to bioinformatics, and Behrisch et al. [45] survey and compare matrix reordering algorithms for visualization; the R package seriation [48] implements many of them with a common interface and quality measures. Hill [49] explains the connection between reciprocal averaging and correspondence analysis. Spectral co-clustering is due to Dhillon [51]. UpSet [52] and PAOH [53] are described with extensive user studies in their original papers, and Alsallakh et al. [30] place them among the set visualization techniques.