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.
Modules
Node statistics. |
|
Edge statistics. |
Classes
An arbitrary node-quantity mapping. |
|
An arbitrary edge-quantity mapping. |
|
Multiple node-quantity mappings. |
|
Multiple edge-quantity mappings. |
Decorators
Decorate arbitrary functions to behave like |
|
Decorate arbitrary functions to behave like |