Stats Cheat Sheet#
Quick reference for XGI’s statistics interface. For a full tutorial, see Statistics.
Accessing stats#
Stats are accessed through the nodes and edges views:
import xgi
H = xgi.Hypergraph([[1, 2, 3], [2, 3, 4, 5], [3, 4, 5]])
H.nodes.degree # NodeStat object
H.edges.order # EdgeStat object
Output formats#
Every stat object supports the same output methods:
Method |
Returns |
|---|---|
|
|
|
|
|
NumPy array |
|
Pandas Series |
Summary statistics#
Method |
Description |
|---|---|
|
Maximum / minimum value |
|
Central tendency |
|
Spread |
|
Total |
|
Statistical moments |
|
ID of the max / min |
|
IDs sorted by value |
|
Unique values |
|
Histogram as DataFrame |
Available node statistics#
Stat |
Example |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Available edge statistics#
Stat |
Example |
|---|---|
|
|
|
|
|
|
|
|
Directed hypergraph statistics#
Nodes: degree, in_degree, out_degree
Edges: order, size, head_order, head_size, tail_order, tail_size
Passing arguments#
Some stats accept arguments. Call the stat to pass them:
H.nodes.degree # all orders
H.nodes.degree(order=2) # only order-2 edges
H.edges.order(degree=3) # only nodes with degree 3
Filtering#
Filter nodes or edges by any statistic:
H.nodes.filterby('degree', 2) # degree == 2
H.nodes.filterby('degree', 2, mode='gt') # degree > 2
H.nodes.filterby('degree', (2, 5), mode='between') # 2 <= degree <= 5
H.edges.filterby('order', 1, mode='leq') # order <= 1
Available modes: eq, neq, lt, gt, leq, geq, between.
Filter by attributes:
H.nodes.filterby_attr('color', 'red')
H.nodes.filterby_attr('age', 18, mode='geq')
Multiple statistics#
Combine multiple stats into a single DataFrame:
H.nodes.multi(['degree', 'clustering_coefficient']).aspandas()
Custom statistics#
Define your own stats with decorators:
@xgi.nodestat_func
def my_stat(net, bunch):
return {n: net.degree(n) ** 2 for n in bunch}
H.nodes.my_stat.asdict() # works like any built-in stat
Using stats with visualization#
Pass stat objects directly to drawing functions:
xgi.draw(H, node_fc=H.nodes.degree, node_size=H.nodes.degree)
xgi.draw(H, edge_fc=H.edges.order)