easygraph.functions.hypergraph package

Subpackages

Submodules

easygraph.functions.hypergraph.assortativity module

Algorithms for finding the degree assortativity of a hypergraph.

easygraph.functions.hypergraph.assortativity.degree_assortativity(H, kind='uniform', exact=False, num_samples=1000)[source]

Computes the degree assortativity of a hypergraph

Parameters
  • H (Hypergraph) – The hypergraph of interest

  • kind (str, optional) – the type of degree assortativity. valid choices are “uniform”, “top-2”, and “top-bottom”. By default, “uniform”.

  • exact (bool, optional) – whether to compute over all edges or sample randomly from the set of edges. By default, False.

  • num_samples (int, optional) – if not exact, specify the number of samples for the computation. By default, 1000.

Returns

the degree assortativity

Return type

float

Raises

EasyGraphError – If there are no nodes or no edges

References

Phil Chodrow, Configuration models of random hypergraphs, Journal of Complex Networks 2020. DOI: 10.1093/comnet/cnaa018

easygraph.functions.hypergraph.assortativity.dynamical_assortativity(H)[source]

Computes the dynamical assortativity of a uniform hypergraph.

Parameters

H (eg.Hypergraph) – Hypergraph of interest

Returns

The dynamical assortativity

Return type

float

Raises

EasyGraphError – If the hypergraph is not uniform, or if there are no nodes or no edges

References

Nicholas Landry and Juan G. Restrepo, Hypergraph assortativity: A dynamical systems perspective, Chaos 2022. DOI: 10.1063/5.0086905

easygraph.functions.hypergraph.hypergraph_clustering module

Algorithms for computing nodal clustering coefficients.

easygraph.functions.hypergraph.hypergraph_clustering.hypergraph_clustering_coefficient(H)[source]

Return the clustering coefficients for each node in a Hypergraph.

This clustering coefficient is defined as the clustering coefficient of the unweighted pairwise projection of the hypergraph, i.e., \(c = A^3_{i,i}/\binom{k}{2},\) where \(A\) is the adjacency matrix of the network and \(k\) is the pairwise degree of \(i\).

Parameters

H (Hypergraph) – Hypergraph

Returns

nodes are keys, clustering coefficients are values.

Return type

dict

Notes

The clustering coefficient is undefined when the number of neighbors is 0 or 1, but we set the clustering coefficient to 0 in these cases. For more discussion, see https://arxiv.org/abs/0802.2512

See also

local_clustering_coefficient, two_node_clustering_coefficient

References

“Clustering Coefficients in Protein Interaction Hypernetworks” by Suzanne Gallagher and Debra Goldberg. DOI: 10.1145/2506583.2506635

Example

>>> import easygraph as eg
>>> H = eg.random_hypergraph(3, [1, 1])
>>> cc = eg.clustering_coefficient(H)
>>> cc
{0: 1.0, 1: 1.0, 2: 1.0}
easygraph.functions.hypergraph.hypergraph_clustering.hypergraph_local_clustering_coefficient(H)[source]

Compute the local clustering coefficient.

This clustering coefficient is based on the overlap of the edges connected to a given node, normalized by the size of the node’s neighborhood.

Parameters

H (Hypergraph) – Hypergraph

Returns

keys are node IDs and values are the clustering coefficients.

Return type

dict

Notes

The clustering coefficient is undefined when the number of neighbors is 0 or 1, but we set the clustering coefficient to 0 in these cases. For more discussion, see https://arxiv.org/abs/0802.2512

See also

clustering_coefficient, two_node_clustering_coefficient

References

“Properties of metabolic graphs: biological organization or representation artifacts?” by Wanding Zhou and Luay Nakhleh. https://doi.org/10.1186/1471-2105-12-132

“Hypergraphs for predicting essential genes using multiprotein complex data” by Florian Klimm, Charlotte M. Deane, and Gesine Reinert. https://doi.org/10.1093/comnet/cnaa028

Example

>>> import easygraph as eg
>>> H = eg.random_hypergraph(3, [1, 1])
>>> cc = eg.hypergraph_local_clustering_coefficient(H)
>>> cc
{0: 1.0, 1: 1.0, 2: 1.0}
easygraph.functions.hypergraph.hypergraph_clustering.hypergraph_two_node_clustering_coefficient(H, kind='union')[source]

Return the clustering coefficients for each node in a Hypergraph.

This definition averages over all of the two-node clustering coefficients involving the node.

Parameters
  • H (Hypergraph) – Hypergraph

  • kind (string, optional) – The type of two node clustering coefficient. Options are “union”, “max”, and “min”. By default, “union”.

Returns

nodes are keys, clustering coefficients are values.

Return type

dict

Notes

The clustering coefficient is undefined when the number of neighbors is 0 or 1, but we set the clustering coefficient to 0 in these cases. For more discussion, see https://arxiv.org/abs/0802.2512

See also

clustering_coefficient, local_clustering_coefficient

References

“Clustering Coefficients in Protein Interaction Hypernetworks” by Suzanne Gallagher and Debra Goldberg. DOI: 10.1145/2506583.2506635

Example

>>> import easygraph as eg
>>> H = eg.random_hypergraph(3, [1, 1])
>>> cc = eg.two_node_clustering_coefficient(H, kind="union")
>>> cc
{0: 0.5, 1: 0.5, 2: 0.5}

easygraph.functions.hypergraph.hypergraph_operation module

easygraph.functions.hypergraph.hypergraph_operation.hypergraph_density(hg, 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.

See also

incidence_density()

Notes

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

Module contents