xgi.stats.NodeStat

class xgi.stats.NodeStat(network, view, func, args=None, kwargs=None)[source]

Bases: IDStat

An arbitrary node-quantity mapping.

NodeStat objects represent a mapping that assigns a value to each node in a network. For more details, see the tutorial.

Attributes

name

Name of this stat.

Methods

asdict

Output the stat as a dict.

aslist

Output the stat as a list.

asnumpy

Output the stat as a numpy array.

aspandas

Output the stat as a pandas series.

ashist

Return the distribution of a numpy array.

max

The maximum value of this stat.

mean

The arithmetic mean of this stat.

median

The median of this stat.

min

The minimum value of this stat.

std

The standard deviation of this stat.

var

The variance of this stat.

moment

The statistical moments of this stat.

argmin

The ID corresponding to the minimum of the stat

argmax

The ID corresponding to the maximum of the stat

argsort

Get the list of IDs sorted by stat value.

argmax()

The ID corresponding to the maximum of the stat

When the maximal value is not unique, returns first ID corresponding to the maximal value.

Returns:

The ID to which the maximum value corresponds.

Return type:

hashable

argmin()

The ID corresponding to the minimum of the stat

When the minimum value is not unique, returns first ID corresponding to the minimum value.

Returns:

The ID to which the minimum value corresponds.

Return type:

hashable

argsort(reverse=False)

Get the list of IDs sorted by stat value.

When values are not unique, the order of the IDs is preserved.

Parameters:

reverse (bool) – Whether the sorting should be ascending or descending.

Returns:

The IDs sorted in ascending or descending order.

Return type:

list

asdict()

Output the stat as a dict.

Notes

All stats are stored as dicts and therefore this method incurs in no overhead as type conversion is not necessary.

ashist(bins=10, bin_edges=False, density=False, log_binning=False)

Return the distribution of a numpy array.

Parameters:
  • vals (Numpy array) – The array of values

  • bins (int, list, or Numpy array) – The number of bins or the bin edges.

  • bin_edges (bool) – Whether to also output the min and max of each bin, by default, False.

  • density (bool) – Whether to normalize the resulting distribution.

  • log_binning (bool) – Whether to bin the values with log-sized bins. By default, False.

Returns:

A two-column table with “bin_center” and “value” columns, where “value” is a count or a probability. If bin_edges is True, outputs two additional columns, bin_lo and bin_hi, which outputs the left and right bin edges respectively.

Return type:

Pandas DataFrame

Notes

Originally from https://github.com/jkbren/networks-and-dataviz

aslist()

Output the stat as a list.

asnumpy()

Output the stat as a numpy array.

aspandas()

Output the stat as a pandas series.

Notes

The name attribute of the returned series is set using the name property.

max()

The maximum value of this stat.

mean()

The arithmetic mean of this stat.

median()

The median of this stat.

min()

The minimum value of this stat.

moment(order=2, center=False)

The statistical moments of this stat.

Parameters:
  • order (int (default 2)) – The order of the moment.

  • center (bool (default False)) – Whether to compute the centered (False) or uncentered/raw (True) moment.

property name

Name of this stat.

The name of a stat is used to populate the keys of dictionaries in MultiStat objects, as well as the names of columns of pandas dataframes.

Examples

>>> import xgi
>>> H = xgi.Hypergraph([[1, 2, 3], [2, 3, 4, 5], [3, 4, 5]])
>>> da, d3 = H.nodes.degree, H.nodes.degree(order=3)
>>> da.name, d3.name
('degree', 'degree(order=3)')
>>> H.nodes.multi([da, d3]).asdict(transpose=True).keys()
dict_keys(['degree', 'degree(order=3)'])
>>> H.nodes.multi([da, d3]).aspandas().columns
Index(['degree', 'degree(order=3)'], dtype='object')
std()

The standard deviation of this stat.

sum()

The sum of this stat.

var()

The variance of this stat.