xgi.stats.NodeStat#
- class 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 of this stat.
Methods
Output the stat as a dict.
Output the stat as a list.
Output the stat as a numpy array.
Output the stat as a pandas series.
Return the distribution of a numpy array.
The maximum value of this stat.
The arithmetic mean of this stat.
The median of this stat.
The minimum value of this stat.
The standard deviation of this stat.
The variance of this stat.
The statistical moments of this stat.
The ID corresponding to the minimum of the stat
The ID corresponding to the maximum of the stat
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 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.
Notes
This implementation calculates the standard deviation with N in the denominator (NumPy’s default). This is in contrast to the sample standard deviation which normalizes by N-1. See https://www.allendowney.com/blog/2024/06/08/which-standard-deviation/ for more details.
- sum()#
The sum of this stat.
- var()#
The variance of this stat.
Notes
This implementation calculates the variance with N in the denominator. (NumPy’s default) This is in contrast to the sample variation which normalizes by N-1. See https://www.allendowney.com/blog/2024/06/08/which-standard-deviation/ for more details.