📏 Measures

Submodules

hypergraphx.measures.degree module

hypergraphx.measures.degree.degree(hg, node, order=None, size=None)[source]

Computes the degree of a node in the hypergraph.

Parameters:
  • hg (Hypergraph|DirectedHypergraph|TemporalHypergraph) – The hypergraph of interest.

  • node (Node) – The node to check.

  • order (int, optional) – The order of the hyperedges to consider. If None, all hyperedges are considered.

  • size (int, optional) – The size of the hyperedges to consider. If None, all hyperedges are considered.

Returns:

The degree of the node.

Return type:

int

hypergraphx.measures.degree.degree_correlation(hg)[source]

Computes the degree sequence correlation matrix of the hypergraph.

Parameters:

hg (Hypergraph) – The hypergraph of interest.

Returns:

The degree sequence correlation matrix of the hypergraph. The (i, j) entry is the Pearson correlation coefficient between the degree sequence at size i + 2 and the degree sequence at size j + 2.

Return type:

np.ndarray

hypergraphx.measures.degree.degree_distribution(hg, order=None, size=None)[source]

Computes the degree distribution of the hypergraph.

Parameters:
  • hg (Hypergraph|DirectedHypergraph|TemporalHypergraph) – The hypergraph of interest.

  • order (int, optional) – The order of the hyperedges to consider. If None, all hyperedges are considered.

  • size (int, optional) – The size of the hyperedges to consider. If None, all hyperedges are considered.

Returns:

The degree distribution of the hypergraph. The keys are the degrees and the values are the number of nodes with that degree.

Return type:

dict

hypergraphx.measures.degree.degree_sequence(hg, order=None, size=None)[source]

Computes the degree sequence of the hypergraph.

Parameters:
  • hg (Hypergraph|DirectedHypergraph|TemporalHypergraph) – The hypergraph of interest.

  • order (int, optional) – The order of the hyperedges to consider. If None, all hyperedges are considered.

  • size (int, optional) – The size of the hyperedges to consider. If None, all hyperedges are considered.

Returns:

The degree sequence of the hypergraph. The keys are the nodes and the values are the degrees.

Return type:

dict

hypergraphx.measures.degree.node_degree(hg, node, order=None, size=None)[source]

Alias for degree(hg, node, order, size).

hypergraphx.measures.degree.node_degree_distribution(hg, order=None, size=None)[source]

Alias for degree_distribution(hg, order, size).

hypergraphx.measures.degree.node_degree_sequence(hg, order=None, size=None)[source]

Alias for degree_sequence(hg, order, size).

hypergraphx.measures.edge_similarity module

hypergraphx.measures.edge_similarity.intersection(a, b)[source]

Computes the intersection between two sets.

Parameters:
  • a (set) – The first set.

  • b (set) – The second set.

Returns:

The size of the intersection between the two sets.

Return type:

int

Example

>>> intersection({1, 2, 3}, {2, 3, 4})
2
hypergraphx.measures.edge_similarity.jaccard_distance(a, b)[source]

Compute the Jaccard distance between two sets.

Parameters:
  • a (set) – The first set.

  • b (set) – The second set.

Returns:

The Jaccard distance between the two sets. The distance is 1 - the similarity.

Return type:

float

Example

>>> jaccard_distance({1, 2, 3}, {2, 3, 4})
0.5
hypergraphx.measures.edge_similarity.jaccard_similarity(a, b)[source]

Computes the Jaccard similarity between two sets.

Parameters:
  • a (set) – The first set.

  • b (set) – The second set.

Returns:

The Jaccard similarity between the two sets.

Return type:

float

See also

jaccard_distance

Example

>>> jaccard_similarity({1, 2, 3}, {2, 3, 4})
0.5

hypergraphx.measures.eigen_centralities module

hypergraphx.measures.eigen_centralities.CEC_centrality(HG, tol=1e-07, max_iter=1000, *, seed=None, rng=None)[source]

Compute the CEC centrality for uniform hypergraphs.

Parameters:
  • HG (Hypergraph) – The uniform hypergraph on which the CEC centrality is computed.

  • tol (float) – The tolerance for calculating the dominant eigenvalue by power method.

  • max_iter (int) – The maximum number of iterations for calculating the dominant eigenvalue by power method.

Returns:

cec – The dictionary of keys nodes of HG and values the CEC centrality of the node.

Return type:

dict

References

Three Hypergraph Eigenvector Centralities, Austin R. Benson, https://doi.org/10.1137/18M1203031

hypergraphx.measures.eigen_centralities.HEC_centrality(HG, max_iter=100, tol=1e-06, *, seed=None, rng=None)[source]

Compute the HEC centrality for uniform hypergraphs.

Parameters:
  • HG (Hypergraph) – The uniform hypergraph on which the HEC centrality is computed.

  • max_iter (int) – The maximum number of iterations.

  • tol (float) – The tolerance for the stopping criterion.

Returns:

HEC – The dictionary of keys nodes of HG and values the HEC centrality of the node.

Return type:

dict

References

Three Hypergraph Eigenvector Centralities, Austin R. Benson, https://doi.org/10.1137/18M1203031

hypergraphx.measures.eigen_centralities.ZEC_centrality(HG, max_iter=1000, tol=1e-07, *, seed=None, rng=None)[source]

Compute the ZEC centrality for uniform hypergraphs.

Parameters:
  • HG (Hypergraph) – The uniform hypergraph on which the ZEC centrality is computed.

  • max_iter (int) – The maximum number of iterations.

  • tol (float) – The tolerance for the stopping criterion.

Returns:

ZEC – The dictionary of keys nodes of HG and values the ZEC centrality of the node.

Return type:

dict

References

Three Hypergraph Eigenvector Centralities, Austin R. Benson, https://doi.org/10.1137/18M1203031

hypergraphx.measures.eigen_centralities.apply(HG, x, g=<function <lambda>>)[source]
hypergraphx.measures.eigen_centralities.power_method(W, max_iter=1000, tol=1e-07, *, seed=None, rng=None, x0=None)[source]

hypergraphx.measures.s_centralities module

hypergraphx.measures.s_centralities.s_betweenness(H, s=1)[source]

Computes the betweenness centrality for each edge in the hypergraph.

Parameters:
  • H (Hypergraph to compute the betweenness centrality for.)

  • s

Return type:

dict. The betweenness centrality for each edge in the hypergraph. The keys are the edges and the values are the betweenness centrality.

hypergraphx.measures.s_centralities.s_betweenness_averaged(H, s=1)[source]

Computes the betweenness centrality for each edge in the temporal hypergraph. The function calculates the betweenness centrality during each time of the temporal hypergraph and then the result is the average betweenness centrality in each time. :param H: The temporal hypergraph to compute the betweenness centrality for. :type H: TemporalHypergraph :param s: :type s: int, optional

Returns:

The betweenness centrality for each edge in the temporal hypergraph. The keys are the edges and the values are the betweenness centrality.

Return type:

dict.

hypergraphx.measures.s_centralities.s_betweenness_nodes(H)[source]

Computes the betweenness centrality for each node in the hypergraph. :param H: The hypergraph to compute the betweenness centrality for. :type H: Hypergraph

Returns:

The betweenness centrality for each node in the hypergraph. The keys are the nodes and the values are the betweenness centrality.

Return type:

dict.

hypergraphx.measures.s_centralities.s_betweenness_nodes_averaged(H)[source]

Computes the betweenness centrality for each node in the temporal hypergraph. The function calculates the betweenness centrality during each time of the temporal hypergraph and then the result is the average betweenness centrality in each time. :param H: The temporal hypergraph to compute the betweenness centrality for. :type H: TemporalHypergraph

Returns:

The betweenness centrality for each node in the temporal hypergraph. The keys are the nodes and the values are the betweenness centrality.

Return type:

dict.

hypergraphx.measures.s_centralities.s_closeness(H, s=1)[source]

Compute the closeness centrality for each edge in the hypergraph. :param H: :type H: Hypergraph to compute the closeness centrality for. :param s:

Return type:

dict. The closeness centrality for each edge in the hypergraph. The keys are the edges and the values are the closeness centrality.

hypergraphx.measures.s_centralities.s_closeness_averaged(H, s=1)[source]

Computes the closeness centrality for each edge in the temporal hypergraph. The function calculates the closeness centrality during each time of the temporal hypergraph and then the result is the average closeness centrality in each time. :param H: The temporal hypergraph to compute the closeness centrality for. :type H: TemporalHypergraph :param s: :type s: int, optional

Returns:

The closeness centrality for each edge in the hypergraph. The keys are the edges and the values are the closeness centrality.

Return type:

dict.

hypergraphx.measures.s_centralities.s_closeness_nodes(H)[source]

Computes the closeness centrality for each node in the hypergraph. :param H: :type H: Hypergraph to compute the closeness centrality for.

Returns:

The closeness centrality for each node in the hypergraph. The keys are the nodes and the values are the betweenness centrality.

Return type:

dict.

hypergraphx.measures.s_centralities.s_closenness_nodes_averaged(H)[source]

Computes the closeness centrality for each node in the temporal hypergraph. The function calculates the closeness centrality during each time of the temporal hypergraph and then the result is the average closeness centrality in each time. :param H: The temporal hypergraph to compute the closeness centrality for. :type H: TemporalHypergraph

Returns:

The closeness centrality for each node in the hypergraph. The keys are the nodes and the values are the closeness centrality.

Return type:

dict.

hypergraphx.measures.sub_hypergraph_centrality module

hypergraphx.measures.sub_hypergraph_centrality.subhypergraph_centrality(hypergraph)[source]

Compute the logarithm of the sub-hypergraph centrality, defined in “Complex Networks as Hypergraphs”, Estrada & Rodríguez-Velázquez, 2005

For every node v in the hypergraph, the sub-hypergraph centrality is given by the number of closed random walks starting and ending at v, each one discounted by the factorial of its length. This function computes the logarithm of the centrality defined in the reference paper.

Parameters:

hypergraph (the hypergraph.)

Returns:

  • The array of the log-sub-hypergraph centrality values for all the nodes in the

  • hypergraph.

hypergraphx.measures.reducibility module

hypergraphx.measures.reducibility.layer_reducibility(hg, partition=None, entropy_method='count')[source]

Compute layer-wise reducibility.

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

  • partition (list or dict, optional) – Node partition for multiscale reducibility.

  • entropy_method ({"count", "project"}, optional) – Entropy computation method.

Returns:

Mapping layer size -> reducibility value.

Return type:

dict

Notes

If you use this function in published work, please cite: Kirkley, Alec, Helcio Felippe, and Federico Battiston. “Structural Reducibility of Hypergraphs.” Physical Review Letters 135.24 (2025): 247401.

Examples

>>> from hypergraphx import Hypergraph
>>> from hypergraphx.measures.reducibility import layer_reducibility
>>> hg = Hypergraph()
>>> hg.add_nodes([0, 1, 2, 3])
>>> hg.add_edges([(0, 1), (1, 2), (2, 3), (0, 1, 2)])
>>> etas = layer_reducibility(hg, entropy_method="count")
hypergraphx.measures.reducibility.reducibility(hg, partition=None, optimization='exact', entropy_method='count')[source]

Compute hypergraph reducibility and the representative set of layers.

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

  • partition (list or dict, optional) – Node partition for multiscale reducibility. If list, it must align with hg.get_nodes() order. If dict, it must map every node to a group.

  • optimization ({"exact", "greedy"}, optional) – Optimization method for selecting representatives.

  • entropy_method ({"count", "project"}, optional) – Entropy computation method.

Returns:

(reducibility, representative_layers)

Return type:

tuple

Notes

If you use this function in published work, please cite: Kirkley, Alec, Helcio Felippe, and Federico Battiston. “Structural Reducibility of Hypergraphs.” Physical Review Letters 135.24 (2025): 247401.

Examples

>>> from hypergraphx import Hypergraph
>>> from hypergraphx.measures.reducibility import reducibility
>>> hg = Hypergraph()
>>> hg.add_nodes([0, 1, 2, 3])
>>> hg.add_edges([(0, 1), (1, 2), (2, 3), (0, 1, 2)])
>>> eta, reps = reducibility(hg, entropy_method="count", optimization="exact")

Module contents

Measures and statistics.

This package exposes a curated set of commonly used measures at the package level for discoverability (e.g. hypergraphx.measures.degree(…)).

Implementation modules can be import-heavy; wrappers import lazily on first use.

hypergraphx.measures.CEC_centrality(hypergraph, *, tol=1e-07, max_iter=1000, seed=None, rng=None)[source]
hypergraphx.measures.HEC_centrality(hypergraph, *, tol=1e-06, max_iter=100, seed=None, rng=None)[source]
hypergraphx.measures.ZEC_centrality(hypergraph, *, tol=1e-07, max_iter=1000, seed=None, rng=None)[source]
hypergraphx.measures.degree_correlation(hypergraph)[source]
hypergraphx.measures.degree_distribution(hypergraph, *, order=None, size=None)[source]
hypergraphx.measures.degree_sequence(hypergraph, *, order=None, size=None)[source]
hypergraphx.measures.intersection(a, b)[source]
hypergraphx.measures.jaccard_distance(a, b)[source]
hypergraphx.measures.jaccard_similarity(a, b)[source]
hypergraphx.measures.subhypergraph_centrality(hypergraph)[source]

Next steps