xgi.stats.MultiDiNodeStat#
- class MultiDiNodeStat(network, view, stats)[source]#
Bases:
MultiIDStat
Multiple node-quantity mappings.
For more details, see the tutorial.
Attributes
Name of this stat.
Methods
Output the stats as a dict of collections.
Output the stats as a list of collections.
Output the stats as a numpy array.
Output the stats as a pandas dataframe.
Return the distributions of a numpy array.
- 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(inner=<class 'dict'>, transpose=False)#
Output the stats as a dict of collections.
- Parameters:
inner (dict (default) or list) – The type of the inner collections. If dict (default), output a dict of dicts. If list, output a dict of lists.
transpose (bool (default False)) – By default, output a dict of dicts whose outer keys are the nodes and inner keys are the specified stats. If True, the outer and inner keys are reversed. Only used when inner is dict.
Examples
>>> import xgi >>> H = xgi.Hypergraph([[1, 2, 3], [2, 3, 4, 5], [3, 4, 5]]) >>> m = H.nodes.multi(['degree', 'clustering_coefficient']) >>> m.asdict() {1: {'degree': 1, 'clustering_coefficient': 1.0}, 2: {'degree': 2, 'clustering_coefficient': 0.6666666666666666}, 3: {'degree': 3, 'clustering_coefficient': 0.6666666666666666}, 4: {'degree': 2, 'clustering_coefficient': 1.0}, 5: {'degree': 2, 'clustering_coefficient': 1.0}} >>> m.asdict(transpose=True) {'degree': {1: 1, 2: 2, 3: 3, 4: 2, 5: 2}, 'clustering_coefficient': {1: 1.0, 2: 0.6666666666666666, 3: 0.6666666666666666, 4: 1.0, 5: 1.0}}
- ashist(bins=10, bin_edges=False, density=False, log_binning=False)#
Return the distributions 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:
Each entry of the list is 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:
list of Pandas DataFrames
Notes
Originally from jkbren/networks-and-dataviz
- aslist(inner=<class 'list'>, transpose=False)#
Output the stats as a list of collections.
- Parameters:
inner (list (default) or dict) – The type of the inner collections. If list (default), output a list of lists. If dict, output a list of dicts.
transpose (bool (default False)) – By default, output a list of lists where each inner list contains the stats of a single node. If True, each inner list contains the values of a single stat of all nodes.
Examples
>>> import xgi >>> H = xgi.Hypergraph([[1, 2, 3], [2, 3, 4, 5], [3, 4, 5]]) >>> m = H.nodes.multi(['degree', 'clustering_coefficient']) >>> m.aslist() # doctest: [[1, 1.0], [2, 0.6666666666666666], [3, 0.6666666666666666], [2, 1.0], [2, 1.0]] >>> m.aslist(transpose=True) [[1, 2, 3, 2, 2], [1.0, 0.6666666666666666, 0.6666666666666666, 1.0, 1.0]]
- asnumpy()#
Output the stats as a numpy array.
Notes
Equivalent to np.array(self.aslist(inner=list)).
Examples
>>> import xgi >>> H = xgi.Hypergraph([[1, 2, 3], [2, 3, 4, 5], [3, 4, 5]]) >>> H.nodes.multi(['degree', 'clustering_coefficient']).asnumpy() ... array([[1. , 1. ], [2. , 0.66666667], [3. , 0.66666667], [2. , 1. ], [2. , 1. ]])
- aspandas()#
Output the stats as a pandas dataframe.
Examples
>>> import xgi >>> H = xgi.Hypergraph([[1, 2, 3], [2, 3, 4, 5], [3, 4, 5]]) >>> H.nodes.multi(['degree', 'clustering_coefficient']).aspandas() ... degree clustering_coefficient 1 1 1.000000 2 2 0.666667 3 3 0.666667 4 2 1.000000 5 2 1.000000
- 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')
- statsclass#
alias of
DiNodeStat
- statsmodule = <module 'xgi.stats.dinodestats' from '/home/docs/checkouts/readthedocs.org/user_builds/xgi/envs/stable/lib/python3.12/site-packages/xgi/stats/dinodestats.py'>#
Module in which to search for mappings.
- 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.