Directed Measuresยถ
Definition
Directed hypergraphs distinguish source and target node sets for each hyperedge.
You will learn
Compute directed measures and compare in- vs out-structure effects.
Overviewยถ
Compute directed hypergraph measures and interpret in/out effects.
Compare directed vs undirected behavior on examples.
Setupยถ
[ ]:
import matplotlib as mpl
mpl.rcParams.update({
"figure.figsize": (6, 4),
"figure.dpi": 120,
"savefig.dpi": 150,
})
[1]:
import hypergraphx as hgx
[2]:
edges = [
((1,), (2,)), # Edge 1: Simple directed edge from 1 to 2
((2,), (1,)), # Edge 2: Simple directed edge from 2 to 1 (reciprocal with Edge 1)
((2, 3), (4,)), # Edge 2: Directed hyperedge with sources 2, 3 and target 4
((4,), (2, 3)), # Edge 3: Directed hyperedge from 4 to targets 2, 5
((5,), (1,)), # Edge 4: Directed edge from 5 to 1 (reciprocal with Edge 1)
((6,), (3, 4)), # Edge 5: Directed hyperedge from 6 to targets 3 and 4
((7,), (2, 6)), # Edge 6: Directed hyperedge from 7 to targets 2 and 6
((3, 8), (5,)), # Edge 7: Directed hyperedge with sources 3, 8 and target 5
((4, 5), (7, 8)) # Edge 8: Directed hyperedge with sources 4, 5 and targets 7, 8
]
[3]:
h = hgx.DirectedHypergraph(edges)
[4]:
from hypergraphx.measures.directed import in_degree, out_degree, in_degree_sequence, out_degree_sequence
[5]:
print("In-degree of node 1:", in_degree(h, 1))
print("In-degree of node 2:", in_degree(h, 2))
print("Out-degree of node 1:", out_degree(h, 1))
print("Out-degree of node 2:", out_degree(h, 2))
In-degree of node 1: 1
In-degree of node 2: 2
Out-degree of node 1: 2
Out-degree of node 2: 3
[6]:
print("In-degree sequence: ", in_degree_sequence(h))
print("Out-degree sequence: ", out_degree_sequence(h))
In-degree sequence: {1: 1, 2: 2, 3: 2, 4: 2, 5: 2, 6: 1, 7: 1, 8: 1}
Out-degree sequence: {1: 2, 2: 3, 3: 2, 4: 2, 5: 1, 6: 1, 7: 1, 8: 1}
[7]:
from hypergraphx.measures.directed import hyperedge_signature_vector
[8]:
v = hyperedge_signature_vector(h)
print("Hyperedge signature vector: ", v)
Hyperedge signature vector: [3. 3. 0. 2. 1. 0. 0. 0. 0.]
[9]:
from hypergraphx.measures.directed import exact_reciprocity, strong_reciprocity, weak_reciprocity
[10]:
print("Exact reciprocity: ", exact_reciprocity(h, max_hyperedge_size=4))
print("Strong reciprocity: ", strong_reciprocity(h, max_hyperedge_size=4))
print("Weak reciprocity: ", weak_reciprocity(h, max_hyperedge_size=4))
Exact reciprocity: {2: 0.6666666666666666, 3: 0.4, 4: 0.0}
Strong reciprocity: {2: 0.6666666666666666, 3: 0.4, 4: 0.0}
Weak reciprocity: {2: 0.6666666666666666, 3: 0.6, 4: 1.0}
[11]:
from hypergraphx.motifs.directed_motifs import *
[12]:
m = compute_directed_motifs(h, order=3, runs_config_model=0)
Computing observed motifs of order 3...
[13]:
m['observed']
[13]:
[((((1,), (2, 3)),), 2),
((((1,), (2, 3)), ((2, 3), (1,))), 1),
((((1, 2), (3,)),), 1)]