-
-
Save Roon/d20bc0cf308d587afade5ff1a999c1a0 to your computer and use it in GitHub Desktop.
ego_graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import networkx as nx | |
| # SAMPLE DATA FORMAT | |
| #nodes = [('tensorflow', {'count': 13}), | |
| # ('pytorch', {'count': 6}), | |
| # ('keras', {'count': 6}), | |
| # ('scikit', {'count': 2}), | |
| # ('opencv', {'count': 5}), | |
| # ('spark', {'count': 13}), ...] | |
| #edges = [('pytorch', 'tensorflow', {'weight': 10, 'distance': 1}), | |
| # ('keras', 'tensorflow', {'weight': 9, 'distance': 2}), | |
| # ('scikit', 'tensorflow', {'weight': 8, 'distance': 3}), | |
| # ('opencv', 'tensorflow', {'weight': 7, 'distance': 4}), | |
| # ('spark', 'tensorflow', {'weight': 1, 'distance': 10}), ...] | |
| #BUILD THE INITIAL FULL GRAPH | |
| G=nx.Graph() | |
| G.add_nodes_from(nodes) | |
| G.add_edges_from(edges) | |
| #BUILD THE EGO GRAPH FOR TENSORFLOW | |
| EG = nx.ego_graph(G, 'tensorflow', distance = 'distance', radius = 22) | |
| #FIND THE 2-CONNECTED SUBGRAPHS | |
| subgraphs = nx.algorithms.connectivity.edge_kcomponents.k_edge_subgraphs(EG, k = 3) | |
| #GET THE SUBGRAPH THAT CONTAINS TENSORFLOW | |
| for s in subgraphs: | |
| if SEED in s: | |
| break | |
| pruned_EG = EG.subgraph(s) | |
| ego_nodes = pruned_EG.nodes() | |
| ego_edges = pruned_EG.edges() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment