Generative Models#
The generators
module provides functionality to generate common models of hypergraphs, both non-uniform and uniform.
[1]:
import random
import numpy as np
import xgi
Hypergraph generative models#
Uniform configuration model#
[2]:
n = 1000
m = 3
k = {i: random.randint(10, 30) for i in range(n)}
H = xgi.uniform_hypergraph_configuration_model(k, m)
/Users/lordgrilo/Dropbox (ISI Foundation)/development/xgi-local/xgi-repo/xgi/generators/uniform.py:61: UserWarning: This degree sequence is not realizable. Increasing the degree of random nodes so that it is.
warnings.warn(
Erdős–Rényi model#
[3]:
n = 1000
ps = [0.01, 0.001]
H = xgi.random_hypergraph(n, ps)
Non-uniform configuration model#
[4]:
n = 1000
k1 = {i: random.randint(10, 30) for i in range(n)}
k2 = {i: sorted(k1.values())[i] for i in range(n)}
H = xgi.chung_lu_hypergraph(k1, k2)
Non-uniform DCSBM hypergraph#
[5]:
n = 1000
k1 = {i: random.randint(1, 100) for i in range(n)}
k2 = {i: sorted(k1.values())[i] for i in range(n)}
g1 = {i: random.choice([0, 1]) for i in range(n)}
g2 = {i: random.choice([0, 1]) for i in range(n)}
omega = np.array([[100, 10], [10, 100]])
H = xgi.dcsbm_hypergraph(k1, k2, g1, g2, omega)
/Users/lordgrilo/Dropbox (ISI Foundation)/development/xgi-local/xgi-repo/xgi/generators/nonuniform.py:186: UserWarning: The sum of the degree sequence does not match the entries in the omega matrix
warnings.warn(
Simplicial Complex Generative Models#
Random simplicial complex model#
(from Iacopini et al. 2019)
Given \(n\) nodes and a vector of probabilities \(\vec{p} = [p_1, p_2, \ldots, p_{d}\)], where \(d\) is the maximal simplex dimension desired, the model creates simplices at each dimension with the corresponding probability (\(p_1\) for edges, \(p_2\) for 2-simplices, etc).
[6]:
n = 20
ps = [0.1, 0.2, 0.1]
SC = xgi.random_simplicial_complex(n, ps)
Random flag complex model in 2D#
The model creates an Erdos-Renyi network with \(n\) nodes and probability \(p\) for any pair of edges. It then promotes all 3-cliques to 2-simplices.
[7]:
n = 50
p = 0.1
SC = xgi.random_flag_complex_d2(n, p)
Generalized random flag complex model#
[8]:
n = 30
p = 0.2
SC = xgi.random_flag_complex(n, p, max_order=3)
Flag complex from graph#
It is also possible to construct flag (clique) complexes starting from an existing network. Of course, let’s show this using Zachary’s Karate club and including simplices up to te
[11]:
import networkx as nx
G = nx.karate_club_graph()
SC_KC = xgi.flag_complex(G, max_order=3)