Hypergraph Analysis and Visualization in PythonThe hatvis toolbox

Chapter 11
Dynamics and learning

A hypergraph is often the substrate of a process: opinions are averaged in groups, infections and innovations spread through teams and households, and labels propagate from a few known vertices to the rest. This chapter shows how the group structure changes such processes. Linear diffusion and consensus can be written with the Laplacians of chapter 2 and are equivalent to processes on a weighted graph; nonlinear group consensus and threshold contagion are not, and produce effects without a pairwise counterpart, such as accelerated or delayed agreement and an abrupt, seed-dependent transition to a spreading state. The second half treats learning on hypergraphs: label spreading, a simplified hypergraph neural network, and the prediction of missing hyperedges.

11.1 Problem and idea

A process on a network is defined by how the state of a node changes as a function of the states of its neighbors. In a pairwise model the influence of a neighbor does not depend on the other neighbors: an infected contact transmits with the same probability whether or not the other members of the household are infected, and the pull of a friend’s opinion is the same whether or not the friend agrees with the rest of the group. Many social, biological, and technical processes violate this assumption. People adopt a behavior when a sufficient fraction of a group has adopted it; a group with a coherent opinion is more persuasive than a divided one; a reaction proceeds only when all reactants are present. The interaction is a function of the whole group.

The idea of this chapter is to separate the two cases precisely (fig. 11.1). When the influence of a group is a sum of pairwise influences, the hypergraph process is a graph process on a suitably weighted clique expansion, and the tools of chapter 2 (Laplacians and their spectra) describe it completely. When the influence depends nonlinearly on the joint state of the group, the process is genuinely higher-order and must be simulated or analyzed on the hypergraph itself [11, 12]. The same distinction applies to learning: a classifier that smooths labels over the clique expansion uses the hypergraph only through pairwise similarities, while edge-dependent weights and nonlinear aggregations use the groups.

Figure 11.1

Figure 11.1. Pairwise and group-threshold transmission to a susceptible vertex i in a group of four. In the pairwise model every infected contact transmits independently; in the threshold model the group transmits only when a sufficient fraction 𝜃 of the other members is infected. With 𝜃 = 1 (simplicial contagion) the group above would not transmit, because one other member is susceptible.

11.2 Theory

11.2.1 Linear diffusion and consensus

Let xi(t) be the state of vertex i (an opinion, a concentration, a temperature). In linear averaging dynamics every vertex moves toward the mean of each of its hyperedges, weighted as in the random walk of (6.4):

x˙ = −Lrwx = − (I −Dv−1BWD e−1BT )x.
(11.1)

The solution is x(t) = e−tLrwx(0), which hatvis evaluates with the action of the matrix exponential on a vector [142] without forming the exponential. On a connected hypergraph all states converge to a common value, the average πTx(0) weighted by the stationary distribution of the walk (πi ∝di), and the rate of convergence is the smallest non-zero eigenvalue of Lrw, the algebraic connectivity of section 2.2.5. With Bolla’s Laplacian (2.6) the dynamics conserve the total ∑ ⁡ ixi instead and describe the diffusion of a quantity. Because BWDe−1BT is the adjacency of a weighted clique expansion (with self-loops), both are graph processes in disguise: the hypergraph enters only through the weights ∑ ⁡ e∋i,jwe∕|e| of the pairs.

11.2.2 Nonlinear group consensus

Neuhäuser, Mellor, and Lambiotte [143] showed that consensus dynamics become genuinely higher-order when the influence of a group on a member depends on the agreement of the other members. In their three-body model the pull exerted by a pair of neighbors is modulated by a function of their opinion difference. hatvis implements a generalization to hyperedges of any size,

ẋi = ∑ e∋iwe exp ⁡ (λσe∖i ) (x¯e∖i −xi ),
(11.2)

where x¯e∖i and σe∖i are the mean and the standard deviation of the opinions of the other members of e. For λ = 0 the model is linear consensus on the clique expansion with pair weights we∕(|e|−1). For λ < 0 a coherent group (small σ) exerts more influence than a divided one, a form of peer pressure; for λ > 0 divided groups pull harder. The model is integrated with the explicit Euler method. Neuhäuser et al. showed for the three-body case that such nonlinearities can speed up or slow down the approach to consensus and shift the final consensus value away from the linear average, depending on the initial distribution of opinions and on the structure of the groups.

11.2.3 Threshold contagion

In a discrete-time susceptible–infected–susceptible (SIS) process, every infected vertex recovers with probability μ in each step, and susceptible vertices become infected through their contacts. de Arruda, Petri, and Moreno [144] proposed a threshold rule for hypergraphs: a hyperedge e can transmit to a susceptible member i only if at least a fraction 𝜃 of the other members of e are infected, and then it transmits with probability β. With 𝜃 = 1 a group transmits only when all other members are infected, the rule of the simplicial contagion model of Iacopini et al. [145]; small 𝜃 approaches pairwise spreading. The stationary prevalence ρ∗ as a function of β distinguishes the two regimes:

Iacopini et al. derived this behavior in a mean-field approximation for simplicial complexes, and de Arruda et al. for threshold models on hypergraphs; it means that the outcome of an intervention can depend on the initial condition, not only on the parameters, and that a small increase of transmissibility can cause a sudden jump in prevalence. Mancastroppa et al. [93] showed that such processes localize in the hyper-cores of section 6.2.6.

11.2.4 Semi-supervised learning

When the classes of a few vertices are known, the others can be classified by assuming that vertices in the same hyperedges tend to have the same class. Zhou, Huang, and Schölkopf [35] extended the label spreading of Zhou et al. [146] to hypergraphs. With the propagation operator Θ = Dv−1∕2BWDe−1BTDv−1∕2 and the indicator matrix Y ∈{0,1}n×c of the known labels, the class scores

F = (1 −α)(I −αΘ)−1Y
(11.3)

minimize a smoothness term ∑ ⁡ ewe |e|∑ i,j∈e ‖fi∕di −fj∕dj‖ 2 plus a fit term 1−α α ‖F −Y‖2, and every vertex is assigned to the class of its largest score. The scores of a class grow with the number of its labeled vertices, so an unbalanced labeled set biases the prediction toward the larger class. Zhu, Ghahramani, and Lafferty [147] proposed class mass normalization to correct for this: each column of F is rescaled to a prescribed class mass before the maximum is taken. hatvis offers the normalization with uniform class priors as an option.

Hypergraph neural networks [25, 148] stack layers X(l+1) = φ (ΘX(l)Ψ(l) ) of propagation with Θ (with self-loops), a learned linear map Ψ(l), and a nonlinearity φ. Wu et al. [149] showed for graphs that much of the accuracy of such networks is retained when the nonlinearities between layers are dropped: the features are propagated K times, ΘKX, and a single linear classifier is trained. hatvis implements this simplified HGNN with multinomial logistic regression on standardized propagated features; it needs no deep-learning framework and serves as a strong baseline. Surveys of hypergraph neural networks and representation learning are given by Kim et al. [150] and Antelmi et al. [151].

11.2.5 Hyperedge prediction

Hyperedge prediction asks whether a candidate set of vertices is likely to form a group [152, 153]. hatvis evaluates simple, interpretable scores of a candidate S: the mean Jaccard similarity of the members’ hyperedge sets, the smallest number of hyperedges shared by a pair of members, and the mean Adamic–Adar index [154] of the member pairs on the clique expansion. To measure predictability, a fraction of the hyperedges is hidden, the scores are computed on the rest, and the hidden hyperedges (positives) are compared with random vertex sets of the same sizes (negatives) by the area under the ROC curve (AUC) and the average precision. Benson et al. [152] showed that groups in temporal data often close over pairs that have already interacted, so that pairwise co-occurrence is a strong predictor; Yadati et al. [153] learn the scores with neural networks.

In a nutshell: Dynamics and learning

  • Linear diffusion and consensus (11.1) are graph processes on a weighted clique expansion; consensus value πTx(0), rate given by the algebraic connectivity.
  • Nonlinear group consensus (11.2): the pull of a group depends on the agreement of its other members; λ < 0 peer pressure, λ > 0 the reverse.
  • Threshold SIS contagion: a group transmits only if a fraction 𝜃 of the other members is infected; 𝜃 = 1 is simplicial contagion; discontinuous, bistable transitions with hysteresis.
  • Label spreading (11.3) with optional class mass normalization; simplified HGNN (ΘKX + logistic regression).
  • Hyperedge prediction: Jaccard, co-occurrence, and Adamic–Adar scores; AUC and average precision against size-matched random sets.

11.3 Using it in hatvis

dynamics.threshold_contagion(H, beta, mu, theta=0.5, initial=0.05, n_steps=100, n_runs=1, random_state=None)

theta

fraction of the other members that must be infected for a hyperedge to transmit.

initial

fraction of initially infected vertices or a list of seed vertices.

Returns

the prevalence per step for every run (a DataFrame).

Related

dynamics.diffusion(H, x0, times, kind), dynamics.group_consensus(H, x0, t_max, dt, lam), dynamics.random_walk_trajectory; learning.label_spreading(H, labels, alpha, class_mass_normalization), learning.hgnn_features, learning.hgnn_classifier(H, X, labels, n_layers), learning.propagation_operator, learning.hyperedge_score, learning.hyperedge_prediction(H, test_fraction, method, negative).

11.4 Examples

Diffusion and group consensus. A planted-partition hypergraph with 60 vertices in three communities and 120 hyperedges of three or four members (pin = 0.85) carries random initial opinions in [0,1].

lin = hv.dynamics.diffusion(H, x0, np.linspace(0, 15, 61)) 
runs = {lam: hv.dynamics.group_consensus(H, x0, t_max=3, dt=0.005, lam=lam) for lam in (-10.0, 0.0, 10.0)}
   

Under linear diffusion all opinions converge to a common value, the degree-weighted average of the initial opinions (fig. 11.2, left). The right panel compares the decay of the spread of opinions in the nonlinear model (11.2) for three values of λ. With λ = +10 the spread first falls fastest, because the initially divided groups pull strongly, but the decay then slows down; with λ = −10 the decay starts slowly, because divided groups have little influence while opinions are diverse, and accelerates as the groups become coherent. At t = 3 the spread is 0.0043 for λ = −10, 0.0051 for the linear model, and 0.0072 for λ = +10. The same hypergraph and the same initial condition thus give a different time course of agreement depending only on how groups aggregate the opinions of their members, an effect that no reweighting of pairs can reproduce.

Figure 11.2

Figure 11.2. Left: linear diffusion of opinions on a planted-partition hypergraph (colors: communities). Right: standard deviation of the opinions over time in the nonlinear group consensus model for λ = −10, 0, and + 10.

Open in ColabExample plot_35_diffusion_consensus.py in the gallery

Threshold contagion. A random hypergraph with 150 vertices, 500 hyperedges of size three, and 150 of size two carries an SIS process with recovery probability μ = 0.2, for a range of transmission probabilities β, two thresholds, and two initial seeds (5% and 40% of the vertices).

            run = hv.dynamics.threshold_contagion(H, beta=b, mu=0.2, theta=theta, initial=init, n_steps=120, 
                                                  n_runs=3, random_state=0) 
            
   

With 𝜃 = 0.5 a group of three transmits as soon as one of the two other members is infected, the process behaves like pairwise spreading, and the stationary prevalence is the same for both seeds at every β (0.43 already at β = 0.02, rising smoothly to 0.83). With 𝜃 = 1 a group of three transmits only when both other members are infected. At β ≈0.06 the infection dies out from the 5% seed but reaches a prevalence of 0.42 from the 40% seed; at β ≈0.10 the two seeds give 0.48 and 0.71 (fig. 11.3). The region of bistability is the hysteresis predicted for simplicial and threshold contagion [144, 145]: whether a behavior spreads depends on how many adopt it initially, not only on how contagious it is.

Figure 11.3

Figure 11.3. Stationary prevalence of threshold SIS contagion as a function of the transmission probability per group, for thresholds 𝜃 = 0.5 (blue) and 𝜃 = 1 (orange) and initial seeds of 5% (solid) and 40% (dashed).

Open in ColabExample plot_36_contagion.py in the gallery

Learning from few labels. A planted-partition hypergraph with 150 vertices in three classes and 400 hyperedges of two to four members (pin = 0.75) is classified from a random fraction of labeled vertices, five repetitions per fraction, with label spreading, label spreading with class mass normalization, and the simplified HGNN with identity input features.

        pred_ls = hv.learning.label_spreading(H, lab, alpha=0.9).idxmax(axis=1) 
        pred_cm = hv.learning.label_spreading(H, lab, alpha=0.9, class_mass_normalization=True).idxmax(axis=1) 
        pred_hg = hv.learning.hgnn_classifier(H, np.eye(H.n_nodes), lab, n_layers=2).astype(float) 
        
   

Table 11.1. Mean accuracy of semi-supervised classification on a planted-partition hypergraph against the fraction of labeled vertices (five repetitions).
labeled label spreading
label spreading,
class mass norm.
simplified HGNN
2% 0.778 0.929 0.669
5% 0.836 0.927 0.851
10% 0.713 0.965 0.911
20% 0.912 0.971 0.976
40% 0.975 0.989 0.991

Table 11.1 and fig. 11.4 show that plain label spreading is unstable: its accuracy drops to 0.713 at 10% labels. The drop comes from unbalanced labeled sets; in one repetition nine vertices of one class and three of each of the others were labeled, and label spreading assigned 130 of the 150 vertices to the overrepresented class. Class mass normalization removes the bias and gives the best accuracy at low label rates (0.93 with 2% labels, i.e. three or four labeled vertices). The simplified HGNN needs more labels, because its logistic regression has to be trained on the labeled vertices, but it is the most accurate from 20% on (0.976 and 0.991).

Figure 11.4

Figure 11.4. Accuracy of label spreading, label spreading with class mass normalization, and the simplified HGNN against the fraction of labeled vertices (logarithmic axis).

Open in ColabExample plot_37_learning.py in the gallery

Predicting hyperedges. Twenty percent of the hyperedges of the same hypergraph are hidden and scored against size-matched random vertex sets.

pred = pd.DataFrame({m: hv.learning.hyperedge_prediction(H, method=m, random_state=0) 
                     for m in ("mean_jaccard", "min_cooccurrence", "adamic_adar")}).T
   

The Adamic–Adar score reaches an AUC of 0.655, the mean Jaccard score 0.593, and the minimum co-occurrence 0.525, barely above chance. The planted partition has a weak signal for hyperedge prediction: a hidden hyperedge is internal to a community with probability 0.75, but a random set of two to four of 150 vertices is often internal to one of three communities as well. Scores based on shared neighbors (Adamic–Adar) capture the community signal best; the minimum co-occurrence is too strict, since in a sparse hypergraph most member pairs of a hidden hyperedge never met elsewhere.

11.5 Further reading

Battiston et al. [11] review dynamics on higher-order networks, including diffusion, synchronization, contagion, and evolutionary games. Neuhäuser et al. [143] analyze nonlinear consensus, Iacopini et al. [145] simplicial contagion, and de Arruda et al. [144] threshold contagion on hypergraphs; Lucas et al. [41] treat synchronization with a multiorder Laplacian. Zhou et al. [35] introduce spectral learning on hypergraphs; Feng et al. [148] and Gao et al. [25] hypergraph neural networks; Kim et al. [150] and Antelmi et al. [151] survey the field. Benson et al. [152] study simplicial closure and higher-order link prediction.