easygraph package
Subpackages
- easygraph.classes package
- Submodules
- easygraph.classes.base module
- easygraph.classes.directed_graph module
- easygraph.classes.directed_multigraph module
- easygraph.classes.graph module
- easygraph.classes.graphviews module
- easygraph.classes.hypergraph module
- easygraph.classes.multigraph module
- easygraph.classes.operation module
- Module contents
- easygraph.datasets package
- easygraph.functions package
- Subpackages
- easygraph.functions.basic package
- easygraph.functions.centrality package
- Submodules
- easygraph.functions.centrality.betweenness module
- easygraph.functions.centrality.closeness module
- easygraph.functions.centrality.degree module
- easygraph.functions.centrality.ego_betweenness module
- easygraph.functions.centrality.flowbetweenness module
- easygraph.functions.centrality.laplacian module
- easygraph.functions.centrality.pagerank module
- Module contents
- easygraph.functions.community package
- easygraph.functions.components package
- easygraph.functions.core package
- easygraph.functions.drawing package
- Submodules
- easygraph.functions.drawing.defaults module
- easygraph.functions.drawing.drawing module
- easygraph.functions.drawing.geometry module
- easygraph.functions.drawing.layout module
- easygraph.functions.drawing.plot module
- easygraph.functions.drawing.positioning module
- easygraph.functions.drawing.simulator module
- easygraph.functions.drawing.utils module
- Module contents
- easygraph.functions.graph_embedding package
- Submodules
- easygraph.functions.graph_embedding.NOBE module
- easygraph.functions.graph_embedding.deepwalk module
- easygraph.functions.graph_embedding.line module
- easygraph.functions.graph_embedding.net_emb_example_citeseer module
- easygraph.functions.graph_embedding.node2vec module
- easygraph.functions.graph_embedding.sdne module
- Module contents
- easygraph.functions.graph_generator package
- easygraph.functions.hypergraph package
- easygraph.functions.path package
- easygraph.functions.structural_holes package
- Submodules
- easygraph.functions.structural_holes.AP_Greedy module
- easygraph.functions.structural_holes.HAM module
- easygraph.functions.structural_holes.HIS module
- easygraph.functions.structural_holes.ICC module
- easygraph.functions.structural_holes.MaxD module
- easygraph.functions.structural_holes.NOBE module
- easygraph.functions.structural_holes.SHII_metric module
- easygraph.functions.structural_holes.evaluation module
- easygraph.functions.structural_holes.maxBlock module
- easygraph.functions.structural_holes.metrics module
- easygraph.functions.structural_holes.weakTie module
- Module contents
- Submodules
- easygraph.functions.isolate module
- Module contents
- Subpackages
- easygraph.model package
- easygraph.nn package
- easygraph.randomhypergraph package
- easygraph.readwrite package
- Subpackages
- Submodules
- easygraph.readwrite.edgelist module
- easygraph.readwrite.gexf module
- easygraph.readwrite.gml module
- easygraph.readwrite.graphml module
- easygraph.readwrite.graphviz module
- easygraph.readwrite.pajek module
- easygraph.readwrite.pickle module
- easygraph.readwrite.ucinet module
- Module contents
- easygraph.utils package
- Submodules
- easygraph.utils.alias module
- easygraph.utils.convert_class module
- easygraph.utils.convert_to_matrix module
- easygraph.utils.decorators module
- easygraph.utils.exception module
- easygraph.utils.index_of_node module
- easygraph.utils.mapped_queue module
- easygraph.utils.misc module
- easygraph.utils.relabel module
- easygraph.utils.sparse module
- easygraph.utils.type_change module
- Module contents
Submodules
easygraph.convert module
- easygraph.convert.from_dgl(g) Union[Graph, DiGraph] [source]
Convert a DGL graph to an EasyGraph graph.
- easygraph.convert.from_edgelist(edgelist, create_using=None)[source]
Returns a graph from a list of edges.
- Parameters
edgelist (list or iterator) – Edge tuples
create_using (EasyGraph graph constructor, optional (default=eg.Graph)) – Graph type to create. If graph instance, then cleared before populated.
Examples
>>> edgelist = [(0, 1)] # single edge (0,1) >>> G = eg.from_edgelist(edgelist)
or
>>> G = eg.Graph(edgelist) # use Graph constructor
- easygraph.convert.from_networkx(g: Union[nx.Graph, nx.DiGraph]) Union[Graph, DiGraph] [source]
Convert a NetworkX graph to an EasyGraph graph.
- easygraph.convert.from_pyg(data: torch_geometric.data.Data, node_attrs: Optional[Iterable[str]] = None, edge_attrs: Optional[Iterable[str]] = None, graph_attrs: Optional[Iterable[str]] = None, to_undirected: Optional[Union[bool, str]] = False, remove_self_loops: bool = False) Any [source]
Converts a
torch_geometric.data.Data
instance to aeasygraph.Graph
ifto_undirected
is set toTrue
, or a directedeasygraph.DiGraph
otherwise.- Parameters
data (torch_geometric.data.Data) – The data object.
node_attrs (iterable of str, optional) – The node attributes to be copied. (default:
None
)edge_attrs (iterable of str, optional) – The edge attributes to be copied. (default:
None
)graph_attrs (iterable of str, optional) – The graph attributes to be copied. (default:
None
)to_undirected (bool or str, optional) – If set to
True
or “upper”, will return aeasygraph.Graph
instead of aeasygraph.DiGraph
. The undirected graph will correspond to the upper triangle of the corresponding adjacency matrix. Similarly, if set to “lower”, the undirected graph will correspond to the lower triangle of the adjacency matrix. (default:False
)remove_self_loops (bool, optional) – If set to
True
, will not include self loops in the resulting graph. (default:False
)
Examples
>>> import torch_geometric as pyg
>>> Data = pyg.data.Data # type: ignore >>> edge_index = torch.tensor([ ... [0, 1, 1, 2, 2, 3], ... [1, 0, 2, 1, 3, 2], ... ]) >>> data = Data(edge_index=edge_index, num_nodes=4) >>> from_pyg(data) <easygraph.classes.digraph.DiGraph at 0x2713fdb40d0>
- easygraph.convert.to_dgl(g: Union[Graph, DiGraph])[source]
Convert an EasyGraph graph to a DGL graph.
- easygraph.convert.to_easygraph_graph(data, create_using=None, multigraph_input=False)[source]
Make a EasyGraph graph from a known data structure.
The preferred way to call this is automatically from the class constructor
>>> d = {0: {1: {"weight": 1}}} # dict-of-dicts single edge (0,1) >>> G = eg.Graph(d)
instead of the equivalent
>>> G = eg.from_dict_of_dicts(d)
- Parameters
data (object to be converted) –
- Current known types are:
any EasyGraph graph dict-of-dicts dict-of-lists container (e.g. set, list, tuple) of edges iterator (e.g. itertools.chain) that produces edges generator of edges Pandas DataFrame (row per edge) numpy matrix numpy ndarray scipy sparse matrix pygraphviz agraph
create_using (EasyGraph graph constructor, optional (default=eg.Graph)) – Graph type to create. If graph instance, then cleared before populated.
multigraph_input (bool (default False)) – If True and data is a dict_of_dicts, try to create a multigraph assuming dict_of_dict_of_lists. If data and create_using are both multigraphs then create a multigraph from a multigraph.
- easygraph.convert.to_networkx(g: Union[Graph, DiGraph]) Union[nx.Graph, nx.DiGraph] [source]
Convert an EasyGraph to a NetworkX graph.
- easygraph.convert.to_pyg(G: Any, group_node_attrs: Optional[Union[List[str], all]] = None, group_edge_attrs: Optional[Union[List[str], all]] = None) torch_geometric.data.Data [source]
Converts a
easygraph.Graph
oreasygraph.DiGraph
to atorch_geometric.data.Data
instance.- Parameters
G (easygraph.Graph or easygraph.DiGraph) – A easygraph graph.
group_node_attrs (List[str] or all, optional) – The node attributes to be concatenated and added to
data.x
. (default:None
)group_edge_attrs (List[str] or all, optional) – The edge attributes to be concatenated and added to
data.edge_attr
. (default:None
)
Note
All
group_node_attrs
andgroup_edge_attrs
values must be numeric.Examples
>>> import torch_geometric as pyg
>>> pyg_to_networkx = pyg.utils.convert.to_networkx # type: ignore >>> networkx_to_pyg = pyg.utils.convert.from_networkx # type: ignore >>> Data = pyg.data.Data # type: ignore >>> edge_index = torch.tensor([ ... [0, 1, 1, 2, 2, 3], ... [1, 0, 2, 1, 3, 2], ... ]) >>> data = Data(edge_index=edge_index, num_nodes=4) >>> g = pyg_to_networkx(data) >>> # A `Data` object is returned >>> to_pyg(g) Data(edge_index=[2, 6], num_nodes=4)