Constructing and sampling partite, 3-uniform hypergraphs with given degree sequence

Partite, 3-uniform hypergraphs are 3-uniform hypergraphs in which each hyperedge contains exactly one point from each of the 3 disjoint vertex classes. We consider the degree sequence problem of partite, 3-uniform hypergraphs, that is, to decide if such a hypergraph with prescribed degree sequences exists. We prove that this decision problem is NP-complete in general, and give a polynomial running time algorithm for third almost-regular degree sequences, that is, when each degree in one of the vertex classes is k or k − 1 for some fixed k, and there is no restriction for the other two vertex classes. We also consider the sampling problem, that is, to uniformly sample partite, 3-uniform hypergraphs with prescribed degree sequences. We propose a Parallel Tempering method, where the hypothetical energy of the hypergraphs measures the deviation from the prescribed degree sequence. The method has been implemented and tested on synthetic and real data. It can also be applied for χ2 testing of contingency tables. We have shown that this hypergraph-based χ2 test is more sensitive than the standard χ2 test. The extra sensitivity is especially advantageous on small data sets, where the proposed Parallel Tempering method shows promising performance.


Introduction
Degree sequence problems are one of the most intensively studied topics in algorithmic graph theory.The basic question is the following: given a sequence of non-negative integers, D := d 1 , d 2 , . . ., d n , is there a simple graph G = (V, E) with |V | = n such that for all i = 1, 2, . . ., n, the degree of vertex v i is d i ?Such a graph G is called a realization of D. In the middle of the previous century, Havel [22] and Hakimi [20] independently gave efficient algorithms that construct a simple graph with a given degree sequence or report that there is no simple graph with the prescribed degree sequence.The running time of these algorithms grows polynomially with n, the length of the degree sequence.Erdős and Gallai [11] gave inequalities that are necessary and sufficient to have a simple graph with a prescribed degree sequence.Gale [16] and Ryser [30] gave necessary and sufficient inequalities to have a bipartite graph with prescribed degree sequences of the two vertex classes.
Hypergraphs are generalizations of simple graphs.In a hypergraph H = (V, E), any hyperedge or simply edge e ∈ E is a non-empty subset of V .A hypergraph is k-uniform if each edge is a subset of vertices of size k.In this way, we can consider simple graphs as 2-uniform hypergraphs.For a long time, it was an open question whether or not efficient algorithms exist for hypergraph degree sequence problems.Recently, Deza et al. [8,9] proved that it is already NP-complete to decide if a 3-uniform hypergraph exists with a prescribed degree sequence.On the other hand, efficient algorithms have been developed for some special classes of degree sequences.These efficient algorithms can decide if a hypergraph realization exists when the degree sequences are very close to regular degree sequences [15,29].
Another intensively studied computational problem is to generate a random realization of a given degree sequence drawn from the uniform distribution.Above importance sampling [2,17], Markov chain Monte Carlo methods have been the standard approaches to generate random realizations of a prescribed degree sequence.A switch operation removes edges (v 1 , v 2 ) and (v 3 , v 4 ) and add edges (v 1 , v 4 ) and (v 2 , v 3 ).It is easy to see that a switch operation does not change the degree sequence, and any graph with a prescribed degree sequence can be transformed into another graph of the same prescribed degree sequence by a finite series of switch operations.The consequence is that a random walk applying random switches on the current realization of a prescribed degree sequence converges to the uniform distribution of all realizations, given that the probabilities of the random switches are set carefully.One easy way to appropriately adjust the probabilities of the switches is the Metropolis-Hastings algorithm [21,25].
Kannan, Tetali and Vempala [23] conjectured that the switch Markov chain is rapidly mixing for any degree sequence.The first rigorous proof was given by Cooper, Dyer and Greenhill [6] for regular degree sequences.The conjecture has been proved for larger and larger degree sequence classes; for a state-of-the-art, see [12].
Beyond its theoretical importance, sampling realizations of a prescribed degree sequence is used to generate background statistics of null hypotheses in hypothesis testing.Random 0-1 matrices with prescribed row and column sums (which are equivalent to random bipartite graphs with prescribed degree sequences) are generated to test competition in ecological systems [26].For other statistical testing of graphs, see [28].
Another family of combinatorial objects that are subject to statistical analysis are the contingency tables that can be considered as bipartite adjacency matrices of bipartite multigraphs.The standard statistical analysis on contingency tables is the χ 2 test.In the case of small entries, the theoretical χ 2 distribution might be far from the exact χ 2 distribution.In such cases, Fisher's exact test is used [1,14], that generates all possible contingency tables and computes their generalized hypergeometric probabilities (in Eq. 1).The p-value of the test is the sum of the generalized hypergeometric probabilities of the contingency tables whose probability is less than the tested contingency table.For large tables, the exact computation is not feasible, and Monte Carlo methods have to be used.In such a Monte Carlo method, a random contingency table with entries a i,j should be generated with probability where R i are the row sums, C j are the column sums and N is the total sum of the contingency table (see, for example, [1]).The Metropolis-Hastings algorithm can be used to generate random contingency tables following these prescribed probabilities.The Monte Carlo estimation to the p-value is the fraction of samples with generalized hypergeometric probability smaller than the generalized hypergeometric probability of the tested contingency table.
There are numerous cases when certain "agents" have different types of events during some time span and we are interested in the aggregation of such events.An example might be (patients, disease, time point) triplets, where the "agents" are the patients and having certain diseases are the possible events.We can ask if the different types of diseases are distributed evenly during time or whether some of the diseases are aggregated at certain time points.Another example might be (users, tweet types, time) triplets.The different tweet types might be characterized by their hashtags.We might ask if the hashtags are distributed evenly during time or if they are aggregated.These data types can be described with so-called partite, 3-uniform hypergraphs.Such hypergraphs have three vertex classes: agents, event types, and time points.The hyperedges are triangles such that the triangle has one-one point in each vertex class.There is a hyperedge incident to vertices a, b and c if agent a had an event of type b at time point c.
In such data sources, it might be an important factor that different agents have different total number of (event, time point) pairs, that is, they place different number of events to the event-time point table.For example, some people might be more healthy and being ill fewer times in a given time frame, while others might be ill more frequently.Similarly, some people are Twitter-addicts and post tweets frequently, while other users have considerably fewer tweets in a given time frame.Furthermore, the (event, time point) pairs coming from one agent are different entries in a table.On the other hand, based on the well-known birthday paradox, if more than square root of n elements are selected from an n-set with replacement, then with high probability there will be an element selected multiple times.Therefore, if agents place several items into the (event, time point) table, then the items will be more evenly distributed than independently distributing the same number of items.The consequence is that the χ 2 statistics will be shifted towards smaller values.
To consider the activity of the agents, an exact χ 2 test on the aggregation of event types should be obtained from uniformly sampling (agent, event type, time point) triplets such that each agent has the same activity as in the real data set, each event type is as frequent as in the real data set and each time point is as busy as in the real data set.That is, we need to generate random partite, 3-uniform hypergraphs with prescribed degree sequences.
This generation problem is hard in general.Indeed, as we show in this paper, it is already NP-complete to decide if a partite, 3-uniform hypergraph exists with a given degree sequence, and randomly generating one such a hypergraph does not seem to be an easier computational problem.However, we show in this paper that the decision and the construction problem is easy if one of the vertex classes is almost-regular, that is, each degree in that vertex class is either k or k − 1 for some k.We do not have to assume anything about the other two vertex classes, that is, the degrees in those two vertex classes might be arbitrary irregular.We call such a degree sequence third almost-regular.We also show that any realization of a third almost-regular degree sequence can be transformed into another one by a series of switch operations.We use this result in a Parallel Tempering Markov chain Monte Carlo method to generate random partite, 3-uniform hypergraphs with prescribed degree sequences.In that framework, the hypothetical energy of a hypergraph tells the deviation of a partite, 3-uniform hypergraph from the prescribed degree sequence, and the minimal energy is obtained when there is no deviation.The Parallel Tempering method cools down the Boltzmann distribution of the hypergraphs to the possible realizations of the prescribed degree sequence.At high temperature, hypergraphs with deviated degree sequences have a high probability in the Boltzmann distribution.Those deviated degree sequences contain the third almost-regular degree sequences, too, on which the switch operations are irreducible.We also give further analysis to the mixing properties of the proposed Markov chain Monte Carlo method.Although this approach is assumed to fail on some problem instances (extremely long time is needed to find a realization) due to the theoretical hardness of the problem, in practical data sets, its performance is acceptable.
We demonstrate the applicability of the method on simulated and real data, and we also show that it indeed provides a more sensitive χ 2 testing.

Realizing hypergraph degree sequences
Definition 1.A hypergraph H = (V, E) is a generalization of simple graphs.For all e ∈ E, e is a non-empty subset of V .A hyperedge e is incident with and for all e ∈ E and for all i = 1, 2, . . .t, |e ∩ V i | = 1, that is, each edge is incident with exactly one vertex in each vertex class.
The degree of a vertex of a hypergraph is the number of hyperedges incident with it.The degree sequence of a hypergraph is the sequence of the degrees of its vertices.If a hypergraph is partite t-uniform, then the degree sequence can be naturally broken down by the vertex classes, that is, it can be written as If D is a sequence of non-negative integers, we say that a hypergraph H = (V, E) is a realization of D, if the sequence of the degrees of the vertices of H is D. If D has a realization, then we say that D is graphic.
In this paper we consider partite 3-uniform hypergraphs, and for sake of simplicity, from now by "hypergraph" we mean partite 3-uniform hypergraphs.We are going to manipulate hypergraphs by switch operations that we describe below.Observe that the switch operation does not change the degrees of the vertices, that is, a switch operation creates another realization of the same degree sequence.We also introduce the following operations that do change the degree sequence.The central question is whether or not there is a hypergraph with a prescribed degree sequence.We will prove the following theorem claiming that this is a hard computational problem.be a hypergraph degree sequence.Then it is NP-complete to decide if D is graphic.
Theorem 4 follows almost verbatim from the argument of [8,9].We will reduce the so-called numerical 3-dimensional matching problem to the realization problem in Theorem 4. In the definition of the numerical 3-dimensional matching problem, we use the following notations.Let [n] denote the set {1, 2, . . ., n} that is naturally indexed by its elements.For a subset X ⊆ [n], we denote the vector from {0, 1} n containing 1 in the indices corresponding to elements of X and 0 elsewhere by 1 X .We denote the inner product of a row vector r and a column vector c by r • c.Vectors are column vectors by default, and row vectors are obtained by transposing column vectors.The transposition is denoted by T in the exponent of the column vector.
Definition 5 (Numerical 3-dimensional matching problem).Let A, B, C be a partition of [n] with |A| = |B| = |C| = k so that n = 3k.Let a ∈ Z n be a weight vector, and let b ∈ Z + 0 be a prescribed bound.Decide whether there exists a subset M ⊆ {0, 1} n such that , and In words, we are looking for a disjoint partitioning of [n] such that each partition contains exactly 1-1-1 element from A, B and C, and the sum of the weights of each member of the partition is b.Theorem 6 ([SP16] in [18]).The numerical 3-dimensional matching problem is NP-complete.
We are ready to prove our NP-completeness result.
Proof of Theorem 4. The partite 3-uniform hypergraph realization problem is contained in NP, because it is easy to check whether the degree sequence of a given hypergraph matches a prescribed degree sequence.
Let A, B, C be a partition of [n], and let a ∈ Z n and b ∈ Z + 0 define an instance of the numerical 3-dimensional matching problem.If an appropriate M exists, then The above equality is clearly necessary for the existence of a solution to the numerical 3-dimensional matching problem.If (2) does not hold, then we reduce the instance to a hypergraph degree sequence which is all zero except for one non-zero entry; it is not graphic as a 3-uniform hypergraph, so the answer to both instances is NO.
Suppose from now on that (2) holds.Let w := 3a − b1 [n] .Notice, that We are ready to define the degree sequence associated to an instance of the numerical 3-dimensional matching problem: To finish the proof, we will show that d(w) has a hypergraph realization which is 3-partite on classes A, B, and C if and only if the numerical 3-dimensional matching problem defined by a, b on A, B, C has a solution.Suppose, that M is a solution to the studied instance of the numerical 3-dimensional matching problem.Observe, that for any x ∈ M , we have , where thus if there is a solution to the numerical 3-dimensional matching problem, then d(w) is graphic.Suppose next, that the degree sequence of some hypergraph H is d(w).Using (3), we have Because H is 3-partite on classes A, B, C, we have 1 e ∈ S for any e ∈ E(H).Equality in (5) implies that w T 1 e ≥ 0 holds for every e ∈ E(H).Subsequently, any x ∈ S such that w T • x > 0 must be x = 1 e the characteristic vector of some edge e ∈ E(H).Let M (H) := {1 e | e ∈ E(H), w T • 1 e = 0}.For any x ∈ M (H), we have w T • x = 0, therefore: which completes the proof that M (H) a solution to the desired instance of the Numerical 3-dimensional matching problem.
On the other hand, in this paper, we also show that it is easy to decide whether or not some special degree sequences are graphic.We start with some definitions.
) be a hypergraph degree sequence.We say that D is third almost-regular, if for some k, Definition 8. Let H = (A, B, C, E) be a hypergraph, where A, B and C are the vertex classes.The (A, B)-projection of H is a bipartite multigraph G = (A, B, Ẽ), where the number of parallel edges between any (a i , b j ) is the number of c k vertices such that The (A, B)-projection is b-balanced if there exists an l such that for all a i ∈ A, the number of parallel edges between a i and b is either The trace of a B-balanced (A, B)-projection is a bipartite (simple) graph defined in the following way: In the adjacency matrix of the (A, B)-projection, in each column, we replace each l by 1 and each l − 1 by 0. The trace is the bipartite graph whose adjacency matrix is the so-obtained 0-1 matrix.
It is clear that the degree of (a i , b j ) in Ḡ is the number of parallel edges between a i and b j in G. Further, it is easy to see the following lemma.
where d(a i ) is the degree of a i in the hypergraph degree sequence D and n 2 is the length of D B , and for all j, Proof.The ⇒ direction: If D is graphic, let H be a realization of it, and let Ḡ be its (A, B)-shadow.Then the degree sequence of Ḡ satisfies the conditions, and since Ḡ is a realization of its own degree sequence, we have found a graphical degree sequence with the prescribed conditions.
The ⇐ direction: If there is a graphic degree sequence D = (D A×B , D C ), then let Ḡ be one of its realizations.We can think about Ḡ as an (A, B)-shadow of a hypergraph H. Constructing H is trivial: for each edge ((a i , b j ), c k ), we create hyperedge (a i , b j , c k ).It is easy to see that the so obtained hypergraph has degree sequence D, thus D is graphic.
Since B might not be an almost-regular vertex class, l might vary across the vertices of B in a B-balanced projection.Clearly, for each b j , the corresponding l and l − 1 is the ceiling and floor of the degree of b j in H divided by the size of A.
A bipartite multigraph G = (A, B, E) can be represented by its adjacency matrix, which is an |A| × |B| matrix M , and for all i = 1, 2, . . ., n 1 and j = 1, 2, . . ., n 2 m i,j is the number of multiedges between a i and b j .In this way, it is easy to see that an (A, B)-projection is B-balanced if each column of its adjacency matrix contains at most two different values that differ from each other by 1.Since A is the almost-regular vertex class, the row sums of the adjacency matrix of the projection are almost-regular, that is, each row sum is either k or k − 1 for some k.
The following is the key lemma for third almost-regular degree sequences.By finding an appropriate series of switch operations, we are going to construct a realization H ′ whose (A, B)-projection is b-balanced, and further, after removing the column corresponding to b in the adjacency matrix, the cropped adjacency matrix still has almost-regular row sums.Indeed, if such an H ′ exists, then the degree sequence of H ′′ := H ′ \ b is third almost-regular.By induction, there exists some H ′′′ which is (B \ {b})-balanced such that H ′′′ and H ′′ share their degree sequence.By construction, H ′′′ + {e ∈ H ′ | b ∈ e} will be a B-balanced realization of D. Regarding the claim of the lemma that any realization H can be transformed to a B-balanced realization H ′ with a finite series of switch operations, the removement of a column can be considered as "freezing" the corresponding hyperedges and considering the remaining subgraph. Let Then there is a unique solution how many l's are in column of the adjacency matrix of the (A, B)-projection corresponding to b such that this column is balanced.Let #k denote the number of rows in the adjacency matrix of the projection whose sum is k, and let #l denote the number of l's such that There are 3 sub-cases: 1. #l = #k.Then we will construct an H ′ such that in the adjacency matrix of its (A, B)-projection, exactly those entries will be l in the column corresponding to b whose row sum is k.Then after removing the column corresponding to b, we got a matrix in which each row sum is 2. #l < #k.Then we will construct an H ′ such that in the adjacency matrix of its (A, B)-projection, #l entries will be l in the column corresponding to b whose row sum is k, #k − #l entries will be l − 1 such that the corresponding row sum is k and all n 1 − #k entries whose corresponding row sum is k − 1 will get l − 1.After removing the column corresponding to b, #k − #l rows will have row sum That is, the row sums are still almost-regular.
3. #l > #k.Then we will construct an H ′ such that in the adjacency matrix of its (A, B)-projection, all #k entries whose row sum is k will be l in the column corresponding to b, #l − #k entries will be l such that the corresponding row sum is k − 1 and all n 1 − #l entries will be l − 1 such that the corresponding row sum is k − 1.After removing the column corresponding to b, #l − #k rows will have row sum k − 1 − l = k − l − 1, and n 1 − #l + #k rows will have row sum That is, the row sums are still almost-regular.
In the adjacency matrix of the (A, B)-projection of H, some of the entries in the column corresponding to b are not the values that are prescribed in the above list.We measure the deviation as the sum of the absolute values of the differences between the prescribed and the actual values.We are going to show that this deviation can be strictly monotonously decreased by switch operations.Particularly, while there is a wrong entry in the inferred column, we will be able to find a switch operation decreasing the deviation by 2.
Clearly, if there is an entry which is larger than prescribed, then there must be an entry that is smaller than prescribed.Indeed, during the switch operations, the degree of b does not change and in the adjacency matrix of the (A, B)-projection, the sum of the inferred column is fixed: it is the degree of b.We have the following cases when an entry is greater than prescribed: 1.In a row with sum k, there is an entry greater than l.Then the entry is at least l + 1 and the remaining row sum is at most k − l − 1.
2. In a row with sum k, there is an entry greater than l − 1.Then the entry is at least l and the remaining row sum is at most k − l.
3. In a row with sum k − 1, there is an entry greater than l.Then the entry is at least l + 1 and the remaining row sum is at most k − l − 2.
4. In a row with sum k − 1, there is an entry greater than l − 1.Then the entry is at least l and the remaining row sum is at most k − l − 1.
Further, we have the following cases when an entry is lower than prescribed: 1.In a row with sum k, there is an entry lower than l.Then the entry is at most l − 1, and the remaining row sum is at least k − l + 1.
2. In a row with sum k, there is an entry lower than l − 1.Then the entry is at most l − 2, and the remaining row sum is at least k − l + 2.
3. In a row with sum k − 1, there is an entry lower than l.Then the entry is at most l − 1, and the remaining row sum is at least k − l.
4. In a row with sum k − 1, there is an entry lower than l − 1.Then the entry is at most l − 2, and the remaining row sum is at least k − l + 1.
We can see that any of the possible combinations of to-be-decreased and to-be-increased entries, the entry to be decreased is strictly larger than the degree to be increased.Let the row index containing the entry to be decreased be i and let the row index containing the entry to be increased be i ′ .Then since there is no case with a prescribed entry l − 1 in a row with row sum k and the same time a prescribed entry l in a row with row sum k − 1, we can conclude that the remaining row sum in row i is strictly smaller than the remaining row sum in row i ′ .
Since the entry we would like to decrease is strictly larger than the entry we would like to increase, by pigeonhole principle it follows that there exists a c such that (a i , b, c) ∈ E(H) and (a i ′ , b, c) ̸ ∈ E(H).Since the remaining row sum in row i is strictly smaller than the remaining row sum in row i ′ , also by pigeonhole principle it follows that there exists a b ′ such that the in the (A, B)-projection of H, the number of parallel edges between a i ′ and b ′ is strictly greater than the number of parallel edges between a i and b ′ .Also by pigeonhole principle, there exists a c ′ such that (a i ′ , b ′ , c ′ ) ∈ H(E) and (a i , b ′ , c ′ ) ̸ ∈ E(H).Then we can switch a i and a i ′ in the hyperedges (a i , b, c) and (a i ′ , b ′ , c ′ ) to get the hyperedges (a i ′ , b, c) and (a i , b ′ , c ′ ).This switch operation decreases the deviation of the column corresponding to b.
Since the deviation of the column corresponding to b can be decreased by switch operation while this deviation is larger than 0, after finite number of switches, the column of b will be balanced.Further, by removing b from the hypergraph obtained from H by the above-described switches still has almost-regular degrees on its vertex class A, we can keep balancing vertices in the vertex class B till all vertices become balanced.Then we can add back the removed vertices in the vertex class B together with their hyperedges to obtain a B-balanced realization of the original degree sequence.
With this key lemma, we can prove the following theorem.) be a third almost-regular hypergraph degree sequence.Then there is a polynomial time algorithm that decides if D is graphic, and if it is graphic, the algorithm also constructs a realization of D.
Proof.First, we construct a bipartite multigraph G = (A, B, Ẽ) with degree sequence D A and D B .It is a triviality that the necessary and sufficient condition for a bipartite degree sequence to have a bipartite multigraph realization is that the degrees in D A and D B must have the same sum, and in case of having the same sum, constructing a bipartite multigraph is also a trivial task.Then we can make switch operations as described in the proof of Lemma 10 to obtain a B-balanced multigraph Ḡ.Now consider the bipartite degree sequence D = (D A×B , D C ), where D A×B contains the entries of the adjacency matrix of Ḡ.We claim that D has a hypergraph realization if and only if D is graphic.
Indeed, by Lemma 10, we also know that D has a hypergraph realization if it also has a B-balanced hypergraph realization H. Take the (A, B)-projection of H.We claim that the entries of the adjacency matrix of the (A, B)-projection is the same than the degree sequence D A×B of D. Indeed, as we discussed, the number of l's and l − 1's in each column in the adjacency matrix of a B-balanced realization is determined by the corresponding degree in D B .Now take the (A, B)-shadow of H. Its degree sequence is indeed D.
To prove the opposite direction, assume that D is graphic, and construct a realization of it, Ḡ = (A × B, C, Ē).Then construct a hypergraph H = (A, B, C) in which (a i , b j , c k ) ∈ E(H) if and only if ((a i , b j ), c k ) ∈ Ē( Ḡ).It is easy to see that H is a realization of D.
We can also prove that any realizations of a third almost-regular degree sequence can be transformed into any other realization of the same degree sequence by a series of switch operations.First, we prove that balanced realizations can be transformed into each other.
Lemma 12. Let H 1 and H 2 be two B-balanced hypergraph realizations of the third almost-regular degree sequence D. Then there exists a series of switch operations that transforms Proof.If the two realizations have the same (A, B)-projections, then their (A, B)-shadows have the same degree sequences.But (A, B)-shadows are bipartite graphs, further, bipartite graphs with the same degree sequences can be transformed into each other by switch operations [20,22].These switch operations can be lifted back to the hypergraph realizations.Indeed, if a switch in the (A, B)-shadow deletes edges ((a 1 , b 1 ), c Thus we only have to show that any B-balanced realization can be transformed into another B-balanced realization with a prescribed (A, B)-projection.Let M 1 and M 2 be two different B-balanced (A, B)-projections of two different hypergraphs H 1 and H 2 , and let their traces be G 1 and G 2 .It is easy to see that G 1 and G 2 are bipartite (simple) graphs with the same degree sequences.Indeed, the column sums of M 1 and M 2 are the same.Therefore, for each column c, the number of l's in column c in M 1 is the same that the number of l's in column c in M 2 .Further, the row sums in M 1 and M 2 are the same.Therefore, for each row r, the number of times row r contains column average ceiling (of the column in question) in M 1 is the same than the number of times r contains column average ceiling (of the column in question) in M 2 .
Bipartite graphs with the same degree sequences can be transformed into each other by switch operations, therefore the trace G 1 can be transformed into G  Finally, we show how to transform any realization of any degree sequence to any other realization of the same degree sequence.Theorem 14.Let D = (D A , D B , D C ) be a hypergraph degree sequence, and let H 1 and H 2 be two realizations of them.Then H 1 can be transformed into H 2 by a finite series of hinge-flip and switch operations.
Before we prove this theorem, we would like to remark that hinge-flips do not keep the degree sequence.However, theorem 14 is the key of the Parallel Tempering method that we will introduce in the next section. .Without loss of generality, we might assume that the degrees in D A are in non-increasing order.Let α be the average degree in D A and let k := ⌈α⌉.Further, let m be the number that satisfies the equation

Then let D ′
A be the degree sequence k, k . . ., k . We are going to show that both H 1 and H 2 can be transformed into realizations of D ′ := (D ′ A , D B , D C ) by hinge flips.This proof is constructive, and it should be clear that the construction proceeds on H 1 and H 2 in the same way.We show the construction for H 1 .Let D * := D and H * 1 = H 1 at the beginning of a series of transformations.Until D * is not equal to D ′ , we find hinge flips on H * 1 , which is a realization of D * that bring closer to a realization of D ′ .We measure the distance as the L 1 distance between D * and D ′ .
Having said these, let i be the largest index for which d * i − d ′ i > 0 and let j be the smallest index for which d * j − d ′ j < 0. It is easy to see that i exists if and only if j exists, and further, neither of them exists if and only if D * = D ′ .It is also easy to see that d * i > d * j for the degrees are non-increasing in D ′ .Then it follows that there exists b and c such that (a i , b, c) ∈ E(H * 1 ) and (a j , b, c) ̸ ∈ E(H * 1 ).Then a hinge flip that removes (a i , b, c) and adds (a j , b, c) leads to a hypergraph whose degree sequence is closer to D ′ in L 1 distance.Thus let the new H * 1 be the hypergraph obtained from the old H * 1 by this hinge flip, and adjust D * accordingly.Since the L 1 distance is decreased by each hinge flip, and the distance cannot be smaller than 0, in finite number of steps, D * will be D ′ and H * 1 will be a realization of D ′ .

Parallel Tempering
Markov chain Monte Carlo methods have been one of the most frequently used methods to generate random objects following a prescribed distribution.These objects are called states in the MCMC literature and the ensemble of the objects are called the state space.
The key is to find a primary Markov chain, that is, a random walk on the state space obeying some mild conditions.The conditions are that i) the random walk must be irreducible, that is, any state can be reached from any other state in finite number of steps with non-zero probability, ii) if there is non-zero probability to go to state y from state x in one step, then the probability of going to x from y in one step should be also non-zero, iii) the probability of going to x from y should be calculable and iv) the ratio of the probabilities of x and y in the prescribed distribution should be calculable.Any primary Markov chain satisfying these conditions can be tailored to a Markov chain that converges to the prescribed distribution by the Metropolis-Hastings algorithm [21,25].
In case of hypergraphs, the question of irreducibility is not trivial.Recall that switches are irreducible on realizations of simple and bipartite graph degree sequences.That is, let D be an arbitrary degree sequence of a simple (respectively bipartite) graph.Then any simple (respectively, bipartite) realization of D can be transformed into any another realization of D by a finite series of switch operations.It is unknown if a similar statement holds for general hypergraph degree sequences.The strong conjecture is that it does not hold.That is, there might exist a hypergraph degree sequence D such that some of the realizations of D cannot be switched into another realization of D by a finite number of switch operations.This could be a striking difference between graphs and hypergraphs.Indeed, not only is it well-known that switches are irreducible on graphs with an arbitrary degree sequence, but it is also conjectured that the switch Markov chain is rapidly mixing, which has already been proved for a large class of degree sequences [12].
If switches are not irreducible on hypergraph realizations of a degree sequence, then they alone cannot be used in a Markov chain Monte Carlo framework to uniformly sample realizations of a degree sequence.One possible way to avoid the question of irreducibility of the switches is to enlarge the space of the Markov chain and extend the possible random operations.Still, we would like to require that the random walk spend sufficient amount of time on realizations of the prescribed degree sequence.To achieve this, we introduce a Parallel Tempering framework [19].The Parallel Tempering method runs several parallel Markov chains, each of which converges to a Boltzmann distribution at a given (hypothetical) temperature based on the (hypothetical) energy of the elements of the state space.The chains regularly change their state with a prescribed probability.The central theorem of Parallel Tempering is that these random changes do not change the convergence of any of the chains.Still, these changes create a "tunneling effect": a state of the Markov chain with low temperature can jump from a local minimum to another local minimum.
In our approach, the hypothetical energy of a hypergraph measures the deviation of its degree sequence from a prescribed one.This causes that at near zero temperature, the Boltzmann distribution is frozen in the realizations of the prescribed degree sequence.The random perturbations of the Markov chains consist of a mixture of switch, hinge flip, toggle out and toggle in operations.At high temperature, the Markov chain can freely walk on arbitrary hypergraphs.By exchanging the states between parallel chains, a frozen state at a low temperature can jump from one local minimum to another local one.
In the next subsection, we give precise definitions of the Markov chain Monte Carlo approach. .

The Parallel Tempering Markov chain
Here ∝ means "proportional to".The exact probability of a particular hypergraph is .
The quantity Z is called partition function.Its computation is typically as hard as sampling from the corresponding Boltzmann distribution [24].In many applications, computing Z is not necessary since we are interested in only the ratios of probabilities.
Observe that Z is canceled in the ratio of the probabilities of two hypergraphs.Indeed, (See also Eq. 7, 8 and9.)We define a Markov chain on H(A, B, C).
Definition 16.Let D = (D A , D B , D C ) be a degree sequence, and let T > 0 be a real number.The Markov chain M T walks on the hypergraphs in H(A, B, C).If the current state is H t , then we define the next state with the following algorithm: 1.With probability 1 3 , we perform a 'switch' operation.We independently and uniformly choose two edges of the hypergraph e 1 , e 2 ∈ E(H t ), where e 1 = (a i , b i , c i ) and e 2 = (a j , b j , c j ), and uniformly choose one vertex set X ∈ {A, B, C}.For X = A (respectively X = B, X = C), we calculate new edges  1  3 , we perform a 'hinge-flip' operation.We uniformly choose an edge e ∈ E(H t ), uniformly choose a vertex set X ∈ {A, B, C}, and for this vertex set X, we uniformly choose a node x ∈ X, x / ∈ e.For X = A (respectively X = B, X = C), we calculate the new edge e ′ = (x, b, c) (respectively e ′ = (a, x, c), e ′ = (a, b, x)).If the new edge is not in the current hypergraph e ′ ̸ ∈ E(H t ), we replace the original edge with the new edge, that is, we take E(H ′ ) := E(H t ) ∪ {e ′ } \ {e}. 1  3 , we perform a 'toggle in/out' operation.We uniformly choose an arbitrary set of nodes (a, b, c).If this is an edge of the current hypergraph (a, b, c) ∈ E(H t ), we remove this edge ('toggle out'), that is, we take E(H ′ ) := E(H t ) \ {(a, b, c)}, Alternatively, if this is not an edge of the current hypergraph (a, b, c) ̸ ∈ E(H t ), we add a new edge corresponding to this set of nodes ('toggle in') that is, we take E(H ′ ) := E(H t ) ∪ {(a, b, c)}.

With probability
We apply the random operation on H t to get a hypergraph H ′ .Draw a random number u uniformly distributed on the [0, 1] interval.Then H t+1 is equal to and we set H t+1 to H t otherwise.
The Markov chain in definition 16 follows the rule of the Metropolis-Hastings algorithm [21,25], and therefore, this Markov chain converges to the Boltzmann distribution π T .Indeed, observe that for any H t and H ′ the probability that the algorithm we defined proposes H ′ from H t is exactly the probability of proposing H t from H ′ .In the Metropolis-Hastings algorithm, a state y proposed from state x is accepted if where π is the target distribution the Markov chain converge to and T (a|b) is the probability of proposing a from a state b.Here the proposal probabilities cancel, and the ratio of the probabilities of the states in the target distribution is exactly the fraction indicated (see also Eq. 6).
Although Theorem 14 guarantees that switches and hinge-flips already make the Markov chain irreducible, we add toggle in/out operations to the Markov chain as they guarantee rapid mixing at high temperatures.Indeed, the state space H(A, B, C) can be considered as the vertices of an |A| × |B| × |C| dimensional hypercube, where each coordinate of the vertices tells whether or not the corresponding hyperedge is in the hypergraph.Observe that at infinite temperature, the Boltzmann distribution is the uniform distribution on H(A, B, C).The toggle in/out operations can be considered as moves along the edges of the hypercube.It is well-known that a random walk along the edges of a hypercube converging to the uniform distribution of the vertices is rapidly mixing.That is, the toggle in/out operations alone make the random walk rapidly mixing in a chain with infinite temperature.Accommodating other operations (switches, hinge-flips) provides even better mixing.
Next, we define the Parallel Tempering.1.With probability 1 2 , draw a random i uniformly distributed on {1, 2, . . ., k}, and do a random step on the i th coordinate according to Markov chain M Ti .

With probability
then swap the current states H i and H i+1 in the Markov chains M Ti and M Ti+1 , otherwise do nothing.
Here we again use the cancellation of the partition functions of the Boltzmann distributions at temperatures T i and T i+1 .Since the construction of the Markov chain M follows the rule of the Parallel Tempering [19], the following theorem holds: that is, each coordinate is independent of the other coordinates and identical to the Boltzmann distribution on H(A, B, C) with the appropriate temperature.
In practice, the number of parallel chains as well as the temperatures of these parallel chains should be designed carefully.There are three basic rules that should be followed: 1.The zero energy states (here: the realizations of the prescribed degree sequence) should be a non-negligible part of the Boltzmann distribution at the lowest temperature.
2. The Boltzmann distribution should be close to the uniform distribution at the highest temperature 3. The acceptance probability of swapping states (that is, the probability that u is smaller than the fraction on the right-hand side of Eq. 9) should be relatively large.
equals the hypergraph-based exact χ 2 test with degree sequence D = (D A , D B , D C ), where D A is a sequence of 1s of length N .Indeed, for each possible contingency table T with entries t i,j and row and column sums D B and D C , there are exactly N t1,1,t1,2,...,t |D B |,|D C | hypergraph realizations of D with (B, C)-projection T .This observation indicates that the difference between the exact and hypergraph-based exact χ 2 tests is vanishing when each agent has degree 1, that is, places exactly one (event, time point) entry.We shall illustrate the effect of changing the degrees of the agents by considering degree sequences with fixed D B and D C and varying D A .We generated large (n = 2000) samples of random regular hypergraphs and obtained their empirical χ 2 distribution, see Fig. 1.These hypergraphs have n 1,i ∈ {3, 4, 5, 6, 10, 12, 15, 20, 30, 60, 600, 7200} nodes in vertex class A, n 2 = n 3 = 60 nodes in vertex classes B and C, and have 7200 hyperedges.That is, D B and D C are fixed to be 120-regular (60 times 120 makes 7200), and D A varies from 2400-regular to 1-regular.We find that having more agents (i.e. more vertices in vertex class A, thus having smaller degrees) leads to a higher mean aggregation of the null distribution (see Fig 1).The distribution of D A = 1 corresponds to the null distribution of the exact χ 2 test.Based on this example, one shall expect that the null distribution of the exact χ 2 test will have a higher mean than that of the hypergraph-based exact χ 2 test, and consequently be less sensitive in identifying hypergraph aggregation.In the next subsection, we shall find an illustrative case when the hypergraph-based exact χ 2 test shows significant aggregation that the exact and theoretical χ 2 tests cannot discern from no aggregation.

Application on Twitter data
We turn to real-world data, a COVID-19 vaccination-related Twitter data set collected during the first six months of 2021, used previously for vaccine skepticism detection [3] and sentiment analysis [4].There are 33K tweets in the data set that the authors collected by specifying vaccination-related keywords 1 to the public Twitter Search API.For each tweet, the following variables were recorded: their author (user ID), the author's categorization (healthcare professional, news media source, other accounts with thousands of followers), the vaccine mentioned, the language and the general sentiment 2 of the tweet (on a scale of 1 to 5 from negative to positive tone), and the date of publication (to the precision of seconds).When multiple vaccines are mentioned in a tweet, it is recorded as multiple tweets, one for each vaccine.
The Twitter data set provides the source for our study of hypergraph aggregation.We can construct hypergraphs from this data corresponding to each selection of three discrete variables that serve as the three vertex classes.Their unique values become the vertices, and then for each tweet, a hyperedge connects the respective vertices.Identical hyperedges are treated as a single hyperedge, not as multiedges.
In case study #1, we proceed with a natural choice: the three sets correspond to the author, the vaccine mentioned, and the date of publication (to the precision of a day).We found that the corresponding hypergraph is extremely aggregated (Fig 2).This result should not come as a surprise considering what no aggregation would mean: that each vaccine was mentioned in the same proportion of tweets on each day, i.e. irrespective of news selectively affecting vaccines (e.g.peaks after March 19: Scientists find a link to AstraZeneca rare blood clotting; March 31: Pfizer 100% efficacy for teenagers).Also, we found that this result is independent of the method.
In line with what we expect based on We report the design and the performance of the Parallel Tempering method for case study #2.Miklós and Tannier (Appendix B in [27]) gave a general design of how to set up parallel chains in Parallel Tempering.They used a quite weak but easy to compute upper bound on the acceptance probability of swapping states between the parallel chains based on the maximum possible difference between energies of the states.Their method could yield an extremely large prescribed number of parallel chains because here the maximum difference between the energies of states to be swapped is the sum of the degrees in the complete tripartite graph minus the sum of the given degrees, that is 3 case the acceptance probability is 1.That is, the acceptance probability between the chains must be at least 6.25% (in other cases, the swap between the two chains might be accepted with non-zero probabilities, too).The observed acceptance probabilities in the Parallel Tempering were at least 20% as shown in Fig. 5.With this protocol, we defined 64 temperatures.The hypergraphs with 0 energy (that is, realizations of the prescribed degree sequence) constituted more than 90% of the Boltzmann distribution at the coldest temperature.Fig. 6 shows the acceptance probabilities of the three types of operations in the individual Markov chains (switches, hinge-flips, toggles), as well as the probabilities to propose an invalid operation (that is, trying to add a hyperedge to a position where there is already a hyperedge).Observe that any valid switch operation is accepted with probability 1 since a switch operation does not change the energy of the state.Therefore the sum of the switch acceptance probability and the invalid switch probability is 1 at any temperature.Toggle in/out and hinge-flip operations change the energies of the current state.Since the probability of changing the energy towards a positive direction is higher than the probability of decreasing the energy, toggle in/outs and hinge-flips are accepted with small probabilities at low temperatures.However, at high temperatures the hinge-flip acceptance and the invalid hinge-flip probabilities sum to almost 1.The same holds for the toggle in/out acceptance and invalid toggle in/out probabilities.Therefore, these probabilities give evidences that the Boltzmann distribution of the warmest chain is close to an Erdős-Rényi distribution of hypergraphs with p = 0.5, that is, when each potential hyperedge is in the hypergraph with probability p = 0.5.Indeed, in such a case, there is 0.25 probability that neither of the proposed new hyperedges defined by a switch operation will be in the current hypergraph.This is in accordance with the cc.75% of probability that a proposed switch is invalid in the warmest chain.Similarly, if each hyperedge is in the hypergraph with 0.5 probability, then there is a 0.5 probability for a valid hinge flip, and thus the probability of an invalid hinge-flip is 50%.Note that the uniform distribution of all possible hypergraphs is the Erdős-Rényi distribution of hypergraphs with p = 0.5.A rough estimation of the expected energy at infinite temperature can be computed as the sum of the absolute differences between the prescribed degrees and half the maximal degrees.In case study #2, it is 3369.The lower and upper quartiles at the maximal temperature T = 148 were 3283 and 3390.This means that the warmest chain can be considered as essentially having infinite temperature, and thus, at that temperature the Markov chain is rapidly mixing.Further, this uniform distribution is cooled down to the distribution containing mainly the realizations of the prescribed degree sequence via largely overlapping Boltzmann distributions.Energies in the Boltzmann distribution were explored at 100 locations, regularly spaced along the logarithmic temperature axis, by independent Markov chains.The interpolation of their lower and upper quartiles, respectively, provides the orange and blue lines; some noise was removed from the lines to make them monotonic.The gray staircase line depicts the temperature selecting procedure: the lower quartile at temperature T i is equal to the upper quartile at temperature T i − 1. Black dots indicate the thus selected temperatures.See text for more details.
It took around 5 hours to generate 1854 samples of the prescribed degree sequence (using a custom Python script run on a single ca.3GHz processor).The program performed 201065 Markov chain Monte Carlo steps in the Parallel Tempering framework.The expected number of steps inside the coldest chain was set to switch each hyperedge once, in expectation, between two samples.The convergence of the Parallel Tempering was further confirmed by autocorrelation analysis and independent runs with a different starting position (data not shown).On the horizontal axis, we show the temperature of the warmer chain T i , i.e., the swap occurs between chains of temperatures T i−1 and T i .

Conclusions
Partite, 3-uniform hypergraphs naturally appear in data science, and frequently we are interested in the marginals of two dimensions of these hypergraphs.In such marginals, it is important to consider the third dimension, the "agents" that place the items in the contingency table.As we have shown in this paper, agents placing many items into the contingency table distribute the entries in the contingency table more evenly.This more balanced distribution causes a shift of the χ 2 distribution towards smaller values.Therefore, a hypergraph-based χ 2 test will be more sensitive than the theoretical χ 2 test that does not consider the effect of the agents.
The exact computation of the hypergraph-based χ 2 distribution is computationally infeasible as there might be a large number of possible hypergraphs with the prescribed degrees.Nevertheless, as we also showed in this paper, it is already NP-complete to decide if a partite, 3-uniform hypergraph exists with prescribed degrees.Therefore it is a natural attempt to develop a Monte Carlo method for computing the hypergraph-based χ 2 distribution.It needs random generation of partite, 3-uniform hypergraphs with prescribed degrees.We proposed a Parallel Tempering MCMC method, in which the hypothetical energy measures the deviation from the prescribed degree sequence.The transitions of the MCMC consist of switches, hinge-flips and toggle ins/outs, of which switches preserve the degree sequence while hinge-flips and toggle ins/outs do not.We prove a theorem that switches are irreducible on realizations of third almost-regular degree sequences that appear at high temperatures in the Parallel Tempering.We also showed that on small data sets, it is possible to heat the Boltzmann distribution up to the uniform distribution of possible hypergraphs.It is  easy to see that toggle ins/outs alone provide rapid mixing of this Boltzmann distribution, yet, it is possible to design a moderate number of parallel chains such that the Boltzmann distributions of consecutive chains have a significant overlap (expressed in large acceptance probabilities of swapping their states), and the realizations of the prescribed degree sequence dominate the Boltzmann distribution of the coldest chain.
The Parallel Tempering MCMC was tested on both synthetic and real data.We showed that the hypergraph-based χ 2 test is indeed more sensitive than the theoretical χ 2 test.This might be especially important when the scarcity of data reduces the power of the theoretical χ 2 test (i.e. its probability of correctly rejecting the null hypothesis).Although our theoretical results suggest that even the Parallel Tempering method becomes infeasible to run for some inputs, the performance of the method is reasonably good on small amounts of data -exactly when it is needed for more sensitive testing.
We see several potential improvements in the Parallel Tempering method; hereby we mention a few.The convergence of the Markov chain might be accelerated with a greedy start.Such a greedy start has already been successfully applied in a Monte Carlo method to sample binary contingency tables, that is, bipartite graphs, or, in yet other words, partite, 2-uniform hypergraphs [5].We opted to uniformly choose switches, hinge-flips and toggle ins/outs as transitions in the Markov chains.However, non-uniform distributions might cause higher acceptance probabilities in the Metropolis-Hastings algorithm and thus faster convergence.Indeed, at low temperatures, the hinge-flips and toggle ins/outs increasing the deviation from the prescribed degree sequence are accepted with a small probability and thus should be proposed only with a small probability.Also, appropriately setting the temperatures of the parallel chains as well as the number of parallel chains might improve the Parallel Tempering method.
There are also theoretical questions remaining.We proved that switches are irreducible on the realizations of third almost-regular degree sequences.We conjecture that the switches might be irreducible for a broader class of degree sequences.In an ongoing work, we are going to prove that the degree sequence realization problem is easy for partite 3-regular hypergraphs if the degree sequences are linearly bounded, that is, each degree in the i th vertex class is between some c 1 × n i+1 × n i+2 and c 2 × n i+1 × n i+2 for some 0 < c 1 < c 2 < 1, and the indexes in n j are modulo 3. We were not able to prove this so far, but conjecture that switches are irreducible on the realizations of such degree sequences.
The ultimate goal would be to identify degree sequence classes with rapidly mixing corresponding Markov chains on their realizations.Proving rapid mixing even for regular degree sequences is absolutely not obvious since it does not follow from the rapid mixing of Markov chains on bipartite graph realizations of regular degree sequences.Indeed, note that the (A, B)-projection (see Def. 8) might be regular or extremely irregular even in case of regular degree sequences.Further, the number of hypergraphs with different (A, B)-projections might vary in an unknown manner hindering the application of available proving techniques based on the decomposition of the state space [13].The Parallel Tempering method might help to identify easy-to-sample degree sequences.Indeed, for bipartite graphs, rapid mixing of a Simulated Annealing technique (a method quite similar to Parallel Tempering) is proved for arbitrary degree sequences [5], while the rapid mixing of the switch Markov chain is proved only for a large class of degree sequences [12].There are necessary and sufficient conditions when a Parallel Tempering is rapidly mixing that might be utilized here [31,32].
Hypergraphs will be denoted by H = (A, B, C, E), where A, B and C are the three disjoint vertex sets.Hypergraph degree sequences sometimes will be denoted by D = (D A , D B , D C ), where D A , D B and D C are the degree sequences of the vertex classes A, B and C, respectively.

Definition 2 .
A switch operation on a hypergraph H = (A, B, C, E) removes two hyperedges (a 1 , b 1 , c 1 ), (a 2 , b 2 , c 2 ) ∈ E(H) and creates two new hyperedges (a 2 , b 1 , c 1 ), (a 1 , b 2 , c 2 ).We require that neither (a 2 , b 1 , c 1 ) nor (a 1 , b 2 , c 2 ) be a hyperedge in H before the switch operation.We similarly define switch operations that swaps the vertices in the vertex class B or C.

Definition 3 .
A hinge flip operation on a hypergraph H = (A, B, C, E) removes a hyperedge (a, b, c) ∈ E(H) and adds a new hyperedge (a ′ , b, c).We require that (a ′ , b, c) be not a hyperedge in the hypergraph before the hinge flip operation.We similarly define hinge flip operations that move a vertex of a hyperedge in the vertex class B or C. A toggle out operation on a hypergraph H = (A, B, C, E) deletes a hyperedge (a, b, c).Its inverse operation is the toggle in operation that adds a hyperedge (a, b, c) to H.It is easy to see that a hinge flip removing a hyperedge (a, b, c) and adding a new hyperedge (a ′ , b, c) decreases the degree of a by 1 and increases the degree of a ′ by 1.A toggle out that removes hyperedge (a, b, c) decreases the degree of a, b and c by 1.A toggle in that adds hyperedge (a, b, c) increases the degree of a, b and c b 1.

Lemma 10 .
Let D = (D A , D B , D C ) be a third almost-regular degree sequence.If D has a realization H = (A, B, C, E) then D also has a realization H ′ whose (A, B)-projection is B-balanced.Furthermore, H ′ can be obtained from H by a series of switch operations.Proof.We will prove the statement by induction on the size of B. Let H = (A, B, C, E) be a realization of D. If B contains exactly one element, then H is third almost-regular precisely when the (A, B)-projection of H is B-balanced, thus the base case of the induction holds.Suppose that the induction hypothesis holds for degree sequences whose second vertex class has size |B| − 1.If the (A, B)-projection of H is B-balanced, then the induction step is trivial.Assume from now on, that the (A, B)-projection of H is not b-balanced for some b ∈ B.

2
by switch operations.Any switch operation in a trace has a corresponding switch operation in the B-balanced (A, B)-projection.Indeed, a switch operation in G 1 that deletes the vertices (a 1 , b 1 ) and (a 2 , b 2 ) and creates the vertices (a 2 , b 1 ) and (a 1 , b 2 ) has a corresponding switch operation in M 1 that decreases the number of parallel edges between a 1 and b 1 from b 1 -average ceiling (the l for the column of b 1 ) to b 1 -average flooring (the l − 1 for the column of b 1 ), decreases the parallel edges between a 2 and b 2 from b 2 -average ceiling to b 2 -average flooring, and increases the number of parallel edges between a 1 and b 1 from b 1 -flooring to b 1 -ceiling and increases the number of parallel edges between a 1 and b 2 from b 2 -average flooring to b 2 average ceiling.Due to the pigeonhole principle, there is a c 1 such that (a 1 , b

Definition 15 .
Let D = (D A , D B , D C ) be a prescribed hypergraph degree sequence on the vertex set A ∪ B ∪ C. Let d(a) (respectively, d(b), d(c)) denote the prescribed degree of the vertex a ∈ A (respectively, b ∈ B, c ∈ C).Let H = (A, B, C, E) be a hypergraph.Let the degree of a ∈ A (respectively, b ∈ B, c ∈ C) in H be denoted by d H (a) (respectively, d H (b), d H (c)).The energy of the hypergraph H = (A, B, C, E) is defined as ∆G(H) := a∈A |d(a) − d H (a)| + b∈B |d(b) − d H (b)| + c∈C |d(c) − d H (c)|. Let H(A, B, C) denote the set of all possible hypergraphs on the vertex set A ∪ B ∪ C. The Boltzmann distribution of H(A, B, C) at temperature T is denoted by π T .The probability of a particular hypergraph H in this distribution is π T (H) ∝ e −∆G(H) T H∈H(A,B,C) e −∆G(H) T

Definition 17 .
Let D = (D A , D B , D C ) be a degree sequence, and let 0 < T 1 < T 2 < . . .T k be real numbers.Let M T1 , M T2 , . . ., M T k be Markov chains defined in definition 16.The M Markov chain walks on H(A, B, C) × H(A, B, C) × . . .× H(A, B, C) (k times the Descartes product of H(A, B, C)), and a random step is defined by the following algorithm:

Fig 1 .
Fig 1.The aggregation index distribution of random regular hypergraphs with varying degrees of agents.The hypergraphs have fixed degree sequences D B and D C , both of them are 120-regular on 60 vertices.The degree sequence D A vary from d = 2400-regular to d = 1-regular on 120•60 d vertices.As the degree of the agents decreases the aggregation index increases on average.See text for more detail.

Fig 1 ,
we find in Fig 2 that hypergraph-based χ 2 values are shifted to the left compared to the exact and theoretical χ 2 values.To check whether this translates to the hypergraph-based χ 2 test being more sensitive in showing significant aggregation, we simulate having much fewer data to study.Case study #2 has n 1 = 4 authors, randomly chosen from the authors of case study #1 (1.5 percent), and only their tweets are kept.Here our expectation is confirmed: the hypergraph-based method shows significant aggregation still (p ≪ 0.05), but the exact and theoretical methods do not (p > 0.05) (Fig 3)

• 4 • 5 •Fig 2 .
Fig 2. Both the exact and the hypergraph-based exact χ 2 tests can identify strong aggregation.Case study #1.a) Hypergraph H (vertical line) corresponds to a data set of 33K tweets, incorporating their 22434 unique (author, vaccine, date) triplets as hyperedges.The dark green histogram shows a uniform distribution of hypergraphs of the same degree sequences as H; the corresponding test is the hypergraph-based exact χ 2 test.The light green histogram shows a uniform distribution of graphs with the same degree sequences as the (B, C)-projection of H; the corresponding test is the exact χ 2 test.The distribution of the theoretical χ 2 test (dashed blue line) closely follows that of the exact χ 2 test.Note that the horizontal axis is broken.b) The contingency table of the (B, C)-projection of H is also suggestive of aggregation: its patterns depart from what could be explained by its row and column means (top and right bars).

Fig 3 .
Fig 3.The sensitivity of the exact and the hypergraph-based exact χ 2 tests differ.Case study #2.Hypergraph H corresponds to the tweets of a small subset, 1.5%, of the authors of case study #1 (765 tweets, of which 517 are unique).H shows significant aggregation according to the hypergraph-based exact χ 2 test but not according to the exact χ 2 test.The three vertex classes A, B, C of the hypergraph correspond respectively to Twitter user, vaccine type, and day of the tweet.Panels a) and b) correspond to that of Fig 2. Panel c) shows a rearranging of the contingency table of panel b).

Fig 4 .
Fig 4. Temperatures selected for the Parallel Tempering of case study #2.Energies in the Boltzmann distribution were explored at 100 locations, regularly spaced along the logarithmic temperature axis, by independent Markov chains.The interpolation of their lower and upper quartiles, respectively, provides the orange and blue lines; some noise was removed from the lines to make them monotonic.The gray staircase line depicts the temperature selecting procedure: the lower quartile at temperature T i is equal to the upper quartile at temperature T i − 1. Black dots indicate the thus selected temperatures.See text for more details.

Fig 5 .
Fig 5.  Acceptance probabilities of swapping the states of neighboring chains in the Parallel Tempering of case study #2.On the horizontal axis, we show the temperature of the warmer chain T i , i.e., the swap occurs between chains of temperatures T i−1 and T i .

Fig 6 .
Fig 6.Acceptance of intrachain operations in the Parallel Tempering of case study #2.Acceptance probabilities consist of the probability of proposing a valid operation multiplied by the probability of accepting it."Invalid" denotes the probability of proposing an invalid operation.
1 , c 1 ) is a hyperedge in H 1 and (a 2 , b 1 , c 1 ) is not a hyperedge in H 1 .Similarly, due to pigeonhole principle, there is a c 2 such that (a 2 , b 2 , c 1 ) is a hyperedge and (a 1 , b 2 , c 2 ) is not a hyperedge in H 1 .Therefore each switch operation in G 1 has at least one switch operation in H 1 .In this way, when a trace G 1 is transformed into G 2 with switch operations, the corresponding hypergraph H 1 is transformed into another hypergraph H ′ 1 that has trace G 2 .Then H ′ 1 has the same (A, B)-projection as H 2 .As we discussed, H ′ 1 can be transformed into H 2 by switch operations.′ 1 by switch operations.Also, we can transform H 2 into a B-balanced realization H ′ 2 by switch operations.Due to lemma 12, H ′ 1 can be transformed into H ′ 2 by switch operations.Thus, H 1 can be transformed into H ′ 2 by switch operations.Since the inverse of a switch operation is also a switch operation, H ′ 2 can be transformed into H 2 by switch operations, and thus, H 1 can be transformed into H 2 by switch operations.
13eorem13.Let H 1 and H 2 be two hypergraph realizations of the same third almost-regular degree sequence D. Then there exists a finite series of switches that transforms H 1 into H 2 .Proof.Based on lemma 10, we can transform H 1 into a B-balanced realization H Theorem 14.It is enough to show that both H 1 and H 2 can be transformed into realizations of the same third almost-regular degree sequence.Indeed, let H ′ 1 and H ′ 2 be two realizations of a third almost-regular degree sequence.Then H ′ 1 can be transformed into H ′ 2 by switch operations.Therefore if H 1 can be transformed into H ′ 1 and H 2 can be transformed into H ′ 2 by hinge flips, then H 1 can be transformed into H 2 by hinge flips and switches.Indeed, the inverses of hinge flips are also hinge flips, therefore H ′ 2 can be transformed into H 2 by hinge flips, thus H 1 can be transformed into H 2 by hinge flips and switches via H ′ 1 and H ′ 2 none of these new edges are in the current hypergraph e ′ 1 , e ′ 2 ̸ ∈ E(H t ), we replace the original edges with them, that is, we take E(H ′