🔗 Representations

Submodules

hypergraphx.representations.projections module

hypergraphx.representations.projections.bipartite_projection(h, *, node_order=None, edge_order=None, return_obj_to_id=False)[source]

Returns a bipartite graph representation of the hypergraph.

Parameters:
  • h (Hypergraph) – The hypergraph to be projected.

  • node_order (list, optional (keyword-only)) – Explicit node iteration order to make the node-id mapping deterministic. If None, uses h.get_nodes() order.

  • edge_order (list, optional (keyword-only)) – Explicit edge iteration order to make the edge-id mapping deterministic. If None, uses h.get_edges() order.

  • return_obj_to_id (bool, optional (keyword-only)) – If True, also return the reverse mapping obj_to_id.

Returns:

(g, id_to_obj) where: - g is a networkx.Graph with node ids like “N0” and “E0” - id_to_obj maps node ids to original objects (node labels and edge tuples)

If return_obj_to_id=True, returns (g, id_to_obj, obj_to_id).

Return type:

tuple

Notes

This function is deterministic given node_order and edge_order. Without them, the mapping depends on the insertion/iteration order of h.

hypergraphx.representations.projections.clique_projection(h, keep_isolated=False)[source]

Returns a clique projection of the hypergraph.

Parameters:
  • h (Hypergraph) – The hypergraph to be projected.

  • keep_isolated (bool) – Whether to keep isolated nodes or not.

Returns:

The clique projection of the hypergraph.

Return type:

networkx.Graph

Notes

Computing the clique projection can be very expensive for large hypergraphs.

Example

>>> import networkx as nx
>>> import hypergraphx as hgx
>>> from hypergraphx.representations.projections import clique_projection
>>>
>>> h = hgx.Hypergraph()
>>> h.add_nodes([1, 2, 3, 4, 5])
>>> h.add_edges([(1, 2), (1, 2, 3), (3, 4, 5)])
>>> g = clique_projection(h)
>>> g.edges()
EdgeView([(1, 2), (1, 3), (2,3), (3, 4), (3, 5), (4, 5)])
hypergraphx.representations.projections.directed_line_graph(h, distance='intersection', s=1, weighted=False, *, edge_order=None)[source]

Returns a line graph of the directed hypergraph.

Parameters:
  • h (DirectedHypergraph) – The directed hypergraph to be projected.

  • distance (str) – The distance function to be used. Can be ‘intersection’ or ‘jaccard’.

  • s (float) – The threshold for the distance function.

  • weighted (bool) – Whether the line graph should be weighted or not.

  • edge_order (list, optional (keyword-only)) – Explicit edge iteration order to make the returned id_to_edge mapping deterministic. If None, uses h.get_edges() order.

Returns:

(g, id_to_edge) where: - g is a networkx.DiGraph whose nodes are edge-ids 0..m-1 - id_to_edge maps those ids back to directed hyperedges

Return type:

tuple

Notes

Computing the line graph can be very expensive for large hypergraphs. This function is deterministic given edge_order. Without it, edge-id assignment depends on the insertion/iteration order of h.

Example

>>> import networkx as nx
>>> import hypergraphx as hgx
>>> from hypergraphx.representations.projections import line_graph
>>>
>>> h = hgx.Hypergraph()
>>> h.add_nodes([1, 2, 3, 4, 5])
>>> h.add_edges([(1, 2), (1, 2, 3), (3, 4, 5)])
>>> g, idx = line_graph(h)
>>> g.edges()
EdgeView([(0, 1), (1, 2)])
hypergraphx.representations.projections.line_graph(h, distance='intersection', s=1, weighted=False, *, edge_order=None)[source]

Returns a line graph of the hypergraph.

Parameters:
  • h (Hypergraph) – The hypergraph to be projected.

  • distance (str) – The distance function to be used. Can be ‘intersection’ or ‘jaccard’.

  • s (float) – The threshold for the distance function.

  • weighted (bool) – Whether the line graph should be weighted or not.

  • edge_order (list, optional (keyword-only)) – Explicit edge iteration order to make the returned id_to_edge mapping deterministic. If None, uses h.get_edges() order.

Returns:

(g, id_to_edge) where: - g is a networkx.Graph whose nodes are edge-ids 0..m-1 - id_to_edge maps those ids back to hyperedges

Return type:

tuple

Notes

Computing the line graph can be very expensive for large hypergraphs. This function is deterministic given edge_order. Without it, edge-id assignment depends on the insertion/iteration order of h.

Example

>>> import networkx as nx
>>> import hypergraphx as hgx
>>> from hypergraphx.representations.projections import line_graph
>>>
>>> h = hgx.Hypergraph()
>>> h.add_nodes([1, 2, 3, 4, 5])
>>> h.add_edges([(1, 2), (1, 2, 3), (3, 4, 5)])
>>> g, idx = line_graph(h)
>>> g.edges()
EdgeView([(0, 1), (1, 2)])

hypergraphx.representations.simplicial_complex module

hypergraphx.representations.simplicial_complex.get_all_subsets(s)[source]

Returns all subsets of a set. :param s: :type s: set. The set to get all subsets of.

Returns:

subsets

Return type:

list. All subsets of the set.

hypergraphx.representations.simplicial_complex.simplicial_complex(h)[source]

Returns a simplicial complex representation of the hypergraph.

Parameters:

h (Hypergraph. The hypergraph to be projected.)

Returns:

S

Return type:

Hypergraph. The simplicial complex representation of the hypergraph.

Module contents

Graph/hypergraph representations and projections.

Curated entrypoints are exposed here for discoverability; implementations are imported lazily on first use.

hypergraphx.representations.bipartite_projection(*args, **kwargs)[source]
hypergraphx.representations.clique_projection(*args, **kwargs)[source]
hypergraphx.representations.directed_line_graph(*args, **kwargs)[source]
hypergraphx.representations.line_graph(*args, **kwargs)[source]

Next steps