In [1]:
import networkx as nx
from core.utils import load_edgelist, Info, graph_name
from glob import glob
import pprint as pp
import os
fname ="/Users/sal.aguinaga/KynKon/datasets/out.as20000102"
og = load_edgelist(fname)
gn = graph_name(fname)
og.name = gn
# sgp = glob("../datasets/"+ gn + "*.p" )
In [2]:
# sample 2 subg of 300 nodes and derive the set of production rules
import core.tree_decomposition as td
def get_sampled_gpickled_graphs(G):
G.remove_edges_from(G.selfloop_edges())
print (sorted(nx.connected_component_subgraphs(G), key=len))
giant_nodes = max(nx.connected_component_subgraphs(G), key=len)
G = nx.subgraph(G, giant_nodes)
num_nodes = G.number_of_nodes()
phrg.graph_checks(G)
prod_rules = {}
K = 2
n = 300
for Gprime in gs.rwr_sample(G, K, n):
nx.write_gpicle()
T = td.quickbb(Gprime)
root = list(T)[0]
T = td.make_rooted(T, root)
T = phrg.binarize(T)
root = list(T)[0]
root, children = T
# td.new_visit(T, G, prod_rules, TD)
td.new_visit(T, G, prod_rules)
return prod_rules
pr = get_sampled_gpickled_graphs(og)
pp.pprint (pr)
In [10]:
print(os.getcwd())
g = nx.read_gpickle('../datasets/as20000102_0.p')
In [6]:
print (sg[0])
G = nx.read_gpickle(sg[0])
nodes = G.nodes()
edges = G.edges()
nodes_dict = [{"id":n} for n in nodes]
node_map = dict(zip(nodes,range(len(nodes)))) # map to indices for source/target in edges
edges_dict = [{"source":node_map[edges[i][0]], "target":node_map[edges[i][1]],
"title":'test'} for i in range(len(edges))]
In [ ]:
pprint(edges_dict)
In [ ]: