🧰 Utilities

Submodules

hypergraphx.utils.components module

hypergraphx.utils.components.connected_components(hg, order=None, size=None)[source]

Return the connected components of the hypergraph. :param hg: :type hg: Hypergraph. The hypergraph to check. :param order: :type order: int. The order of the hyperedges to consider. If None, all hyperedges are considered. :param size: :type size: int. The size of the hyperedges to consider. If None, all hyperedges are considered.

Return type:

list. The connected components of the hypergraph.

hypergraphx.utils.components.is_connected(hg, order=None, size=None)[source]

Return True if the hypergraph is connected. :param hg: :type hg: Hypergraph. The hypergraph to check. :param order: :type order: int. The order of the hyperedges to consider. If None, all hyperedges are considered. :param size: :type size: int. The size of the hyperedges to consider. If None, all hyperedges are considered.

Return type:

bool. True if the hypergraph is connected, False otherwise.

hypergraphx.utils.components.is_isolated(hg, node, order=None, size=None)[source]

Return True if the given node is isolated. :param hg: :type hg: Hypergraph. The hypergraph to check. :param node: :type node: Node. The node to check. :param order: :type order: int. The order of the hyperedges to consider. If None, all hyperedges are considered. :param size: :type size: int. The size of the hyperedges to consider. If None, all hyperedges are considered.

Return type:

bool. True if the node is isolated, False otherwise.

hypergraphx.utils.components.isolated_nodes(hg, order=None, size=None)[source]

Return the isolated nodes of the hypergraph. :param hg: :type hg: Hypergraph. The hypergraph to check. :param order: :type order: int. The order of the hyperedges to consider. If None, all hyperedges are considered. :param size: :type size: int. The size of the hyperedges to consider. If None, all hyperedges are considered.

Return type:

list. The isolated nodes.

hypergraphx.utils.components.largest_component(hg, order=None, size=None)[source]

Return the largest connected component of the hypergraph. :param hg: :type hg: Hypergraph. The hypergraph to check. :param order: :type order: int. The order of the hyperedges to consider. If None, all hyperedges are considered. :param size: :type size: int. The size of the hyperedges to consider. If None, all hyperedges are considered.

Return type:

list. The nodes in the largest connected component.

hypergraphx.utils.components.largest_component_size(hg, order=None, size=None)[source]

Return the size of the largest connected component of the hypergraph. :param hg: :type hg: Hypergraph. The hypergraph to check. :param order: :type order: int. The order of the hyperedges to consider. If None, all hyperedges are considered. :param size: :type size: int. The size of the hyperedges to consider. If None, all hyperedges are considered.

Return type:

int. The size of the largest connected component.

hypergraphx.utils.components.node_connected_component(hg, node, order=None, size=None)[source]

Return the connected component of the hypergraph containing the given node. :param hg: :type hg: Hypergraph. The hypergraph to check. :param node: :type node: Node. The node to check. :param order: :type order: int. The order of the hyperedges to consider. If None, all hyperedges are considered. :param size: :type size: int. The size of the hyperedges to consider. If None, all hyperedges are considered.

Return type:

list. The nodes in the connected component of the input node.

hypergraphx.utils.components.num_connected_components(hg, order=None, size=None)[source]

Return the number of connected components of the hypergraph. :param hg: :type hg: Hypergraph. The hypergraph to check. :param order: :type order: int. The order of the hyperedges to consider. If None, all hyperedges are considered. :param size: :type size: int. The size of the hyperedges to consider. If None, all hyperedges are considered.

Return type:

int. The number of connected components.

hypergraphx.utils.community module

hypergraphx.utils.community.calculate_permutation_matrix(u_ref, u_pred)[source]

Calculate the permutation matrix to overcome the column switching between two matrices.

Parameters:
  • u_ref (reference matrix.)

  • u_pred (matrix to switch.)

Returns:

P

Return type:

permutation matrix of the same dimension as u_ref.

hypergraphx.utils.community.normalize_array(u, axis)[source]

Return the normalized array u over a given axis. E.g., if u is a matrix NxK and axis=1, then this function returns the matrix u normalized by row.

Parameters:
  • u (numpy array.)

  • axis (axis along which the normalization is performed.)

hypergraphx.utils.labeling module

class hypergraphx.utils.labeling.LabelEncoder(classes_=None, _to_int=None)[source]

Bases: object

Minimal drop-in replacement for sklearn’s LabelEncoder, used throughout HypergraphX to map arbitrary node labels to dense integer ids.

This exists to avoid forcing scikit-learn as a hard dependency.

classes_ = None
fit(y)[source]
inverse_transform(y)[source]
transform(y)[source]
hypergraphx.utils.labeling.get_inverse_mapping(mapping)[source]

Get the inverse mapping of a LabelEncoder.

Parameters:

mapping (LabelEncoder) – The mapping to invert

Returns:

The inverse mapping

Return type:

dict

hypergraphx.utils.labeling.inverse_map_nodes(mapping, nodes)[source]

Revert node mapping using a mapping.

Parameters:
  • mapping (LabelEncoder) – The mapping to use

  • nodes (List) – The nodes to map

Returns:

The mapped nodes

Return type:

List

hypergraphx.utils.labeling.inverse_relabel_edge(mapping, edge)[source]

Revert edge relabeling using a mapping.

Parameters:
  • mapping (LabelEncoder) – The mapping to use

  • edge (Tuple) – The edge to relabel

Returns:

The relabeled edge

Return type:

Tuple

hypergraphx.utils.labeling.inverse_relabel_edges(mapping, edges)[source]

Revert edges relabeling using a mapping.

Parameters:
  • mapping (LabelEncoder) – The mapping to use

  • edges (List[Tuple]) – The edges to relabel

Returns:

The relabeled edges

Return type:

List[Tuple]

hypergraphx.utils.labeling.map_node(mapping, node)[source]

Map a node using a mapping.

Parameters:
  • mapping (LabelEncoder) – The mapping to use

  • node (Any) – The node to map

Returns:

The mapped node

Return type:

Any

hypergraphx.utils.labeling.map_nodes(mapping, nodes)[source]

Map a list of nodes using a mapping.

Parameters:
  • mapping (LabelEncoder) – The mapping to use

  • nodes (List) – The nodes to map

Returns:

The mapped nodes

Return type:

List

hypergraphx.utils.labeling.relabel_edge(mapping, edge)[source]

Relabel an edge using a mapping.

Parameters:
  • mapping (LabelEncoder) – The mapping to use

  • edge (Tuple) – The edge to relabel

Returns:

The relabeled edge

Return type:

Tuple

hypergraphx.utils.labeling.relabel_edges(mapping, edges)[source]

Relabel a list of edges using a mapping.

Parameters:
  • mapping (LabelEncoder) – The mapping to use

  • edges (List[Tuple]) – The edges to relabel

Returns:

The relabeled edges

Return type:

List[Tuple]

hypergraphx.utils.labeling.relabel_edges_with_mapping(edges, mapping)[source]

Relabel edges using a dictionary mapping old labels to new labels.

Parameters:
  • edges (List[Tuple]) – The edges to relabel

  • mapping (dict) – Mapping from old labels to new labels

Returns:

The relabeled edges

Return type:

List[Tuple]

hypergraphx.utils.traversal module

Module contents

Utility helpers.

This module is intentionally import-light: most implementations are imported lazily on first use to avoid pulling heavy dependencies at import time.

hypergraphx.utils.calculate_permutation_matrix(*args, **kwargs)[source]
hypergraphx.utils.canon_edge(*args, **kwargs)[source]
hypergraphx.utils.connected_components(*args, **kwargs)[source]
hypergraphx.utils.get_inverse_mapping(*args, **kwargs)[source]
hypergraphx.utils.inverse_map_nodes(*args, **kwargs)[source]
hypergraphx.utils.inverse_relabel_edge(*args, **kwargs)[source]
hypergraphx.utils.inverse_relabel_edges(*args, **kwargs)[source]
hypergraphx.utils.is_connected(*args, **kwargs)[source]
hypergraphx.utils.is_isolated(*args, **kwargs)[source]
hypergraphx.utils.isolated_nodes(*args, **kwargs)[source]
hypergraphx.utils.largest_component(*args, **kwargs)[source]
hypergraphx.utils.largest_component_size(*args, **kwargs)[source]
hypergraphx.utils.map_node(*args, **kwargs)[source]
hypergraphx.utils.map_nodes(*args, **kwargs)[source]
hypergraphx.utils.merge_metadata(*args, **kwargs)[source]
hypergraphx.utils.node_connected_component(*args, **kwargs)[source]
hypergraphx.utils.normalize_array(*args, **kwargs)[source]
hypergraphx.utils.num_connected_components(*args, **kwargs)[source]
hypergraphx.utils.relabel_edge(*args, **kwargs)[source]
hypergraphx.utils.relabel_edges(*args, **kwargs)[source]

Next steps