stats package

Statistics of networks, their nodes, and edges.

Any mapping that assigns some quantity to each node of a network is considered a node statistic. For example, the degree is a node-integer mapping, while a node attribute that assigns a string label to each node is a node-string mapping. The stats package provides a common interface to all such mappings.

Each such mapping is accessible via the H.nodes view. For example, the degree of all nodes supports type conversion using the as* methods.

>>> import xgi
>>> H = xgi.Hypergraph([[1, 2, 3], [2, 3, 4, 5], [3, 4, 5]])
>>> H.nodes.degree.asdict()
{1: 1, 2: 2, 3: 3, 4: 2, 5: 2}
>>> H.nodes.degree.aslist()
[1, 2, 3, 2, 2]

Another feature is the ability to filter the nodes of a network by degree.

>>> H.nodes.filterby('degree', 2)
NodeView((2, 4, 5))

The power of the stats package is that any other node statistic that can be conceived of as a node-quantity mapping is given the same interface. For example, node attributes get the same treatment:

>>> H.add_nodes_from([
...     (1, {"color": "red", "name": "horse"}),
...     (2, {"color": "blue", "name": "pony"}),
...     (3, {"color": "yellow", "name": "zebra"}),
...     (4, {"color": "red", "name": "orangutan", "age": 20}),
...     (5, {"color": "blue", "name": "fish", "age": 2}),
... ])
>>> H.nodes.attrs('color').asdict()
{1: 'red', 2: 'blue', 3: 'yellow', 4: 'red', 5: 'blue'}
>>> H.nodes.attrs('color').aslist()
['red', 'blue', 'yellow', 'red', 'blue']
>>> H.nodes.filterby_attr('color', 'red')
NodeView((1, 4))

Many other features are available, including edge-statistics, and user-defined statistics. For more details, see the tutorial.

Available statistics

Hypergraphs and simplicial complexes

Statistics of nodes

average_neighbor_degree

Average neighbor degree.

clique_eigenvector_centrality

Compute the clique motif eigenvector centrality of a hypergraph.

clustering_coefficient

Local clustering coefficient.

degree

Node degree.

h_eigenvector_centrality

Compute the H-eigenvector centrality of a hypergraph.

local_clustering_coefficient

Compute the local clustering coefficient.

node_edge_centrality

Computes node centralities.

two_node_clustering_coefficient

Return the clustering coefficients for each node in a Hypergraph.

Statistics of edges

order

Edge order.

size

Edge size.

node_edge_centrality

Computes edge centralities.

Corresponding decorators

nodestat_func

Decorate arbitrary functions to behave like NodeStat objects.

edgestat_func

Decorate arbitrary functions to behave like EdgeStat objects.

Corresponding modules

nodestats

Node statistics.

edgestats

Edge statistics.

Corresponding classes

NodeStat

An arbitrary node-quantity mapping.

EdgeStat

An arbitrary edge-quantity mapping.

MultiNodeStat

Multiple node-quantity mappings.

MultiEdgeStat

Multiple edge-quantity mappings.

Directed hypergraphs

Statistics of nodes

degree

Node degree.

in_degree

Node in-degree.

out_degree

Node out-degree.

Statistics of edges

order

Edge order.

size

Edge size.

head_order

Head order.

head_size

Head size.

tail_order

Tail order.

tail_size

Tail size.

Corresponding decorators

dinodestat_func

Decorator that allows arbitrary functions to behave like DiNodeStat objects.

diedgestat_func

Decorator that allows arbitrary functions to behave like DiEdgeStat objects.

Corresponding modules

dinodestats

Node statistics.

diedgestats

Directed edge statistics.

Corresponding classes

DiNodeStat

An arbitrary node-quantity mapping.

DiEdgeStat

An arbitrary edge-quantity mapping.

MultiDiNodeStat

Multiple node-quantity mappings.

MultiDiEdgeStat

Multiple edge-quantity mappings.