xgi.algorithms.properties

Functional interface to hypergraph methods and assorted utilities.

Functions

xgi.algorithms.properties.degree_counts(H, order=None)[source]

Returns a list of the the number of occurrences of each degree value.

The counts correspond to degrees from 0 to max(degree).

Parameters:
  • H (Hypergraph object) – The hypergraph of interest

  • order (int, optional) – Order of edges to take into account. If None (default), consider all edges.

Returns:

A list of frequencies of degrees. The degree values are the index in the list.

Return type:

list

Notes

Note: the bins are width one, hence len(list) can be large (Order(num_edges))

The degree is defined as the number of edges to which a node belongs. A node belonging only to a singleton edge will thus have degree 1 and contribute accordingly to the degree count.

Examples

>>> import xgi
>>> hyperedge_list = [[1, 2], [2, 3, 4]]
>>> H = xgi.Hypergraph(hyperedge_list)
>>> xgi.degree_counts(H)
[0, 3, 1]
xgi.algorithms.properties.degree_histogram(H)[source]

Returns a degree histogram including bin centers (degree values).

Parameters:

H (Hypergraph object) – The hypergraph of interest

Returns:

First entry is observed degrees (bin centers),

second entry is degree count (histogram height)

Return type:

tuple of lists

Notes

Note: the bins are width one, hence there will be an entry for every observed degree.

Examples

>>> import xgi
>>> hyperedge_list = [[1, 2], [2, 3, 4]]
>>> H = xgi.Hypergraph(hyperedge_list)
>>> xgi.degree_histogram(H)
([1, 2], [3, 1])
xgi.algorithms.properties.density(H, order=None, max_order=None, ignore_singletons=False)[source]

Hypergraph density.

The density of a hypergraph is the number of existing edges divided by the number of possible edges.

Let H have \(n\) nodes and \(m\) hyperedges. Then,

  • density(H) = \(\frac{m}{2^n - 1}\),

  • density(H, ignore_singletons=True) = \(\frac{m}{2^n - 1 - n}\).

Here, \(2^n\) is the total possible number of hyperedges on H, from which we subtract \(1\) because the empty hyperedge is not considered. We subtract an additional \(n\) when singletons are not considered.

Now assume H has \(a\) edges with order \(1\) and \(b\) edges with order \(2\). Then,

  • density(H, order=1) = \(\frac{a}{{n \choose 2}}\),

  • density(H, order=2) = \(\frac{b}{{n \choose 3}}\),

  • density(H, max_order=1) = \(\frac{a}{{n \choose 1} + {n \choose 2}}\),

  • density(H, max_order=1, ignore_singletons=True) = \(\frac{a}{{n \choose 2}}\),

  • density(H, max_order=2) = \(\frac{m}{{n \choose 1} + {n \choose 2} + {n \choose 3}}\),

  • density(H, max_order=2, ignore_singletons=True) = \(\frac{m}{{n \choose 2} + {n \choose 3}}\),

Parameters:
  • order (int, optional) – If not None, only count edges of the specified order. By default, None.

  • max_order (int, optional) – If not None, only count edges of order up to this value, inclusive. By default, None.

  • ignore_singletons (bool, optional) – Whether to consider singleton edges. Ignored if order is not None and different from \(0\). By default, False.

Notes

If both order and max_order are not None, max_order is ignored.

xgi.algorithms.properties.edge_neighborhood(H, n, include_self=False)[source]

The edge neighborhood of the specified node.

The edge neighborhood of a node n in a hypergraph H is an edgelist of all the edges containing n and its edges are all the edges in H that contain n. Usually, the edge neighborhood does not include n itself. This can be controlled with include_self.

Parameters:
  • H (Hypergraph) – THe hypergraph of interest

  • n (node) – Node whose edge_neighborhood is needed.

  • include_self (bool, optional) – Whether the edge_neighborhood contains n. By default, False.

Returns:

An edgelist of the edge_neighborhood of n.

Return type:

list

See also

neighbors

Examples

>>> import xgi
>>> H = xgi.Hypergraph([[1, 2, 3], [3, 4], [4, 5, 6]])
>>> H.nodes.neighbors(3)
{1, 2, 4}
>>> xgi.edge_neighborhood(H, 3)
[{1, 2}, {4}]
>>> xgi.edge_neighborhood(H, 3, include_self=True)
[{1, 2, 3}, {3, 4}]
xgi.algorithms.properties.incidence_density(H, order=None, max_order=None, ignore_singletons=False)[source]

Density of the incidence matrix.

The incidence matrix of a hypergraph contains one row per node and one column per edge. An entry is non-zero when the corresponding node is a member of the corresponding edge. The density of this matrix is the number of non-zero entries divided by the total number of entries.

Parameters:
  • order (int, optional) – If not None, only count edges of the specified order. By default, None.

  • max_order (int, optional) – If not None, only count edges of order up to this value, inclusive. By default, None.

  • ignore_singletons (bool, optional) – Whether to consider singleton edges. Ignored if order is not None and different from \(0\). By default, False.

See also

density()

Notes

If both order and max_order are not None, max_order is ignored.

The parameters order, max_order and ignore_singletons have a similar effect on the denominator as they have in density().

xgi.algorithms.properties.is_possible_order(H, d)[source]

Whether the specified order is between 0 (singletons) and the maximum order.

Parameters:
  • H (Hypergraph) – The hypergraph of interest.

  • d (int) – Order for which to check.

Returns:

Whether d is a possible order.

Return type:

bool

xgi.algorithms.properties.is_uniform(H)[source]

Order of uniformity if the hypergraph is uniform, or False.

A hypergraph is uniform if all its edges have the same order.

Returns d if the hypergraph is d-uniform, that is if all edges in the hypergraph (excluding singletons) have the same degree d. Returns False if not uniform.

Returns:

d – If the hypergraph is d-uniform, return d, or False otherwise.

Return type:

int or False

Examples

This function can be used as a boolean check:

>>> import xgi
>>> H = xgi.Hypergraph([(0, 1, 2), (1, 2, 3), (2, 3, 4)])
>>> xgi.is_uniform(H)
2
>>> if xgi.is_uniform(H): print('H is uniform!')
H is uniform!
xgi.algorithms.properties.max_edge_order(H)[source]

The maximum order of edges in the hypergraph.

Parameters:

H (Hypergraph) – The hypergraph of interest.

Returns:

Maximum order of edges in hypergraph.

Return type:

int

See also

num_edges_order

xgi.algorithms.properties.num_edges_order(H, d=None)[source]

The number of edges of order d.

Parameters:
  • H (Hypergraph) – The hypergraph of interest.

  • d (int, optional) – The order of edges to count. If None (default), counts for all orders.

Returns:

The number of edges of order d

Return type:

int

See also

max_edge_order

xgi.algorithms.properties.unique_edge_sizes(H)[source]

A function that returns the unique edge sizes.

Parameters:

H (Hypergraph object) – The hypergraph of interest

Returns:

The unique edge sizes in ascending order by size.

Return type:

list()