xgi.convert.bipartite_graph#
Methods for converting to and from bipartite graphs.
Functions
- from_bipartite_graph(G, dual=False)[source]#
Create a Hypergraph from a NetworkX bipartite graph.
Any hypergraph may be represented as a bipartite graph where nodes in the first layer are nodes and nodes in the second layer are hyperedges.
The default behavior is to create nodes in the hypergraph from the nodes in the bipartite graph where the attribute bipartite=0 and hyperedges in the hypergraph from the nodes in the bipartite graph with attribute bipartite=1. Setting the keyword dual reverses this behavior.
- Parameters:
G (nx.Graph) – A networkx bipartite graph. Each node in the graph has a property ‘bipartite’ taking the value of 0 or 1 indicating the type of node.
dual (bool, default : False) – If True, get edges from bipartite=0 and nodes from bipartite=1
- Returns:
The equivalent hypergraph or directed hypergraph
- Return type:
References
The Why, How, and When of Representations for Complex Systems, Leo Torres, Ann S. Blevins, Danielle Bassett, and Tina Eliassi-Rad, https://doi.org/10.1137/20M1355896
Examples
>>> import networkx as nx >>> import xgi >>> G = nx.Graph() >>> G.add_nodes_from([1, 2, 3, 4], bipartite=0) >>> G.add_nodes_from(['a', 'b', 'c'], bipartite=1) >>> G.add_edges_from([(1, 'a'), (1, 'b'), (2, 'b'), (2, 'c'), (3, 'c'), (4, 'a')]) >>> H = xgi.from_bipartite_graph(G)
- to_bipartite_graph(H, index=False)[source]#
Create a NetworkX bipartite network from a hypergraph.
- Parameters:
H (xgi.Hypergraph or xgi.DiHypergraph) – The XGI hypergraph object of interest
index (bool (default False)) – If False (default), return only the graph. If True, additionally return the index-to-node and index-to-edge mappings.
- Returns:
if xgi.Hypergraph –
- nx.Graph[, dict, dict]
The resulting equivalent bipartite graph, and optionally the index-to-unit mappings.
if xgi.Hypergraph –
- nx.DiGraph[, dict, dict]
The resulting equivalent directed bipartite graph, and optionally the index-to-unit mappings.
References
The Why, How, and When of Representations for Complex Systems, Leo Torres, Ann S. Blevins, Danielle Bassett, and Tina Eliassi-Rad, https://doi.org/10.1137/20M1355896
Examples
>>> import xgi >>> hyperedge_list = [[1, 2], [2, 3, 4]] >>> H = xgi.Hypergraph(hyperedge_list) >>> G = xgi.to_bipartite_graph(H) >>> G, itn, ite = xgi.to_bipartite_graph(H, index=True)